summaryrefslogtreecommitdiff
path: root/src/storage.c
blob: 909f477cf880cfb486c151c93078be3731893a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "storage.h"
#include "common.h"

#include <string.h>
#include <stdlib.h>

const char *display_storage() {
  const char *excode = run_command_s("zpool list 2>/dev/null || echo $?");
  if ( excode != NULL && (strncmp(excode, "127", strlen("127")) == 0)) {
    free((void *)excode);
    return run_command_s("df -h | "
        "awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | "
        "awk '{sub(/, $/, \"\"); print}'");
  } 

  free((void *)excode);
  return run_command_s("zpool list | "
      "awk 'NR>1 {printf \"%s: %s / %s, \", $1, $3, $2}' | "
      "awk '{sub(/, $/, \"\"); print}'");
}