Skip to content

Commit

Permalink
parse fifo-based --jobserver-auth flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzini committed May 2, 2024
1 parent 4a5b957 commit 4aabf9c
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions token.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ static void tokenexit(void)
}
}

/* --jobserver-auth=fifo:PATH - open named pipe for both reading and writing */
static int parse_makeflags_fifo(const char *makeflags)
{
char *fname;
size_t len = 0;

if (isspace(*makeflags))
return false;

do
len++;
while (!isspace(makeflags[len]));

fname = xmemdup(makeflags, len + 1);
fname[len] = '\0';

parent_rfd = open(fname, O_RDONLY);
if (parent_rfd == -1)
return errno;

parent_wfd = open(fname, O_WRONLY);
if (parent_wfd == -1)
return errno;

fcntl(parent_rfd, F_SETFD, 1);
fcntl(parent_wfd, F_SETFD, 1);
return 0;
}

/* --jobserver-auth=R,W - file descriptors provided on the command line */
static int parse_makeflags_pipe(const char *makeflags)
{
Expand Down Expand Up @@ -209,7 +238,9 @@ int tokeninit(void)
char *makeflags = getenv("MAKEFLAGS");
const char *p;
const char *makearg = NULL;
int ret, fd[2];
int fd[2];
int ret = 0;

sigset_t blocked, old;

if (!makeflags)
Expand All @@ -233,7 +264,10 @@ int tokeninit(void)
if (!makearg)
goto out_err;

ret = parse_makeflags_pipe(makearg);
if (!memcmp(makearg, "fifo:", 5))
ret = parse_makeflags_fifo(makearg + 5);
else
ret = parse_makeflags_pipe(makearg);

if (ret)
goto out_err;
Expand Down

0 comments on commit 4aabf9c

Please sign in to comment.