author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sun, 28 May 2023 04:12:10 +0200 | |
changeset 50633 | f2ae815ae34c |
parent 41336 | 763b45bc4483 |
permissions | -rw-r--r-- |
28060 | 1 |
/* |
2 |
* Utility functions |
|
3 |
* |
|
4 |
* Copyright (c) 2011 Yuya Nishihara <yuya@tcha.org> |
|
5 |
* |
|
6 |
* This software may be used and distributed according to the terms of the |
|
7 |
* GNU General Public License version 2 or any later version. |
|
8 |
*/ |
|
9 |
||
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
10 |
#include <errno.h> |
28855
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
11 |
#include <fcntl.h> |
28060 | 12 |
#include <signal.h> |
13 |
#include <stdarg.h> |
|
14 |
#include <stdio.h> |
|
15 |
#include <stdlib.h> |
|
28084
3fc45956c978
chg: initialize sigaction fields more reliably
Yuya Nishihara <yuya@tcha.org>
parents:
28060
diff
changeset
|
16 |
#include <string.h> |
34309
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
17 |
#include <sys/time.h> |
28060 | 18 |
#include <sys/types.h> |
19 |
#include <sys/wait.h> |
|
20 |
#include <unistd.h> |
|
21 |
||
22 |
#include "util.h" |
|
23 |
||
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
24 |
static int colorenabled = 0; |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
25 |
|
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
26 |
static inline void fsetcolor(FILE *fp, const char *code) |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
27 |
{ |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
28 |
if (!colorenabled) { |
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
29 |
return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
30 |
} |
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
31 |
fprintf(fp, "\033[%sm", code); |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
32 |
} |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
33 |
|
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
34 |
static void vabortmsgerrno(int no, const char *fmt, va_list args) |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
35 |
{ |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
36 |
fsetcolor(stderr, "1;31"); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
37 |
fputs("chg: abort: ", stderr); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
38 |
vfprintf(stderr, fmt, args); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
39 |
if (no != 0) { |
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
40 |
fprintf(stderr, " (errno = %d, %s)", no, strerror(no)); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
41 |
} |
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
42 |
fsetcolor(stderr, ""); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
43 |
fputc('\n', stderr); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
44 |
exit(255); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
45 |
} |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
46 |
|
28060 | 47 |
void abortmsg(const char *fmt, ...) |
48 |
{ |
|
49 |
va_list args; |
|
50 |
va_start(args, fmt); |
|
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
51 |
vabortmsgerrno(0, fmt, args); |
28060 | 52 |
va_end(args); |
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
53 |
} |
28060 | 54 |
|
28788
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
55 |
void abortmsgerrno(const char *fmt, ...) |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
56 |
{ |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
57 |
int no = errno; |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
58 |
va_list args; |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
59 |
va_start(args, fmt); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
60 |
vabortmsgerrno(no, fmt, args); |
57a78a64de44
chg: add util function abortmsgerrno to print error with errno
Jun Wu <quark@fb.com>
parents:
28787
diff
changeset
|
61 |
va_end(args); |
28060 | 62 |
} |
63 |
||
64 |
static int debugmsgenabled = 0; |
|
34309
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
65 |
static double debugstart = 0; |
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
66 |
|
35959
9724f54923ec
chg: enable clang-format on all .c and .h files
Augie Fackler <augie@google.com>
parents:
34309
diff
changeset
|
67 |
static double now() |
9724f54923ec
chg: enable clang-format on all .c and .h files
Augie Fackler <augie@google.com>
parents:
34309
diff
changeset
|
68 |
{ |
34309
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
69 |
struct timeval t; |
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
70 |
gettimeofday(&t, NULL); |
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
71 |
return t.tv_usec / 1e6 + t.tv_sec; |
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
72 |
} |
28060 | 73 |
|
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
74 |
void enablecolor(void) |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
75 |
{ |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
76 |
colorenabled = 1; |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
77 |
} |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
78 |
|
28060 | 79 |
void enabledebugmsg(void) |
80 |
{ |
|
81 |
debugmsgenabled = 1; |
|
34309
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
82 |
debugstart = now(); |
28060 | 83 |
} |
84 |
||
85 |
void debugmsg(const char *fmt, ...) |
|
86 |
{ |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
87 |
if (!debugmsgenabled) { |
28060 | 88 |
return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
89 |
} |
28060 | 90 |
|
91 |
va_list args; |
|
92 |
va_start(args, fmt); |
|
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
93 |
fsetcolor(stderr, "1;30"); |
34309
b94db1780365
chg: show timestamp with debug messages
Jun Wu <quark@fb.com>
parents:
28855
diff
changeset
|
94 |
fprintf(stderr, "chg: debug: %4.6f ", now() - debugstart); |
28060 | 95 |
vfprintf(stderr, fmt, args); |
28787
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
96 |
fsetcolor(stderr, ""); |
ea86cdcd9b50
chg: use color in debug/error messages conditionally
Jun Wu <quark@fb.com>
parents:
28165
diff
changeset
|
97 |
fputc('\n', stderr); |
28060 | 98 |
va_end(args); |
99 |
} |
|
100 |
||
28854
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
101 |
void fchdirx(int dirfd) |
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
102 |
{ |
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
103 |
int r = fchdir(dirfd); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
104 |
if (r == -1) { |
28854
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
105 |
abortmsgerrno("failed to fchdir"); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
106 |
} |
28854
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
107 |
} |
ddef14468952
chg: add fchdirx as a utility function
Jun Wu <quark@fb.com>
parents:
28788
diff
changeset
|
108 |
|
28855
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
109 |
void fsetcloexec(int fd) |
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
110 |
{ |
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
111 |
int flags = fcntl(fd, F_GETFD); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
112 |
if (flags < 0) { |
28855
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
113 |
abortmsgerrno("cannot get flags of fd %d", fd); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
114 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
115 |
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { |
28855
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
116 |
abortmsgerrno("cannot set flags of fd %d", fd); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
117 |
} |
28855
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
118 |
} |
f5764e177bbe
chg: extract the logic of setting FD_CLOEXEC to a utility function
Jun Wu <quark@fb.com>
parents:
28854
diff
changeset
|
119 |
|
28165
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
120 |
void *mallocx(size_t size) |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
121 |
{ |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
122 |
void *result = malloc(size); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
123 |
if (!result) { |
28165
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
124 |
abortmsg("failed to malloc"); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
125 |
} |
28165
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
126 |
return result; |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
127 |
} |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
128 |
|
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
129 |
void *reallocx(void *ptr, size_t size) |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
130 |
{ |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
131 |
void *result = realloc(ptr, size); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
132 |
if (!result) { |
28165
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
133 |
abortmsg("failed to realloc"); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
134 |
} |
28165
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
135 |
return result; |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
136 |
} |
c6705c6303dd
chg: add utility functions mallocx, reallocx
Jun Wu <quark@fb.com>
parents:
28084
diff
changeset
|
137 |
|
28060 | 138 |
/* |
139 |
* Execute a shell command in mostly the same manner as system(), with the |
|
140 |
* give environment variables, after chdir to the given cwd. Returns a status |
|
141 |
* code compatible with the Python subprocess module. |
|
142 |
*/ |
|
143 |
int runshellcmd(const char *cmd, const char *envp[], const char *cwd) |
|
144 |
{ |
|
145 |
enum { F_SIGINT = 1, F_SIGQUIT = 2, F_SIGMASK = 4, F_WAITPID = 8 }; |
|
146 |
unsigned int doneflags = 0; |
|
147 |
int status = 0; |
|
148 |
struct sigaction newsa, oldsaint, oldsaquit; |
|
149 |
sigset_t oldmask; |
|
150 |
||
151 |
/* block or mask signals just as system() does */ |
|
28084
3fc45956c978
chg: initialize sigaction fields more reliably
Yuya Nishihara <yuya@tcha.org>
parents:
28060
diff
changeset
|
152 |
memset(&newsa, 0, sizeof(newsa)); |
28060 | 153 |
newsa.sa_handler = SIG_IGN; |
154 |
newsa.sa_flags = 0; |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
155 |
if (sigemptyset(&newsa.sa_mask) < 0) { |
28060 | 156 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
157 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
158 |
if (sigaction(SIGINT, &newsa, &oldsaint) < 0) { |
28060 | 159 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
160 |
} |
28060 | 161 |
doneflags |= F_SIGINT; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
162 |
if (sigaction(SIGQUIT, &newsa, &oldsaquit) < 0) { |
28060 | 163 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
164 |
} |
28060 | 165 |
doneflags |= F_SIGQUIT; |
166 |
||
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
167 |
if (sigaddset(&newsa.sa_mask, SIGCHLD) < 0) { |
28060 | 168 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
169 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
170 |
if (sigprocmask(SIG_BLOCK, &newsa.sa_mask, &oldmask) < 0) { |
28060 | 171 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
172 |
} |
28060 | 173 |
doneflags |= F_SIGMASK; |
174 |
||
175 |
pid_t pid = fork(); |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
176 |
if (pid < 0) { |
28060 | 177 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
178 |
} |
28060 | 179 |
if (pid == 0) { |
180 |
sigaction(SIGINT, &oldsaint, NULL); |
|
181 |
sigaction(SIGQUIT, &oldsaquit, NULL); |
|
182 |
sigprocmask(SIG_SETMASK, &oldmask, NULL); |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
183 |
if (cwd && chdir(cwd) < 0) { |
28060 | 184 |
_exit(127); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
185 |
} |
28060 | 186 |
const char *argv[] = {"sh", "-c", cmd, NULL}; |
187 |
if (envp) { |
|
188 |
execve("/bin/sh", (char **)argv, (char **)envp); |
|
189 |
} else { |
|
190 |
execv("/bin/sh", (char **)argv); |
|
191 |
} |
|
192 |
_exit(127); |
|
193 |
} else { |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
194 |
if (waitpid(pid, &status, 0) < 0) { |
28060 | 195 |
goto done; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
196 |
} |
28060 | 197 |
doneflags |= F_WAITPID; |
198 |
} |
|
199 |
||
200 |
done: |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
201 |
if (doneflags & F_SIGINT) { |
28060 | 202 |
sigaction(SIGINT, &oldsaint, NULL); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
203 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
204 |
if (doneflags & F_SIGQUIT) { |
28060 | 205 |
sigaction(SIGQUIT, &oldsaquit, NULL); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
206 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
207 |
if (doneflags & F_SIGMASK) { |
28060 | 208 |
sigprocmask(SIG_SETMASK, &oldmask, NULL); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
209 |
} |
28060 | 210 |
|
211 |
/* no way to report other errors, use 127 (= shell termination) */ |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
212 |
if (!(doneflags & F_WAITPID)) { |
28060 | 213 |
return 127; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
214 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
215 |
if (WIFEXITED(status)) { |
28060 | 216 |
return WEXITSTATUS(status); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
217 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
218 |
if (WIFSIGNALED(status)) { |
28060 | 219 |
return -WTERMSIG(status); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
35959
diff
changeset
|
220 |
} |
28060 | 221 |
return 127; |
222 |
} |