2 #include "run-command.h"
5 int run_command_v(int argc
, char **argv
)
10 return -ERR_RUN_COMMAND_FORK
;
12 execvp(argv
[0], (char *const*) argv
);
13 die("exec %s failed.", argv
[0]);
17 int retval
= waitpid(pid
, &status
, 0);
22 error("waitpid failed (%s)", strerror(retval
));
23 return -ERR_RUN_COMMAND_WAITPID
;
26 return -ERR_RUN_COMMAND_WAITPID_WRONG_PID
;
27 if (WIFSIGNALED(status
))
28 return -ERR_RUN_COMMAND_WAITPID_SIGNAL
;
30 if (!WIFEXITED(status
))
31 return -ERR_RUN_COMMAND_WAITPID_NOEXIT
;
32 code
= WEXITSTATUS(status
);
39 int run_command(const char *cmd
, ...)
42 char *argv
[MAX_RUN_COMMAND_ARGS
];
47 argv
[0] = (char*) cmd
;
49 while (argc
< MAX_RUN_COMMAND_ARGS
) {
50 arg
= argv
[argc
++] = va_arg(param
, char *);
55 if (MAX_RUN_COMMAND_ARGS
<= argc
)
56 return error("too many args to run %s", cmd
);
57 return run_command_v(argc
, argv
);