summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-volume.c37
-rw-r--r--cli/src/cli-rpc-ops.c56
2 files changed, 41 insertions, 52 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 7ca9ed4bb..f2edbd0b1 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");
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 24afb66f0..ee52ccc95 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -43,6 +43,8 @@
#include "glusterfs3.h"
#include "portmap.h"
+#include "run.h"
+
extern rpc_clnt_prog_t *cli_rpc_prog;
extern int cli_op_ret;
extern int connected;
@@ -1318,7 +1320,8 @@ print_limit_list (char *volname, char *limit_list)
char ret_str [1024] = {0, };
char value [1024] = {0, };
char mountdir [] = "/tmp/mntXXXXXX";
- char cmd_str [PATH_MAX + 1024] = {0, };
+ char abspath [PATH_MAX] = {0, };
+ runner_t runner = {0,};
GF_VALIDATE_OR_GOTO ("cli", volname, out);
GF_VALIDATE_OR_GOTO ("cli", limit_list, out);
@@ -1336,10 +1339,8 @@ print_limit_list (char *volname, char *limit_list)
/* Mount a temporary client to fetch the disk usage
* of the directory on which the limit is set.
*/
- snprintf (cmd_str, sizeof (cmd_str), GFS_PREFIX "/sbin/glusterfs -s localhost "
- "--volfile-id %s %s", volname, mountdir);
-
- ret = system (cmd_str);
+ ret = runcmd (GFS_PREFIX"/sbin/glusterfs", "-s",
+ "localhost", "--volfile-id", volname, mountdir, NULL);
if (ret) {
gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs client");
ret = -1;
@@ -1373,10 +1374,9 @@ print_limit_list (char *volname, char *limit_list)
}
value [j] = '\0';
- memset (&cmd_str, 0, sizeof (cmd_str));
- snprintf (cmd_str, sizeof (cmd_str), "%s/%s", mountdir, path);
+ snprintf (abspath, sizeof (abspath), "%s/%s", mountdir, path);
- ret = getxattr (cmd_str, "trusted.limit.list", (void *) ret_str, 4096);
+ ret = getxattr (abspath, "trusted.limit.list", (void *) ret_str, 4096);
if (ret < 0) {
cli_out ("%-20s %10s", path, value);
} else {
@@ -1389,15 +1389,18 @@ print_limit_list (char *volname, char *limit_list)
}
unmount:
- memset (&cmd_str, 0, sizeof (cmd_str));
+
+ runinit (&runner);
+ runner_add_args (&runner, "umount",
#if GF_LINUX_HOST_OS
- snprintf (cmd_str, sizeof (cmd_str), "umount -l %s", mountdir);
-#else
- snprintf (cmd_str, sizeof (cmd_str), "umount %s", mountdir);
+ "-l",
#endif
- ret = system (cmd_str);
+ mountdir, NULL);
+ ret = runner_run_reuse (&runner);
if (ret)
- gf_log ("cli", GF_LOG_WARNING, "error executing: %s", cmd_str);
+ runner_log (&runner, "cli", GF_LOG_WARNING, "error executing");
+ runner_end (&runner);
+
rm_dir:
rmdir (mountdir);
out:
@@ -2654,7 +2657,7 @@ out:
int
gf_cli3_1_gsync_config_command (dict_t *dict)
{
- char cmd[PATH_MAX] = {0,};
+ runner_t runner = {0,};
char *subop = NULL;
char *gwd = NULL;
char *slave = NULL;
@@ -2674,16 +2677,21 @@ gf_cli3_1_gsync_config_command (dict_t *dict)
return -1;
if (dict_get_str (dict, "master", &master) != 0)
- master = "";
+ master = NULL;
if (dict_get_str (dict, "op_name", &op_name) != 0)
- op_name = "";
-
- snprintf (cmd, PATH_MAX,
- GSYNCD_PREFIX"/gsyncd -c %s/"GSYNC_CONF" %s%s %s --config-%s%s%s",
- gwd, *master ? ":" : "", master, slave,
- subop, *op_name ? " " : "", op_name);
-
- return system (cmd) ? -1 : 0;
+ op_name = NULL;
+
+ runinit (&runner);
+ runner_add_args (&runner, GSYNCD_PREFIX"/gsyncd", "-c", NULL);
+ runner_argprintf (&runner, "%s/"GSYNC_CONF, gwd);
+ if (master)
+ runner_argprintf (&runner, ":%s", master);
+ runner_add_arg (&runner, slave);
+ runner_argprintf (&runner, "--config-%s", subop);
+ if (op_name)
+ runner_add_arg (&runner, op_name);
+
+ return runner_run (&runner);
}
int