From 86fa8679f981c2a02a6eddeb50b619787691d5fd Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Mon, 20 Oct 2025 14:46:44 +0200 Subject: [PATCH] Teach jobclient.h about fifo jobservers In make 4.4 a new jobserver communication format over a fifo appeared. This teaches the jobclient.h "library" about that format. --- jobclient.h | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/jobclient.h b/jobclient.h index 5d6eee4..8f02a5f 100644 --- a/jobclient.h +++ b/jobclient.h @@ -4,6 +4,7 @@ #include #include #include +#include // https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#POSIX-Jobserver @@ -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; }