310
310
signal_cb (int signum, siginfo_t *info, void *data)
312
/* NOTE: Using g_printerr as can't call g_warning from a signal callback */
313
if (write (signal_pipe[1], &info->si_signo, sizeof (int)) < 0 ||
312
pid_t receiving_pid = getpid ();
314
/* Report to the main thread:
315
* - The process receiving the signal so we can filter out signals from
316
* child processes that haven't yet called exec closing the signal pipe.
317
* - The signal received
318
* - The process that sent the signal.
320
if (write (signal_pipe[1], &receiving_pid, sizeof (pid_t)) < 0 ||
321
write (signal_pipe[1], &info->si_signo, sizeof (int)) < 0 ||
314
322
write (signal_pipe[1], &info->si_pid, sizeof (pid_t)) < 0)
324
/* NOTE: Using g_printerr as can't call g_warning from a signal callback */
315
325
g_printerr ("Failed to write to signal pipe: %s", strerror (errno));
319
330
handle_signal (GIOChannel *source, GIOCondition condition, gpointer data)
333
pid_t receiving_pid, sending_pid;
323
334
Process *process;
325
if (read (signal_pipe[0], &signo, sizeof (int)) < 0 ||
326
read (signal_pipe[0], &pid, sizeof (pid_t)) < 0)
336
if (read (signal_pipe[0], &receiving_pid, sizeof (pid_t)) < 0 ||
337
read (signal_pipe[0], &signo, sizeof (int)) < 0 ||
338
read (signal_pipe[0], &sending_pid, sizeof (pid_t)) < 0)
328
340
g_warning ("Error reading from signal pipe: %s", strerror (errno));
332
g_debug ("Got signal %d from process %d", signo, pid);
334
process = g_hash_table_lookup (processes, GINT_TO_POINTER (pid));
344
/* Ignore signals received from child processes */
345
if (receiving_pid != getpid ())
348
g_debug ("Got signal %d from process %d", signo, sending_pid);
350
process = g_hash_table_lookup (processes, GINT_TO_POINTER (sending_pid));
335
351
if (process == NULL)
336
352
process = process_get_current ();