aboutsummaryrefslogtreecommitdiff
path: root/spawn.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:33:07 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:33:07 +0000
commit555f751f94a7efa90f03713a876f41f2424ea9f0 (patch)
tree95b3ed4273abb6103f74b60e5915d9386ddc8936 /spawn.c
parentMerge branch 'restore-signals-when-spawning-subprocess' (diff)
errno: don’t use ‘_errno’ as a variable name; _ are reserved for use as identifiers
Diffstat (limited to 'spawn.c')
-rw-r--r--spawn.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/spawn.c b/spawn.c
index 5f8fc13b..3f8a8fd3 100644
--- a/spawn.c
+++ b/spawn.c
@@ -39,10 +39,10 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
sigset_t mask;
sigemptyset(&mask);
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
- const int _errno = errno;
- LOG_ERRNO_P(errno, "failed to restore signals");
- (void)!write(pipe_fds[1], &_errno, sizeof(_errno));
- _exit(_errno);
+ const int errno_copy = errno;
+ LOG_ERRNO("failed to restore signals");
+ (void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
+ _exit(errno_copy);
}
if ((stdin_fd >= 0 && (dup2(stdin_fd, STDIN_FILENO) < 0 || close(stdin_fd) < 0)) ||
@@ -51,8 +51,9 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
(cwd != NULL && chdir(cwd) < 0) ||
execvp(argv[0], argv) < 0)
{
- (void)!write(pipe_fds[1], &errno, sizeof(errno));
- _exit(errno);
+ const int errno_copy = errno;
+ (void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
+ _exit(errno_copy);
}
xassert(false);
_exit(errno);
@@ -61,10 +62,10 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
/* Parent */
close(pipe_fds[1]);
- int _errno;
- static_assert(sizeof(_errno) == sizeof(errno), "errno size mismatch");
+ int errno_copy;
+ static_assert(sizeof(errno_copy) == sizeof(errno), "errno size mismatch");
- ssize_t ret = read(pipe_fds[0], &_errno, sizeof(_errno));
+ ssize_t ret = read(pipe_fds[0], &errno_copy, sizeof(errno_copy));
close(pipe_fds[0]);
if (ret == 0) {
@@ -74,8 +75,8 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
LOG_ERRNO("failed to read from pipe");
return false;
} else {
- LOG_ERRNO_P(_errno, "%s: failed to spawn", argv[0]);
- errno = _errno;
+ LOG_ERRNO_P(errno_copy, "%s: failed to spawn", argv[0]);
+ errno = errno_copy;
waitpid(pid, NULL, 0);
return false;
}