shell: rework code to use shell.spawn

spawn gives out streams and we have more control over the stdout/stderr
buffers. otherwise, we have to provide a max buffer capture size to exec
This commit is contained in:
Girish Ramakrishnan
2024-10-15 10:10:15 +02:00
parent 7b648cddfd
commit 6c3ca9c364
18 changed files with 101 additions and 88 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ async function hdparm(file) {
}
async function getSwaps() {
const [error, stdout] = await safe(shell.exec('swapon --noheadings --raw --bytes --show=type,size,used,name', {}));
const [error, stdout] = await safe(shell.spawn('swapon', ['--noheadings', '--raw', '--bytes', '--show=type,size,used,name'], { encoding: 'utf8' }));
if (error) return {};
const output = stdout.trim();
if (!output) return {}; // no swaps
@@ -314,7 +314,7 @@ async function getLogs(unit, options) {
}
async function getBlockDevices() {
const result = await shell.exec('lsblk --paths --json --list --fs --output +rota', {});
const result = await shell.spawn('lsblk', ['--paths', '--json', '--list', '--fs', '--output', '+rota'], { encoding: 'utf8' });
const info = safe.JSON.parse(result);
if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, `failed to parse lsblk: ${safe.error.message}`);