diff options
author | NRK <nrk@disroot.org> | 2023-01-27 18:55:10 +0600 |
---|---|---|
committer | Mike Frysinger <vapier@gmail.com> | 2023-01-28 13:08:00 -0500 |
commit | 459783bbad912e5eda6533959c09b94db1d385d1 (patch) | |
tree | 07266d905b14f3f836b76780c408345526483780 /src | |
parent | a28bdc7e5c60058075b6d5721f8e9433ec1893d6 (diff) |
openrc: avoid unnecessary malloc inside sig-handler
malloc (called by xasprintf) is not async-signal-safe. beside, the
string here is constant, so there's no need to malloc it all.
eerrorx isn't async-signal-safe either (due to calling fprintf and exit)
but consequence of them are _typically_ not as grave as calling malloc
while it's internal state is inconsistent.
Bug: https://github.com/OpenRC/openrc/issues/589
Diffstat (limited to 'src')
-rw-r--r-- | src/openrc/rc.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/openrc/rc.c b/src/openrc/rc.c index 183663d0..55e85078 100644 --- a/src/openrc/rc.c +++ b/src/openrc/rc.c @@ -382,7 +382,7 @@ static void handle_signal(int sig) { int serrno = errno; - char *signame = NULL; + const char *signame = NULL; pid_t pid; RC_PID *pi; int status = 0; @@ -414,15 +414,15 @@ handle_signal(int 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 */ case SIGUSR1: |