summaryrefslogtreecommitdiffstats
path: root/gluster-blockd.c
blob: 18506acde4bba20d553f3a93f4fb72b8296e2991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <stdio.h>

#include "rpc/block.h"
#include "utils.h"


blockTrans *
block_exec_1_svc(char **cmd, struct svc_req *rqstp)
{
  FILE *fp;
  static blockTrans *obj;

  if(GB_ALLOC(obj) < 0)
    return NULL;

  if (GB_ALLOC_N(obj->out, 4096) < 0) {
    GB_FREE(obj);
    return NULL;
  }

  fp = popen(*cmd, "r");
  if (fp != NULL) {
    size_t newLen = fread(obj->out, sizeof(char), 4996, fp);
    if (ferror( fp ) != 0) {
      ERROR("%s", "Error reading command output\n");
    } else {
      obj->out[newLen++] = '\0';
    }
    obj->exit = WEXITSTATUS(pclose(fp));
  }

  return obj;
}