"Fossies" - the Fresh Open Source Software Archive

Member "xxgdb-1.12/signals.c" (6 Apr 1995, 5091 Bytes) of package /linux/misc/old/xxgdb-1.12.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*****************************************************************************
    2  *
    3  *  xdbx - X Window System interface to the dbx debugger
    4  *
    5  *  Copyright 1989 The University of Texas at Austin
    6  *  Copyright 1990 Microelectronics and Computer Technology Corporation
    7  *
    8  *  Permission to use, copy, modify, and distribute this software and its
    9  *  documentation for any purpose and without fee is hereby granted,
   10  *  provided that the above copyright notice appear in all copies and that
   11  *  both that copyright notice and this permission notice appear in
   12  *  supporting documentation, and that the name of The University of Texas
   13  *  and Microelectronics and Computer Technology Corporation (MCC) not be 
   14  *  used in advertising or publicity pertaining to distribution of
   15  *  the software without specific, written prior permission.  The
   16  *  University of Texas and MCC makes no representations about the 
   17  *  suitability of this software for any purpose.  It is provided "as is" 
   18  *  without express or implied warranty.
   19  *
   20  *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
   21  *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
   22  *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
   23  *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
   24  *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
   25  *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   26  *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   27  *
   28  *  Author:     Po Cheung
   29  *  Created:    March 10, 1989
   30  *
   31  *****************************************************************************/
   32 
   33 /* signals.c
   34  *
   35  *   Signal handling for xdbx and dbx.
   36  *
   37  *   kill_hanlder():    For SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGTERM
   38  *          print error message and exit with signal status.
   39  *   quit_handler():    SIGCHLD, wait for dbx to die and exit gracefully.
   40  *   stop_handler():    SIGTSTP, stop dbx process, then stop own process.
   41  *   cont_handler():    SIGCONT, continue dbx process.
   42  *   trap_signals():    Install signal handlers.
   43  */
   44 
   45 /*
   46  * iand 94/02/10 eliminate signal handler prototype warnings on SVR4 and similar systems
   47  * iand 94/02/10 use reliable signals on SYSV
   48  *
   49  */
   50 
   51 #include <stdio.h>
   52 #include <signal.h>
   53 #ifdef  _POSIX_SOURCE
   54 #include <sys/types.h>
   55 #endif
   56 #include <sys/wait.h>
   57 #include "global.h"
   58 
   59 #if ( defined(SYSV) || defined(SVR4) ) && !defined(HPUX) && !defined(linux)
   60 #define signal sigset
   61 #endif
   62 
   63 /*  Kill the dbx child process and then exits. */
   64 /*  ARGSUSED */
   65 static void 
   66 kill_handler(sig)
   67     int sig;
   68 {
   69     if (FalseSignal) {
   70     FalseSignal = FALSE;
   71     return;
   72     }
   73     kill(dbxpid, SIGKILL);
   74     switch (sig) {
   75       case SIGINT  : fprintf(stderr, "Interrupt\n"); break;
   76       case SIGQUIT : fprintf(stderr, "Quit\n"); break;
   77       case SIGILL  : fprintf(stderr, "Illegal instruction\n"); break;
   78       case SIGBUS  : fprintf(stderr, "Bus error\n"); break;
   79       case SIGSEGV : fprintf(stderr, "Segmentation violation\n"); break;
   80       case SIGTERM : fprintf(stderr, "Soft kill\n"); break;
   81     }
   82 #ifdef CREATE_IO_WINDOW
   83     if (iowinpid) kill(iowinpid, SIGKILL);
   84     iowinpid = 0;
   85     sleep(10);
   86 #endif /* CREATE_IO_WINDOW */
   87     if (debug)
   88         fprintf(stderr,"kill_handler signal %d\n", sig);
   89     exit(sig);
   90 }
   91 
   92 
   93 static void quit_handler(int sig)
   94 {
   95     int pid;
   96 #ifdef SYSV 
   97     int status;
   98 #else
   99     union wait status;
  100 #endif /* SYSV */
  101 
  102     /*  wait for the child to report its status; if the child has died, 
  103      *  exit gracefully.
  104      */
  105 #ifdef SYSV 
  106 #if 1  /* instead of ifdef SVR4 */
  107     pid = waitpid((pid_t)0, &status, WNOHANG|WUNTRACED);    /* (MJH) */
  108 #else
  109     pid = waitpid(&status, NULL , WNOHANG|WUNTRACED);
  110 #endif /* SVR4 */
  111 #else
  112    pid =  wait3(&status, WNOHANG|WUNTRACED, NULL);
  113 #endif /* SYSV */
  114 
  115 #ifdef EDIT_BUTTON
  116     /* dont die if sub edit process dies */
  117     if (pid == dbxpid && (WIFEXITED(status) || WIFSIGNALED(status))
  118     && !WIFSTOPPED(status))
  119 #else
  120     if ((WIFEXITED(status) || WIFSIGNALED(status)) && !WIFSTOPPED(status))
  121 #endif /* EDIT_BUTTON */
  122 
  123         {
  124 #ifdef CREATE_IO_WINDOW
  125         if (iowinpid)
  126             kill(iowinpid, SIGKILL);
  127         iowinpid = 0;
  128 #endif /* CREATE_IO_WINDOW */
  129         if (debug) {
  130             fprintf(stderr,"quit_handler (child must have died ?)\n");
  131         }
  132         exit(1);
  133         }
  134 }
  135 
  136 
  137 static void stop_handler(int sig)
  138 {
  139     if (dbxpid)
  140     kill(dbxpid, SIGSTOP);  /* stop dbx process */
  141     kill(0, SIGSTOP);       /* stop own process */
  142 }
  143 
  144 
  145 static void cont_handler(int sig)
  146 {
  147     if (dbxpid) {
  148     sleep(1);       /* we need this */
  149     kill(dbxpid, SIGCONT);  /* continue dbx after stop */
  150     }
  151 }
  152 
  153 
  154 /*
  155  *  Trap signals to xdbx so that the child process can be handled properly.
  156  */
  157 void trap_signals()
  158 {
  159     signal(SIGINT,  kill_handler);
  160     signal(SIGQUIT, kill_handler);
  161     signal(SIGILL,  kill_handler);
  162     signal(SIGBUS,  kill_handler);
  163     signal(SIGSEGV, kill_handler);
  164     signal(SIGTERM, kill_handler);
  165 
  166     signal(SIGTSTP, stop_handler);  /* stop signal from keyboard */
  167     signal(SIGCONT, cont_handler);  /* continue after stop */
  168     signal(SIGCHLD, quit_handler);  /* child status has changed */
  169 }