From dac824dc8b08d86cd5ef1eb4a31dc0a514fabd8d Mon Sep 17 00:00:00 2001 From: Philip Guenthe Date: Wed, 28 Oct 2009 20:41:40 +0000 Subject: 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@ --- usr.bin/sort/sort.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'usr.bin') 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) -- cgit v1.2.3