Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
fix return type for reachedload
avoid needlessly changing errno
use FD_CLOEXEC instead of posix_spawn_file_actions_addclose
use only one fd with 'fifo:' authentication type
fix |=/&= mixup
  • Loading branch information
capezotte committed Apr 6, 2024
1 parent 1d9f35f commit b3b77b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
13 changes: 2 additions & 11 deletions build.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,6 @@ jobstart(struct job *j, struct edge *e)
warn("posix_spawn_file_actions_addclose:");
goto err3;
}
if (isjobserverclient()) {
/* do not allow children to steal GNU/tokens */
for (i = 0; i < 2; ++i) {
if ((errno = posix_spawn_file_actions_addclose(&actions, buildopts.gmakepipe[i]))) {
warn("posix_spawn_file_actions_addclose:");
goto err3;
}
}
}
if (e->pool != &consolepool) {
if ((errno = posix_spawn_file_actions_addopen(&actions, 0, "/dev/null", O_RDONLY, 0))) {
warn("posix_spawn_file_actions_addopen:");
Expand Down Expand Up @@ -538,7 +529,7 @@ jobwork(struct job *j)
}

/* queries the system load average */
static double
static bool
reachedload(void)
{
#ifdef HAVE_GETLOADAVG
Expand Down Expand Up @@ -603,7 +594,7 @@ build(void)
fds[0].fd = buildopts.gmakepipe[0];
fds[0].events = 0;
if (isjobserverclient()) {
fds[0].events &= POLLIN;
fds[0].events |= POLLIN;
if (atexit(gmakeatexit) == 0) {
sact.sa_handler = termsignal;
sigaction(SIGTERM, &sact, NULL);
Expand Down
15 changes: 9 additions & 6 deletions samu.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ jobserverflags(const char *flag)
if (!flag)
return;
if (sscanf(flag, "%d,%d", &rfd, &wfd) == 2) {
/* prepare error message */
errno = EBADF;
;
} else if (strncmp(flag, "fifo:", 5) == 0) {
rfd = open(flag + 5, O_RDONLY);
wfd = open(flag + 5, O_WRONLY);
if ((rfd = wfd = open(flag + 5, O_RDWR)) == -1)
fatal("unable to open jobserver fifo:");
} else {
fatal("invalid jobserver parameter");
}

fcntl(rfd, F_SETFD, FD_CLOEXEC);
if (wfd != rfd)
fcntl(wfd, F_SETFD, FD_CLOEXEC);

buildopts.gmakepipe[0] = rfd;
buildopts.gmakepipe[1] = wfd;
warn("using GNU Make jobserver");
Expand All @@ -127,8 +130,8 @@ parsegmakeflags(char *env) {
buildopts.dryrun = true;
} else if (strncmp(arg, "-j", 2) == 0) {
jobsflag(arg + 2);
} else if (strncmp(arg, "--jobserver-auth=", 17) == 0 || strncmp(arg, "--jobserver-fds=", 16) == 0) {
jobserverflags(strchr(arg, '=')+1);
} else if (strncmp(arg, "--jobserver-auth=", 17) == 0) {
jobserverflags(arg + 17);
}
arg = strtok(NULL, " ");
}
Expand Down

0 comments on commit b3b77b7

Please sign in to comment.