summaryrefslogtreecommitdiff
path: root/usr.bin/diff/diff.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-06-25 03:37:33 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-06-25 03:37:33 +0000
commitc40b6440ed441f569bb89ee27c1695ac0432547b (patch)
tree4a3ad7d7e667635005df68d686a1178db69df35c /usr.bin/diff/diff.c
parent8a09840496aac00b47ef80432ea41fc452208dbf (diff)
exit path signal race safe
Diffstat (limited to 'usr.bin/diff/diff.c')
-rw-r--r--usr.bin/diff/diff.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c
index 4625f99a9e0..8eba550652c 100644
--- a/usr.bin/diff/diff.c
+++ b/usr.bin/diff/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.3 2003/06/25 03:02:33 tedu Exp $ */
+/* $OpenBSD: diff.c,v 1.4 2003/06/25 03:37:32 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -126,7 +126,7 @@ main(int argc, char **argv)
if (*argp) {
fprintf(stderr,
"diff: -c: bad count\n");
- done();
+ done(0);
}
argp = "";
} else
@@ -138,7 +138,7 @@ main(int argc, char **argv)
case 'S':
if (*argp == 0) {
fprintf(stderr, "diff: use -Sstart\n");
- done();
+ done(0);
}
start = argp;
*--argp = 0; /* don't pass it on */
@@ -155,40 +155,40 @@ main(int argc, char **argv)
default:
fprintf(stderr, "diff: -%s: unknown option\n",
--argp);
- done();
+ done(0);
}
}
if (argc != 2) {
fprintf(stderr, "diff: two filename arguments required\n");
- done();
+ done(0);
}
file1 = argv[0];
file2 = argv[1];
if (hflag && opt) {
fprintf(stderr,
"diff: -h doesn't support -e, -f, -n, -c, or -I\n");
- done();
+ done(0);
}
if (!strcmp(file1, "-"))
stb1.st_mode = S_IFREG;
else if (stat(file1, &stb1) < 0) {
fprintf(stderr, "diff: ");
perror(file1);
- done();
+ done(0);
}
if (!strcmp(file2, "-"))
stb2.st_mode = S_IFREG;
else if (stat(file2, &stb2) < 0) {
fprintf(stderr, "diff: ");
perror(file2);
- done();
+ done(0);
}
if ((stb1.st_mode & S_IFMT) == S_IFDIR &&
(stb2.st_mode & S_IFMT) == S_IFDIR) {
diffdir(argv);
} else
diffreg();
- done();
+ done(0);
/* notreached */
return (0);
}
@@ -208,10 +208,12 @@ max(int a, int b)
}
void
-done(void)
+done(int sig)
{
if (tempfile)
unlink(tempfile);
+ if (sig)
+ _exit(status);
exit(status);
}
@@ -219,7 +221,7 @@ void
catchsig(int sigraised)
{
/* print something? */
- done();
+ done(0);
}
void *
@@ -246,5 +248,5 @@ static void
noroom(void)
{
fprintf(stderr, "diff: files too big, try -h\n");
- done();
+ done(0);
}