Use names instead of numbers for reporting signals and trap signals in rc
This commit is contained in:
parent
3a20ea36cc
commit
3c7c1736b7
@ -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)
|
||||
|
||||
|
54
src/rc.c
54
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 ();
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user