mirror of
https://github.com/mirror/make.git
synced 2026-09-05 06:12:55 +08:00
Using anonymous pipes for jobserver support has some advantages: for example there is nothing on disk that needs to be cleaned up. However it has many obscure problems, related to the fact that in order for it to work we need to ensure these resources are properly passed through to child processes that want to use the jobserver. At the same time we don't want to pass the pipe to process which DON'T know about the jobserver. Other processes can open file descriptors which we then think are our jobserver, but aren't. And, we open the pipe file descriptors in blocking mode which doesn't work for all users. See issues such as SV 57178, SV 57242, and SV 62397 To avoid these issues, use named pipes (on systems where they are available) instead of anonoymous pipes. This simplifies many things: we never need to pass open file descriptors to our children; they can open the jobserver named pipe. We don't need to worry about recursive vs. non-recursive children. Users don't have to "pass through" the resources if they are invoking sub-makes. Each child can open its own file descriptor and set blocking as needed. The downside is the named pipe exists on disk and so must be cleaned up when the "top-level" make instance exits. In order to allow make to continue to be used in build systems where older versions of GNU make, or other tools that want to use the jobserver, but don't understand named pipes, introduce a new option --jobserver-style that allows the user to choose anonymous pipes. * NEWS: Announce the change and the --jobserver-style option. * doc/make.1: Add --jobserver-style documentation. * doc/make.texi (Special Variables): Add missing items to .FEATURES. (Options Summary): Add --jobserver-style. (POSIX Jobserver): Named pipes, changes to --jobserver-auth, and the --jobserver-style option. (Windows Jobserver): Document --jobserver-style for Windows. * configure.ac: Check for mkfifo. * src/config.h-vms.template: Undefined HAVE_MKFIFO. * src/config.h.W32.template: Ditto. * src/main.c: Add jobserver-style as a new command line option. (main): Add jobserver-fifo to .FEATURES if supported. Pass the style option to jobserver_setup(). * src/os.h (jobserver_setup): Accept a style string option. * src/posixos.c (enum js_type): Enumeration of the jobserver style. (js_type): Which style we are currently using. (fifo_name): The path to the named pipe (if in use). (jobserver_setup): If no style is given, or "fifo" is given, set up a named pipe: get a temporary file and use mkfifo() on it, then open it for reading and writing. If something fails fall back to anonymous pipes. (jobserver_parse_auth): Parse jobserver-auth to determine the style. If we are using a named pipe, open it. If we're using anonymous pipes ensure they're valid as before. (jobserver_get_invalid_auth): Don't invalidate the jobserver when using named pipes. (jobserver_clear): Clean up memory used for named pipes. (jobserver_acquire_all): Unlink the named pipe when done. * src/w32/w32os.c (jobserver_setup): Check the style argument. * tests/scripts/features/jobserver: Use --jobserver-style to test the anonymous pipe behavior, and also test named pipe/semaphore behavior. Check invalid jobserver-style options. * tests/scripts/functions/shell: Use --jobserver-style to test the anonymous pipe behavior, and also test named pipe/semaphore behavior.
99 lines
3.4 KiB
C
99 lines
3.4 KiB
C
/* Declarations for operating system interfaces for GNU Make.
|
|
Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
|
This file is part of GNU Make.
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify it under the
|
|
terms of the GNU General Public License as published by the Free Software
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
version.
|
|
|
|
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
/* This section provides OS-specific functions to support the jobserver. */
|
|
|
|
#ifdef MAKE_JOBSERVER
|
|
|
|
/* Returns 1 if the jobserver is enabled, else 0. */
|
|
unsigned int jobserver_enabled ();
|
|
|
|
/* Called in the master instance to set up the jobserver initially. */
|
|
unsigned int jobserver_setup (int job_slots, const char *style);
|
|
|
|
/* Called in a child instance to connect to the jobserver.
|
|
Return 1 if we got a valid auth, else 0. */
|
|
unsigned int jobserver_parse_auth (const char* auth);
|
|
|
|
/* Returns an allocated buffer used to pass to child instances. */
|
|
char *jobserver_get_auth ();
|
|
|
|
/* Returns a pointer to a static string used to indicate that the child
|
|
cannot access the jobserver, or NULL if it always can. */
|
|
const char *jobserver_get_invalid_auth ();
|
|
|
|
/* Clear this instance's jobserver configuration. */
|
|
void jobserver_clear ();
|
|
|
|
/* Recover all the jobserver tokens and return the number we got. */
|
|
unsigned int jobserver_acquire_all ();
|
|
|
|
/* Release a jobserver token. If it fails and is_fatal is 1, fatal. */
|
|
void jobserver_release (int is_fatal);
|
|
|
|
/* Notify the jobserver that a child exited. */
|
|
void jobserver_signal ();
|
|
|
|
/* Get ready to start a non-recursive child. */
|
|
void jobserver_pre_child (int);
|
|
|
|
/* Complete starting a non-recursive child. */
|
|
void jobserver_post_child (int);
|
|
|
|
/* Set up to acquire a new token. */
|
|
void jobserver_pre_acquire ();
|
|
|
|
/* Wait until we can acquire a jobserver token.
|
|
TIMEOUT is 1 if we have other jobs waiting for the load to go down;
|
|
in this case we won't wait forever, so we can check the load.
|
|
Returns 1 if we got a token, or 0 if we stopped waiting due to a child
|
|
exiting or a timeout. */
|
|
unsigned int jobserver_acquire (int timeout);
|
|
|
|
#else
|
|
|
|
#define jobserver_enabled() (0)
|
|
#define jobserver_setup(_slots, _style) (0)
|
|
#define jobserver_parse_auth(_auth) (0)
|
|
#define jobserver_get_auth() (NULL)
|
|
#define jobserver_clear() (void)(0)
|
|
#define jobserver_release(_fatal) (void)(0)
|
|
#define jobserver_acquire_all() (0)
|
|
#define jobserver_signal() (void)(0)
|
|
#define jobserver_pre_child(_r) (void)(0)
|
|
#define jobserver_post_child(_r) (void)(0)
|
|
#define jobserver_pre_acquire() (void)(0)
|
|
#define jobserver_acquire(_tmout) (0)
|
|
|
|
#endif
|
|
|
|
/* Create a "bad" file descriptor for stdin when parallel jobs are run. */
|
|
#if defined(VMS) || defined(WINDOWS32) || defined(_AMIGA) || defined(__MSDOS__)
|
|
# define get_bad_stdin() (-1)
|
|
#else
|
|
int get_bad_stdin ();
|
|
#endif
|
|
|
|
/* Set a file descriptor to close/not close in a subprocess. */
|
|
#if defined(VMS) || defined(_AMIGA) || defined(__MSDOS__)
|
|
# define fd_inherit(_i) 0
|
|
# define fd_noinherit(_i) 0
|
|
#else
|
|
void fd_inherit (int);
|
|
void fd_noinherit (int);
|
|
#endif
|