diff options
author | haturatu <warsaw21g@gmail.com> | 2024-06-25 00:33:30 +0900 |
---|---|---|
committer | haturatu <warsaw21g@gmail.com> | 2024-06-25 00:33:30 +0900 |
commit | b4307fffd9ef76efc612699a783e76368291f882 (patch) | |
tree | 74468d4e3d0c6f411bf22ceccf05f441dcb1ebea /src/storage.c | |
parent | b9cd005c12ea757533152f2537f0f689f76b4e8b (diff) |
fix escape & storage
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/storage.c b/src/storage.c index 1924acf..5500e93 100644 --- a/src/storage.c +++ b/src/storage.c @@ -4,27 +4,26 @@ #include <string.h> const char *display_storage() { - const char *iszfs = run_command_s("LC_ALL=C zpool list 2>&1"); - if ( - strncmp( - iszfs, - "sh: command not found: zpool", - strlen("sh: command not found: zpool") - ) == 0 || - strncmp( - iszfs, - "internal error: failed to initialize ZFS library", - strlen("internal error: failed to initialize ZFS library") - ) == 0 || - strncmp(iszfs, "sh: zpool: not found", strlen("sh: zpool: not found")) == 0 || - strncmp(iszfs, "sh: 1: zpool: not found", strlen("sh: 1: zpool: not found")) == 0 - ) { + const char *excode = run_command_s("LC_ALL=C zpool list 2>/dev/null || echo $?"); + + if (excode != NULL && strcmp(excode, "127") == 0) { return run_command_s("df -h | " - "awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | " - "awk '{sub(/, $/, \"\"); print}'"); + "awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | " + "awk '{sub(/, $/, \"\"); print}'"); + } else { + const char *iszfs = run_command_s("LC_ALL=C zpool list 2>&1"); + if ( + strncmp(iszfs, "sh: zpool: not found", strlen("sh: zpool: not found")) == 0 || + strncmp(iszfs, "sh: 1: zpool: not found", strlen("sh: 1: zpool: not found")) == 0 + ) { + return run_command_s("df -h | " + "awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | " + "awk '{sub(/, $/, \"\"); print}'"); + } else { + return run_command_s("zpool list | " + "awk 'NR>1 {printf \"%s: %s / %s, \", $1, $3, $2}' | " + "awk '{sub(/, $/, \"\"); print}'"); + } } - - return run_command_s("zpool list | " - "awk 'NR>1 {printf \"%s: %s / %s, \", $1, $3, $2}' | " - "awk '{sub(/, $/, \"\"); print}'"); } + |