jobserver_connect, jobserver_create, jobserver_create_n, jobserver_close - connect to or create and then quit a jobserver
#include <jobserver.h>
int jobserver_connect(struct jobserver * js);
int jobserver_create (struct jobserver * js, char const * tokens);
int jobserver_create_n(struct jobserver * js, size_t size, char token);
int jobserver_close(struct jobserver * js);
The jobserver_connect() function tries to connect to an environment-defined jobserver js.
The jobserver_create() and jobserver_create_n() functions create a new jobserver js and publish it to the environment. The jobserver is initialized with either a null-terminated word of tokens or with size tokens as additional job slots to the free token.
To create a jobserver that spawns one child after the other, no additional token need be passed. In general, if the jobserver is created after a -j X option, size or strlen(tokens) should be X-1.
The jobserver_close() function closes jobserver js if there are no remaining jobs. Note that it does not modify the environment variable, use jobserver_unsetenv(3) to achieve this.
On success, the jobserver_open() and jobserver_close() functions return 0.
On success, the jobserver_create() and jobserver_create_n() functions return the number of possible parallel jobs, that is the number tokens available in the jobserver pipe plus one (size + 1 or strlen(tokens) + 1).
On error, -1 is returned and errno is set accordingly.
(Linux only) The signalfd file descriptor could not be created.
The jobserver pipe is closed because the current process was spawned by Make without the ’+’ prefix, see section 13.1 of the GNU Make documentation.
Either one of the jobserver file descriptors is invalid.
No jobserver found.
Error while parsing the environment.
The number of tokens in the pipe exceeds PIPE_BUF.
Too many file descriptors for the process.
Too many file descriptors for the system.
Not enough memory to set the environment variable.
Cannot count tokens, call jobserver_wait(3) and try again.
Not all jobs have been waited for yet, call jobserver_collect(3) and try again.
No jobs remain but some tokens have not been given back. You might want to inform the user.
jobserver(7), jobserver_clear(3), jobserver_collect(3), jobserver_launch_job(3), jobserver_print(3), jobserver_getenv(3), jobserver_setenv(3), jobserver_terminate_job(3), jobserver_unsetenv(3), jobserver_wait(3)