summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-volume.c
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-05-26 03:32:27 +0000
committerAnand Avati <avati@gluster.com>2011-05-26 08:55:22 -0700
commit9072b817b0803f999081c6244b18a9ae8fb0234c (patch)
tree919d47d2ea6d42975dac3dd9293f925d6e7849e6 /cli/src/cli-cmd-volume.c
parent302ad26982d1eb7762e743e14dda627ffb317379 (diff)
reimplement invocation of external programs with run API
Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2562 (invoke external commands precisely with fork + exec) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2562
Diffstat (limited to 'cli/src/cli-cmd-volume.c')
-rw-r--r--cli/src/cli-cmd-volume.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 7ca9ed4bb2f..f2edbd0b1fa 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -32,6 +32,7 @@
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "cli1-xdr.h"
+#include "run.h"
extern struct rpc_clnt *global_rpc;
@@ -1053,30 +1054,10 @@ out:
static int
cli_check_gsync_present ()
{
- FILE *in = NULL;
char buff[PATH_MAX] = {0, };
- char cmd[PATH_MAX + 256] = {0, };
+ runner_t runner = {0,};
char *ptr = NULL;
int ret = 0;
- struct stat stat_buff;
-
- if (strlen (GSYNCD_PREFIX)+1 > PATH_MAX-strlen("/gsyncd")) {
- ret = -1;
- goto out;
- }
-
- ret = snprintf (cmd, sizeof(cmd), GSYNCD_PREFIX "/gsyncd");
- if (ret < 0) {
- ret = 0;
- goto out;
- }
- ret = lstat (cmd, &stat_buff);
-
- if (ret || !(stat_buff.st_mode & S_IXUSR)) {
- ret = -1;
- gf_log ("", GF_LOG_INFO, "geo-replication not installed");
- goto out;
- }
ret = setenv ("_GLUSTERD_CALLED_", "1", 1);
if (-1 == ret) {
@@ -1085,16 +1066,16 @@ cli_check_gsync_present ()
goto out;
}
- memset (cmd, 0, sizeof (cmd));
- ret = snprintf (cmd, sizeof(cmd), GSYNCD_PREFIX"/gsyncd --version");
-
- if (!(in = popen(cmd, "r"))) {
- ret = -1;
+ runinit (&runner);
+ runner_add_args (&runner, GSYNCD_PREFIX"/gsyncd", "--version", NULL);
+ runner_redir (&runner, STDOUT_FILENO, RUN_PIPE);
+ ret = runner_start (&runner);
+ if (ret == -1) {
gf_log ("", GF_LOG_INFO, "geo-replication not installed");
goto out;
}
- ptr = fgets(buff, sizeof(buff), in);
+ ptr = fgets(buff, sizeof(buff), runner_chio (&runner, STDOUT_FILENO));
if (ptr) {
if (!strstr (buff, "gsyncd")) {
ret = -1;
@@ -1105,7 +1086,7 @@ cli_check_gsync_present ()
goto out;
}
- ret = pclose (in);
+ ret = runner_end (&runner);
if (ret)
gf_log ("", GF_LOG_ERROR, "geo-replication not installed");