mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-12-08 11:30:21 +00:00
move cmd_exec to lib utils
Code move only; no functional change intended. Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
This commit is contained in:
parent
10e51a76a9
commit
08bd33d77f
@ -256,4 +256,6 @@ char *int_to_str(int val, char *buf);
|
|||||||
int get_guid(__u64 *guid, const char *arg);
|
int get_guid(__u64 *guid, const char *arg);
|
||||||
int get_real_family(int rtm_type, int rtm_family);
|
int get_real_family(int rtm_type, int rtm_family);
|
||||||
|
|
||||||
|
int cmd_exec(const char *cmd, char **argv, bool do_fork);
|
||||||
|
|
||||||
#endif /* __UTILS_H__ */
|
#endif /* __UTILS_H__ */
|
||||||
|
|||||||
34
ip/ipnetns.c
34
ip/ipnetns.c
@ -357,40 +357,6 @@ static int netns_list(int argc, char **argv)
|
|||||||
return 0;
|
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)
|
static int on_netns_exec(char *nsname, void *arg)
|
||||||
{
|
{
|
||||||
char **argv = arg;
|
char **argv = arg;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ CFLAGS += -fPIC
|
|||||||
|
|
||||||
UTILOBJ = utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o \
|
UTILOBJ = utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o \
|
||||||
inet_proto.o namespace.o json_writer.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
|
NLOBJ=libgenl.o ll_map.o libnetlink.o
|
||||||
|
|
||||||
|
|||||||
40
lib/exec.c
Normal file
40
lib/exec.c
Normal file
@ -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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user