Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions jobclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

// https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#POSIX-Jobserver

Expand All @@ -22,15 +23,35 @@ static int parse_makeflags(int *fds) {
}
p += sizeof(flagname) - 1;

const char *c = strchr(p, ',');
if (!c) {
fprintf(stderr, "job: error: Incorrect --jobserver-auth format\n");
return 0;
}
c++;
if (strncmp(p, "fifo:", strlen("fifo:")) == 0) {
const char *fifo_name = strchr(p, ':');
if (!fifo_name) {
fprintf(stderr, "X_job: error: Incorrect --jobserver-auth format\n");
return 0;
}
fifo_name++;
fds[0] = open(fifo_name, O_RDONLY);
if (fds[0] < 0) {
fprintf(stderr, "job: cannot open jobserver %s: %s", fifo_name, strerror (errno));
return 0;
}
fds[1] = open(fifo_name, O_WRONLY);
if (fds[1] < 0) {
close(fds[0]);
fprintf(stderr, "job: cannot open jobserver %s: %s", fifo_name, strerror (errno));
return 0;
}
} else {
const char *c = strchr(p, ',');
if (!c) {
fprintf(stderr, "Y_job: error: Incorrect --jobserver-auth format\n");
return 0;
}
c++;

fds[0] = atoi(p);
fds[1] = atoi(c);
fds[0] = atoi(p);
fds[1] = atoi(c);
}

return 1;
}
Expand Down