start-stop-daemon: avoid malloc inside sig-handler

same rational as 459783bb

Bug: https://github.com/OpenRC/openrc/issues/589
This commit is contained in:
NRK 2023-01-31 06:31:31 +06:00 committed by Mike Frysinger
parent 5858f980c8
commit ae5e38dce5
1 changed files with 4 additions and 7 deletions

View File

@ -204,20 +204,20 @@ handle_signal(int sig)
{
int status;
int serrno = errno;
char *signame = NULL;
const char *signame = NULL;
switch (sig) {
case SIGINT:
if (!signame)
xasprintf(&signame, "SIGINT");
signame = "SIGINT";
/* FALLTHROUGH */
case SIGTERM:
if (!signame)
xasprintf(&signame, "SIGTERM");
signame = "SIGTERM";
/* FALLTHROUGH */
case SIGQUIT:
if (!signame)
xasprintf(&signame, "SIGQUIT");
signame = "SIGQUIT";
eerrorx("%s: caught %s, aborting", applet, signame);
/* NOTREACHED */
@ -236,9 +236,6 @@ handle_signal(int sig)
eerror("%s: caught unknown signal %d", applet, sig);
}
/* free signame */
free(signame);
/* Restore errno */
errno = serrno;
}