tee: -i option ignores SIGINT

This commit is contained in:
Greg Reagle 2015-01-22 16:08:25 -05:00 committed by sin
parent 2277b619be
commit 4f0a813ca1
2 changed files with 12 additions and 3 deletions

5
tee.1
View File

@ -3,7 +3,7 @@
tee \- duplicate stdin tee \- duplicate stdin
.SH SYNOPSIS .SH SYNOPSIS
.B tee .B tee
.RB [ \-a ] .RB [ \-ai ]
.RI [ file ...] .RI [ file ...]
.SH DESCRIPTION .SH DESCRIPTION
.B tee .B tee
@ -12,3 +12,6 @@ writes from stdin to stdout, making copies in each file.
.TP .TP
.B \-a .B \-a
append to each file rather than overwriting. append to each file rather than overwriting.
.TP
.B \-i
ignore SIGINT, i.e. the interrupt from keyboard signal

10
tee.c
View File

@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -8,13 +9,13 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-a] [file...]\n", argv0); eprintf("usage: %s [-ai] [file...]\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int aflag = 0; int aflag = 0, iflag = 0;
char buf[BUFSIZ]; char buf[BUFSIZ];
int i, nfps; int i, nfps;
size_t n; size_t n;
@ -24,10 +25,15 @@ main(int argc, char *argv[])
case 'a': case 'a':
aflag = 1; aflag = 1;
break; break;
case 'i':
iflag = 1;
break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;
if (iflag && signal(SIGINT, SIG_IGN) == SIG_ERR)
eprintf("signal:");
nfps = argc + 1; nfps = argc + 1;
fps = ecalloc(nfps, sizeof *fps); fps = ecalloc(nfps, sizeof *fps);