From 9072b817b0803f999081c6244b18a9ae8fb0234c Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Thu, 26 May 2011 03:32:27 +0000 Subject: reimplement invocation of external programs with run API Signed-off-by: Csaba Henk Signed-off-by: Anand Avati BUG: 2562 (invoke external commands precisely with fork + exec) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2562 --- libglusterfs/src/common-utils.c | 59 ----------------------------------------- libglusterfs/src/common-utils.h | 1 - libglusterfs/src/compat.h | 5 ++++ libglusterfs/src/graph.y | 2 ++ 4 files changed, 7 insertions(+), 60 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index e745ec0fa..7cb389ba3 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1485,65 +1485,6 @@ get_checksum_for_file (int fd, uint32_t *checksum) } -/* One should pass the command here with command with full path, - otherwise, execv will fail */ -int -gf_system (const char *command) -{ - int ret = -1; - pid_t pid = 0; - int status = 0; - int idx = 0; - char *dupcmd = NULL; - char *arg = NULL; - char *tmp = NULL; - char *argv[100] = { NULL, }; - - dupcmd = gf_strdup (command); - if (!dupcmd) - goto out; - - pid = fork (); - if (pid < 0) { - /* failure */ - goto out; - } - if (pid == 0) { - /* Child process */ - /* Step 0: Prepare the argv */ - arg = strtok_r (dupcmd, " ", &tmp); - while (arg) { - argv[idx] = arg; - arg = strtok_r (NULL, " ", &tmp); - idx++; - } - /* Step 1: Close all 'fd' */ - for (idx = 3; idx < 65536; idx++) { - close (idx); - } - /* Step 2: execv (); */ - ret = execvp (argv[0], argv); - - /* Code will not come here at all */ - gf_log ("", GF_LOG_ERROR, "execv of (%s) failed", command); - - kill (getpid(), SIGKILL); - } - if (pid > 0) { - /* Current, ie, parent process */ - pid = waitpid (pid, &status, 0); - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) - ret = 0; - else - ret = -1; - } -out: - if (dupcmd) - GF_FREE (dupcmd); - - return ret; -} - int get_checksum_for_path (char *path, uint32_t *checksum) { diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index a1df3de35..d3218b018 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -344,7 +344,6 @@ int gf_unlockfd (int fd); int get_checksum_for_file (int fd, uint32_t *checksum); int log_base2 (unsigned long x); -int gf_system (const char *command); int get_checksum_for_path (char *path, uint32_t *checksum); char *strtail (char *str, const char *pattern); diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h index a6f1f01bd..4d336ea06 100644 --- a/libglusterfs/src/compat.h +++ b/libglusterfs/src/compat.h @@ -378,4 +378,9 @@ dirent_size (struct dirent *entry) #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG(buf, (long)(v)) #endif +#if defined(__GNUC__) && !defined(RELAX_POISONING) +/* Use run API, see run.h */ +#pragma GCC poison system popen +#endif + #endif /* __COMPAT_H__ */ diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y index 52e15940a..3e566aa1d 100644 --- a/libglusterfs/src/graph.y +++ b/libglusterfs/src/graph.y @@ -29,6 +29,8 @@ #include #include +#define RELAX_POISONING + #include "xlator.h" #include "graph-utils.h" #include "logging.h" -- cgit