1 /* Declarations for operating system interfaces for GNU Make.
2 Copyright (C) 2016-2022 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #define IO_UNKNOWN 0x0001
18 #define IO_COMBINED_OUTERR 0x0002
19 #define IO_STDIN_OK 0x0004
20 #define IO_STDOUT_OK 0x0008
21 #define IO_STDERR_OK 0x0010
22
23 #if defined(VMS) || defined(_AMIGA) || defined(__MSDOS__)
24 # define check_io_state() (IO_STDIN_OK|IO_STDOUT_OK|IO_STDERR_OK)
25 # define fd_inherit(_i) (0)
26 # define fd_noinherit(_i) (0)
27 # define fd_set_append(_i) (void)(0)
28 # define os_anontmp() (-1)
29 #else
30
31 /* Determine the state of stdin/stdout/stderr. */
32 unsigned int check_io_state (void);
33
34 /* Set a file descriptor to close/not close in a subprocess. */
35 void fd_inherit (int);
36 void fd_noinherit (int);
37
38 /* If the file descriptor is for a file put it into append mode. */
39 void fd_set_append (int);
40
41 /* Return a file descriptor for a new anonymous temp file, or -1. */
42 int os_anontmp (void);
43 #endif
44
45 /* This section provides OS-specific functions to support the jobserver. */
46
47 #ifdef MAKE_JOBSERVER
48
49 /* Returns 1 if the jobserver is enabled, else 0. */
50 unsigned int jobserver_enabled (void);
51
52 /* Called in the parent make to set up the jobserver initially. */
53 unsigned int jobserver_setup (int job_slots, const char *style);
54
55 /* Called in a child instance to connect to the jobserver.
56 Return 1 if we got a valid auth, else 0. */
57 unsigned int jobserver_parse_auth (const char* auth);
58
59 /* Returns an allocated buffer used to pass to child instances. */
60 char *jobserver_get_auth (void);
61
62 /* Returns a pointer to a static string used to indicate that the child
63 cannot access the jobserver, or NULL if it always can. */
64 const char *jobserver_get_invalid_auth (void);
65
66 /* Clear this instance's jobserver configuration.
67 This method might be invoked from a signal handler. */
68 void jobserver_clear (void);
69
70 /* Recover all the jobserver tokens and return the number we got.
71 Will also run jobserver_clear() as a side-effect. */
72 unsigned int jobserver_acquire_all (void);
73
74 /* Release a jobserver token. If it fails and is_fatal is 1, fatal. */
75 void jobserver_release (int is_fatal);
76
77 /* Notify the jobserver that a child exited. */
78 void jobserver_signal (void);
79
80 /* Get ready to start a non-recursive child. */
81 void jobserver_pre_child (int);
82
83 /* Complete starting a non-recursive child. */
84 void jobserver_post_child (int);
85
86 /* Set up to acquire a new token. */
87 void jobserver_pre_acquire (void);
88
89 /* Wait until we can acquire a jobserver token.
90 TIMEOUT is 1 if we have other jobs waiting for the load to go down;
91 in this case we won't wait forever, so we can check the load.
92 Returns 1 if we got a token, or 0 if we stopped waiting due to a child
93 exiting or a timeout. */
94 unsigned int jobserver_acquire (int timeout);
95
96 #else
97
98 #define jobserver_enabled() (0)
99 #define jobserver_setup(_slots, _style) (0)
100 #define jobserver_parse_auth(_auth) (0)
101 #define jobserver_get_auth() (NULL)
102 #define jobserver_get_invalid_auth() (NULL)
103 #define jobserver_clear() (void)(0)
104 #define jobserver_release(_fatal) (void)(0)
105 #define jobserver_acquire_all() (0)
106 #define jobserver_signal() (void)(0)
107 #define jobserver_pre_child(_r) (void)(0)
108 #define jobserver_post_child(_r) (void)(0)
109 #define jobserver_pre_acquire() (void)(0)
110 #define jobserver_acquire(_tmout) (0)
111
112 #endif /* MAKE_JOBSERVER */
113
114 #ifndef NO_OUTPUT_SYNC
115
116 /* Returns 1 if output sync is enabled, else 0. */
117 unsigned int osync_enabled (void);
118
119 /* Called in the parent make to set up output sync initially. */
120 void osync_setup (void);
121
122 /* Returns an allocated buffer containing output sync info to pass to child
123 instances, or NULL if not needed. */
124 char *osync_get_mutex (void);
125
126 /* Called in a child instance to obtain info on the output sync mutex.
127 Return 1 if we got a valid mutex, else 0. */
128 unsigned int osync_parse_mutex (const char *mutex);
129
130 /* Clean up this instance's output sync facilities.
131 This method might be invoked from a signal handler. */
132 void osync_clear (void);
133
134 /* Acquire the output sync lock. This will wait until available.
135 Returns 0 if there was an error getting the semaphore. */
136 unsigned int osync_acquire (void);
137
138 /* Release the output sync lock. */
139 void osync_release (void);
140
141 #else
142
143 #define osync_enabled() (0)
144 #define osync_setup() (void)(0)
145 #define osync_get_mutex() (0)
146 #define osync_parse_mutex(_s) (0)
147 #define osync_clear() (void)(0)
148 #define osync_acquire() (1)
149 #define osync_release() (void)(0)
150
151 #endif /* NO_OUTPUT_SYNC */
152
153 /* Create a "bad" file descriptor for stdin when parallel jobs are run. */
154 #if defined(VMS) || defined(WINDOWS32) || defined(_AMIGA) || defined(__MSDOS__)
155 # define get_bad_stdin() (-1)
156 #else
157 int get_bad_stdin (void);
158 #endif