diff options
| author | Roy Marples <roy@marples.name> | 2007-04-09 16:53:21 +0000 | 
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2007-04-09 16:53:21 +0000 | 
| commit | 3c7c1736b7d6b6d086e9c5b54b963f8e244e3418 (patch) | |
| tree | 0404eb66de61b5674cc85b678618e54b446ca839 | |
| parent | 3a20ea36cc7f1ed89186bdfa46ea0dd2c72742ec (diff) | |
| download | openrc-3c7c1736b7d6b6d086e9c5b54b963f8e244e3418.tar.xz | |
Use names instead of numbers for reporting signals and trap signals in rc
| -rw-r--r-- | src/Makefile | 2 | ||||
| -rw-r--r-- | src/rc.c | 54 | ||||
| -rw-r--r-- | src/runscript.c | 11 | ||||
| -rw-r--r-- | src/start-stop-daemon.c | 9 | 
4 files changed, 70 insertions, 6 deletions
| diff --git a/src/Makefile b/src/Makefile index 33509c30..91398f47 100644 --- a/src/Makefile +++ b/src/Makefile @@ -98,7 +98,7 @@ override CFLAGS += -DLIB=\"$(LIB)\"  # However, this does save us using libtool when we're testing  # NOTE: The toplevel Makefile for baselayout will automatically  # disable then when doing `make dist` -##override LDFLAGS += -Wl,-rpath . +override LDFLAGS += -Wl,-rpath .  all: $(TARGET) @@ -55,6 +55,7 @@  extern char **environ; +static char *applet = NULL;  static char **env = NULL;  static char **newenv = NULL;  static char **coldplugged_services; @@ -65,7 +66,6 @@ static char **types = NULL;  static char *mycmd = NULL;  static char *myarg = NULL;  static char *tmp = NULL; -static char *applet = NULL;  struct termios *termios_orig; @@ -103,6 +103,9 @@ static void cleanup (void)      rc_rm_dir (RC_SVCDIR "softscripts.new", true);    if (rc_is_dir (RC_SVCDIR "softscripts.old"))      rc_rm_dir (RC_SVCDIR "softscripts.old", true); + +  if (applet) +    free (applet);  }  static int do_e (int argc, char **argv) @@ -453,6 +456,47 @@ static void wait_for_services ()    select (0, NULL, NULL, NULL, &tv);  } +static void handle_signal (int sig) +{ +  pid_t pid; +  int status; +  int serrno = errno; +  char signame[10] = { '\0' }; + +  switch (sig) +    { +    case SIGCHLD: +      do +	{ +	  pid = waitpid (-1, &status, WNOHANG); +	  if (pid < 0) +	    { +	      if (errno && errno != ECHILD) +		eerror ("waitpid: %s", strerror (errno)); +	      return; +	    } +	} while (! WIFEXITED (status) && ! WIFSIGNALED (status)); +      break; + +    case SIGINT: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGINT"); +    case SIGTERM: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGTERM"); +    case SIGQUIT: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGQUIT"); +      eerrorx ("%s: caught %s, aborting", applet, signame); + +    default: +      eerror ("%s: caught unknown signal %d", applet, sig); +    } + +  /* Restore errno */ +  errno = serrno; +} +  int main (int argc, char **argv)  {    char *RUNLEVEL = NULL; @@ -469,7 +513,7 @@ int main (int argc, char **argv)    char ksoftbuffer [PATH_MAX];    if (argv[0]) -    applet = basename (argv[0]); +    applet = strdup (basename (argv[0]));    if (! applet)      eerrorx ("arguments required"); @@ -509,6 +553,12 @@ int main (int argc, char **argv)    atexit (cleanup);    newlevel = argv[0]; +  /* Setup a signal handler */ +  signal (SIGINT, handle_signal); +  signal (SIGQUIT, handle_signal); +  signal (SIGTERM, handle_signal); +  signal (SIGCHLD, handle_signal); +    /* Ensure our environment is pure       Also, add our configuration to it */    env = rc_filter_env (); diff --git a/src/runscript.c b/src/runscript.c index d87d42f0..ad8a251c 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -94,6 +94,7 @@ static void handle_signal (int sig)    pid_t pid;    int status;    int serrno = errno; +  char signame[10] = { '\0' };    switch (sig)      { @@ -113,11 +114,17 @@ static void handle_signal (int sig)  	    }  	} while (! WIFEXITED (status) && ! WIFSIGNALED (status));        break; - +          case SIGINT: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGINT");      case SIGTERM: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGTERM");      case SIGQUIT: -      eerrorx ("%s: caught signal %d, aborting", applet, sig); +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGQUIT"); +      eerrorx ("%s: caught %s, aborting", applet, signame);      default:        eerror ("%s: caught unknown signal %d", applet, sig); diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index fef416cb..b48b7966 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -459,13 +459,20 @@ static void handle_signal (int sig)    int pid;    int status;    int serrno = errno; +  char signame[10] = { '\0' };    switch (sig)      {      case SIGINT: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGINT");      case SIGTERM: +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGTERM");      case SIGQUIT: -      eerrorx ("%s: caught signal %d, aborting", progname, sig); +      if (! signame[0]) +	snprintf (signame, sizeof (signame), "SIGQUIT"); +      eerrorx ("%s: caught %s, aborting", progname, signame);      case SIGCHLD:        while (1) | 
