aboutsummaryrefslogtreecommitdiff
path: root/src/rc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-04-09 16:53:21 +0000
committerRoy Marples <roy@marples.name>2007-04-09 16:53:21 +0000
commit3c7c1736b7d6b6d086e9c5b54b963f8e244e3418 (patch)
tree0404eb66de61b5674cc85b678618e54b446ca839 /src/rc.c
parent3a20ea36cc7f1ed89186bdfa46ea0dd2c72742ec (diff)
Use names instead of numbers for reporting signals and trap signals in rc
Diffstat (limited to 'src/rc.c')
-rw-r--r--src/rc.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/rc.c b/src/rc.c
index 48fb9089..2b9629f7 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -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 ();