mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 07:48:50 -05:00
avoid unsafe functions in signal handler
signal(7) lists a set of functions that can safely be called from within a signal handler. Even fileno and strlen are not guaranteed to be safe. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
8d11aa3cdf
commit
220a3ce2b8
@ -311,21 +311,19 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
|
|||||||
*/
|
*/
|
||||||
static void handler(int signum)
|
static void handler(int signum)
|
||||||
{
|
{
|
||||||
int out = fileno(stdout);
|
|
||||||
int err = fileno(stderr);
|
|
||||||
const char *msg;
|
|
||||||
if(signum == SIGSEGV) {
|
if(signum == SIGSEGV) {
|
||||||
msg = "\nerror: segmentation fault\n"
|
const char msg[] = "\nerror: segmentation fault\n"
|
||||||
"Please submit a full bug report with --debug if appropriate.\n";
|
"Please submit a full bug report with --debug if appropriate.\n";
|
||||||
xwrite(err, msg, strlen(msg));
|
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
||||||
exit(signum);
|
exit(signum);
|
||||||
} else if(signum == SIGINT || signum == SIGHUP) {
|
} else if(signum == SIGINT || signum == SIGHUP) {
|
||||||
if(signum == SIGINT) {
|
if(signum == SIGINT) {
|
||||||
msg = "\nInterrupt signal received\n";
|
const char msg[] = "\nInterrupt signal received\n";
|
||||||
|
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
||||||
} else {
|
} else {
|
||||||
msg = "\nHangup signal received\n";
|
const char msg[] = "\nHangup signal received\n";
|
||||||
|
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
||||||
}
|
}
|
||||||
xwrite(err, msg, strlen(msg));
|
|
||||||
if(alpm_trans_interrupt(config->handle) == 0) {
|
if(alpm_trans_interrupt(config->handle) == 0) {
|
||||||
/* a transaction is being interrupted, don't exit pacman yet. */
|
/* a transaction is being interrupted, don't exit pacman yet. */
|
||||||
return;
|
return;
|
||||||
@ -337,7 +335,7 @@ static void handler(int signum)
|
|||||||
/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman */
|
/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman */
|
||||||
alpm_unlock(config->handle);
|
alpm_unlock(config->handle);
|
||||||
/* output a newline to be sure we clear any line we may be on */
|
/* output a newline to be sure we clear any line we may be on */
|
||||||
xwrite(out, "\n", 1);
|
xwrite(STDOUT_FILENO, "\n", 1);
|
||||||
_Exit(128 + signum);
|
_Exit(128 + signum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user