| int run_command_v(int argc, char **argv) |
| return -ERR_RUN_COMMAND_FORK; |
| execvp(argv[0], (char *const*) argv); |
| die("exec %s failed.", argv[0]); |
| int retval = waitpid(pid, &status, 0); |
| error("waitpid failed (%s)", strerror(retval)); |
| return -ERR_RUN_COMMAND_WAITPID; |
| return -ERR_RUN_COMMAND_WAITPID_WRONG_PID; |
| return -ERR_RUN_COMMAND_WAITPID_SIGNAL; |
| return -ERR_RUN_COMMAND_WAITPID_NOEXIT; |
| code = WEXITSTATUS(status); |
| int run_command(const char *cmd, ...) |
| char *argv[MAX_RUN_COMMAND_ARGS]; |
| while (argc < MAX_RUN_COMMAND_ARGS) { |
| arg = argv[argc++] = va_arg(param, char *); |
| if (MAX_RUN_COMMAND_ARGS <= argc) |
| return error("too many args to run %s", cmd); |
| return run_command_v(argc, argv); |