cannot access the jobserver, or NULL if it always can. */
const char *jobserver_get_invalid_auth ();
-/* Clear this instance's jobserver configuration. */
+/* Clear this instance's jobserver configuration.
+ This method might be invoked from a signal handler. */
void jobserver_clear ();
-/* Recover all the jobserver tokens and return the number we got. */
+/* Recover all the jobserver tokens and return the number we got.
+ Will also run jobserver_clear() as a side-effect. */
unsigned int jobserver_acquire_all ();
/* Release a jobserver token. If it fails and is_fatal is 1, fatal. */
Return 1 if we got a valid mutex, else 0. */
unsigned int osync_parse_mutex (const char *mutex);
-/* Clean up this instance's output sync facilities. */
+/* Clean up this instance's output sync facilities.
+ This method might be invoked from a signal handler. */
void osync_clear ();
/* Acquire the output sync lock. This will wait until available.
/* This section provides OS-specific functions to support the jobserver. */
+/* True if this is the root make instance. */
+static unsigned char job_root = 0;
+
/* These track the state of the jobserver pipe. Passed to child instances. */
static int job_fds[2] = { -1, -1 };
/* When using pselect() we want the read to be non-blocking. */
set_blocking (job_fds[0], 0);
+ job_root = 1;
+
return 1;
}
job_fds[0] = job_fds[1] = job_rfd = -1;
- free (fifo_name);
- fifo_name = NULL;
+ if (fifo_name)
+ {
+ if (job_root)
+ {
+ int r;
+ EINTRLOOP (r, unlink (fifo_name));
+ }
+
+ if (!handling_fatal_signal)
+ {
+ free (fifo_name);
+ fifo_name = NULL;
+ }
+ }
js_type = js_none;
}
++tokens;
}
- if (fifo_name)
- EINTRLOOP (r, unlink (fifo_name));
-
DB (DB_JOBS, ("Acquired all %u jobserver tokens.\n", tokens));
+ jobserver_clear ();
+
return tokens;
}
static char *osync_tmpfile = NULL;
-static unsigned int sync_parent = 0;
+static unsigned int sync_root = 0;
unsigned int
osync_enabled ()
if (osync_handle >= 0)
{
fd_noinherit (osync_handle);
- sync_parent = 1;
+ sync_root = 1;
}
}
osync_handle = -1;
}
- if (sync_parent && osync_tmpfile)
+ if (sync_root && osync_tmpfile)
{
- unlink (osync_tmpfile);
+ int r;
+
+ EINTRLOOP (r, unlink (osync_tmpfile));
osync_tmpfile = NULL;
}
}
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 1;
+ /* We don't want to keep waiting on EINTR. */
if (fcntl (osync_handle, F_SETLKW, &fl) == -1)
{
perror ("fcntl()");
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 1;
+ /* We don't want to keep waiting on EINTR. */
if (fcntl (osync_handle, F_SETLKW, &fl) == -1)
perror ("fcntl()");
}
if (pipe (pd) == 0)
{
/* Close the write side. */
- (void) close (pd[1]);
+ close (pd[1]);
/* Save the read side. */
bad_stdin = pd[0];