~robert-ancell/lightdm/signal-fix

« back to all changes in this revision

Viewing changes to src/process.c

  • Committer: Robert Ancell
  • Date: 2013-05-16 03:06:51 UTC
  • Revision ID: robert.ancell@canonical.com-20130516030651-t0vph5pdkrk33c1k
Ignore signals received in child processes that could cause the main process to exit

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
static void
310
310
signal_cb (int signum, siginfo_t *info, void *data)
311
311
{
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 ();
 
313
 
 
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.
 
319
     */
 
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)
 
323
    {
 
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));
 
326
    }
316
327
}
317
328
 
318
329
static gboolean
319
330
handle_signal (GIOChannel *source, GIOCondition condition, gpointer data)
320
331
{
321
332
    int signo;
322
 
    pid_t pid;
 
333
    pid_t receiving_pid, sending_pid;
323
334
    Process *process;
324
335
 
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)
327
339
    {
328
340
        g_warning ("Error reading from signal pipe: %s", strerror (errno));
329
341
        return TRUE;
330
342
    }
331
343
 
332
 
    g_debug ("Got signal %d from process %d", signo, pid);
333
 
 
334
 
    process = g_hash_table_lookup (processes, GINT_TO_POINTER (pid));
 
344
    /* Ignore signals received from child processes */
 
345
    if (receiving_pid != getpid ())
 
346
        return;
 
347
 
 
348
    g_debug ("Got signal %d from process %d", signo, sending_pid);
 
349
 
 
350
    process = g_hash_table_lookup (processes, GINT_TO_POINTER (sending_pid));
335
351
    if (process == NULL)
336
352
        process = process_get_current ();
337
353
    if (process)