Changeset 147224 for trunk/base


Ignore:
Timestamp:
Mar 31, 2016, 3:53:21 PM (4 years ago)
Author:
raimue@…
Message:

pextlib/system: ignore signals SIGINT/SIGQUIT

When a SIGINT/SIGQUIT was generated by the user during execution of a program,
both the program and the waiting parent tclsh process got interrupted by
a signal. However, the handler in the tclsh only generated an unpleasant error
message that a SIGINT/SIGQUIT was received.

With this change, only the child will handle the signal, hopefully ending its
execution. If the program handles SIGINT/SIGQUIT, it might still just terminate
with a normal exit code, so there is no chance for us to determine that it was
killed by a signal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/pextlib1.0/system.c

    r141420 r147224  
    5757#include <limits.h>
    5858#include <errno.h>
     59#include <signal.h>
    5960
    6061#include "system.h"
     
    188189    }
    189190
     191    /*
     192     * Ignore SIGINT and SIGQUIT, just like system(3)
     193     *
     194     * system(3) also blocks SIGCHLD during the execution of the program.
     195     * However, that would make our wait(2) call more complicated. As we are
     196     * not relying on delivery of SIGCHLD anywhere else, we just do not change
     197     * the handling here at all.
     198     */
     199    struct sigaction sa, old_sa_int, old_sa_quit;
     200    memset(&sa, 0, sizeof(sa));
     201    sa.sa_handler = SIG_IGN;
     202    sigemptyset(&sa.sa_mask);
     203    sigaction(SIGINT, &sa, &old_sa_int);
     204    sigaction(SIGQUIT, &sa, &old_sa_quit);
     205
     206    /* fork a new process */
    190207    pid = fork();
    191208    switch (pid) {
     
    229246            }
    230247        }
     248
     249        /* restore original signal handling */
     250        sigaction(SIGINT, &old_sa_int, NULL);
     251        sigaction(SIGQUIT, &old_sa_quit, NULL);
    231252
    232253        /* XXX ugly string constants */
     
    343364    }
    344365
     366    /* restore original signal handling */
     367    sigaction(SIGINT, &old_sa_int, NULL);
     368    sigaction(SIGQUIT, &old_sa_quit, NULL);
     369
    345370    if (odup) {
    346371        /* Cleanup. */
Note: See TracChangeset for help on using the changeset viewer.