]> git.proxmox.com Git - mirror_iproute2.git/blame - lib/exec.c
rdma: Properly mark RDMAtool license
[mirror_iproute2.git] / lib / exec.c
CommitLineData
6054c1eb 1/* SPDX-License-Identifier: GPL-2.0 */
08bd33d7
DA
2#include <sys/wait.h>
3#include <stdio.h>
4#include <errno.h>
5#include <unistd.h>
6
7#include "utils.h"
8
9int cmd_exec(const char *cmd, char **argv, bool do_fork)
10{
11 fflush(stdout);
12 if (do_fork) {
13 int status;
14 pid_t pid;
15
16 pid = fork();
17 if (pid < 0) {
18 perror("fork");
19 exit(1);
20 }
21
22 if (pid != 0) {
23 /* Parent */
24 if (waitpid(pid, &status, 0) < 0) {
25 perror("waitpid");
26 exit(1);
27 }
28
29 if (WIFEXITED(status)) {
30 return WEXITSTATUS(status);
31 }
32
33 exit(1);
34 }
35 }
36
37 if (execvp(cmd, argv) < 0)
38 fprintf(stderr, "exec of \"%s\" failed: %s\n",
39 cmd, strerror(errno));
40 _exit(1);
41}