summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2009-10-28 20:41:39 +0000
committerguenther <guenther@openbsd.org>2009-10-28 20:41:39 +0000
commit665ae1c5bae7f828597d6b777c0339606a61e144 (patch)
tree3dd7882a20be558bba8e35c042d50c9f1ca3d9e5
parentErr out if either sigaction fails and not just when both do. (diff)
downloadwireguard-openbsd-665ae1c5bae7f828597d6b777c0339606a61e144.tar.xz
wireguard-openbsd-665ae1c5bae7f828597d6b777c0339606a61e144.zip
Don't catch a signal if we inherited it as ignored. Instigated by
comments from Matt Fisher (mfisher_ix at maine.rr.com). ok otto@
-rw-r--r--usr.bin/sort/sort.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index f8d94064533..99158ffc17c 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.c,v 1.37 2009/10/27 23:59:43 deraadt Exp $ */
+/* $OpenBSD: sort.c,v 1.38 2009/10/28 20:41:39 guenther Exp $ */
/*-
* Copyright (c) 1993
@@ -259,7 +259,7 @@ main(int argc, char *argv[])
outfile = outpath = toutpath;
} else if (!(ch = access(outpath, 0)) &&
strncmp(_PATH_DEV, outpath, 5)) {
- struct sigaction act;
+ struct sigaction oact, act;
int sigtable[] = {SIGHUP, SIGINT, SIGPIPE, SIGXCPU, SIGXFSZ,
SIGVTALRM, SIGPROF, 0};
int outfd;
@@ -284,7 +284,10 @@ main(int argc, char *argv[])
act.sa_flags = SA_RESTART;
act.sa_handler = onsig;
for (i = 0; sigtable[i]; ++i) /* always unlink toutpath */
- sigaction(sigtable[i], &act, 0);
+ if (sigaction(sigtable[i], NULL, &oact) < 0 ||
+ oact.sa_handler != SIG_IGN &&
+ sigaction(sigtable[i], &act, NULL) < 0)
+ err(2, "sigaction");
} else
outfile = outpath;
if (outfp == NULL && (outfp = fopen(outfile, "w")) == NULL)