]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
move cmd_exec to lib utils
authorDavid Ahern <dsa@cumulusnetworks.com>
Mon, 12 Dec 2016 00:53:11 +0000 (16:53 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 13 Dec 2016 18:20:16 +0000 (10:20 -0800)
Code move only; no functional change intended.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
include/utils.h
ip/ipnetns.c
lib/Makefile
lib/exec.c [new file with mode: 0644]

index 26c970daa5d0069d5c62cdffd2cd9bbf3b787d39..ac4517a3bde1c396af3d018f2fca9a115a21e286 100644 (file)
@@ -256,4 +256,6 @@ char *int_to_str(int val, char *buf);
 int get_guid(__u64 *guid, const char *arg);
 int get_real_family(int rtm_type, int rtm_family);
 
+int cmd_exec(const char *cmd, char **argv, bool do_fork);
+
 #endif /* __UTILS_H__ */
index bd1e9013706c417c2dae0171c2ec181e7f93fde7..db9a541769f1709ee26356d97b86e83d546d5aaa 100644 (file)
@@ -357,40 +357,6 @@ static int netns_list(int argc, char **argv)
        return 0;
 }
 
-static int cmd_exec(const char *cmd, char **argv, bool do_fork)
-{
-       fflush(stdout);
-       if (do_fork) {
-               int status;
-               pid_t pid;
-
-               pid = fork();
-               if (pid < 0) {
-                       perror("fork");
-                       exit(1);
-               }
-
-               if (pid != 0) {
-                       /* Parent  */
-                       if (waitpid(pid, &status, 0) < 0) {
-                               perror("waitpid");
-                               exit(1);
-                       }
-
-                       if (WIFEXITED(status)) {
-                               return WEXITSTATUS(status);
-                       }
-
-                       exit(1);
-               }
-       }
-
-       if (execvp(cmd, argv)  < 0)
-               fprintf(stderr, "exec of \"%s\" failed: %s\n",
-                               cmd, strerror(errno));
-       _exit(1);
-}
-
 static int on_netns_exec(char *nsname, void *arg)
 {
        char **argv = arg;
index 5b7ec169048ac32d95718bc64f50c1e8c1bf5a61..749073261c49e52e69ddab2b84fbf60229b77f3e 100644 (file)
@@ -8,7 +8,7 @@ CFLAGS += -fPIC
 
 UTILOBJ = utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o \
        inet_proto.o namespace.o json_writer.o \
-       names.o color.o bpf.o
+       names.o color.o bpf.o exec.o
 
 NLOBJ=libgenl.o ll_map.o libnetlink.o
 
diff --git a/lib/exec.c b/lib/exec.c
new file mode 100644 (file)
index 0000000..97c9912
--- /dev/null
@@ -0,0 +1,40 @@
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+int cmd_exec(const char *cmd, char **argv, bool do_fork)
+{
+       fflush(stdout);
+       if (do_fork) {
+               int status;
+               pid_t pid;
+
+               pid = fork();
+               if (pid < 0) {
+                       perror("fork");
+                       exit(1);
+               }
+
+               if (pid != 0) {
+                       /* Parent  */
+                       if (waitpid(pid, &status, 0) < 0) {
+                               perror("waitpid");
+                               exit(1);
+                       }
+
+                       if (WIFEXITED(status)) {
+                               return WEXITSTATUS(status);
+                       }
+
+                       exit(1);
+               }
+       }
+
+       if (execvp(cmd, argv)  < 0)
+               fprintf(stderr, "exec of \"%s\" failed: %s\n",
+                               cmd, strerror(errno));
+       _exit(1);
+}