diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-06-18 09:44:10 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-06-18 09:44:10 +0000 |
commit | 7f41223b8dd179beaa95e2cba8cb36dc94d0637e (patch) | |
tree | 0fc81beb85470543cd3aff6d862d184a7bbe8d1f /usr.bin | |
parent | 6ace33ac2e812b824f4257d41ff411001f0a9a2e (diff) |
unlink ktrace file more carefully; wosch/joerg
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ktrace/ktrace.1 | 4 | ||||
-rw-r--r-- | usr.bin/ktrace/ktrace.c | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/usr.bin/ktrace/ktrace.1 b/usr.bin/ktrace/ktrace.1 index 110bc2a9b0f..699f4112c64 100644 --- a/usr.bin/ktrace/ktrace.1 +++ b/usr.bin/ktrace/ktrace.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ktrace.1,v 1.4 1997/05/28 21:59:03 deraadt Exp $ +.\" $OpenBSD: ktrace.1,v 1.5 1997/06/18 09:44:08 deraadt Exp $ .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -76,7 +76,7 @@ to decode it. The options are as follows: .Bl -tag -width indent .It Fl a -Append to the trace file instead of truncating it. +Append to the trace file instead of recreating it. .It Fl C Disable tracing on all user owned processes, and, if executed by root, all processes in the system. diff --git a/usr.bin/ktrace/ktrace.c b/usr.bin/ktrace/ktrace.c index e174f1a6d71..284fabd83e9 100644 --- a/usr.bin/ktrace/ktrace.c +++ b/usr.bin/ktrace/ktrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.c,v 1.4 1997/01/15 23:42:40 millert Exp $ */ +/* $OpenBSD: ktrace.c,v 1.5 1997/06/18 09:44:09 deraadt Exp $ */ /* $NetBSD: ktrace.c,v 1.4 1995/08/31 23:01:44 jtc Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ktrace.c 8.2 (Berkeley) 4/28/95"; #endif -static char *rcsid = "$OpenBSD: ktrace.c,v 1.4 1997/01/15 23:42:40 millert Exp $"; +static char *rcsid = "$OpenBSD: ktrace.c,v 1.5 1997/06/18 09:44:09 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -140,9 +140,19 @@ main(argc, argv) } omask = umask(S_IRWXG|S_IRWXO); - if ((fd = open(tracefile, O_CREAT | O_WRONLY | (append ? 0 : O_TRUNC), - DEFFILEMODE)) < 0) - err(1, tracefile); + if (append) { + if ((fd = open(tracefile, O_CREAT | O_WRONLY, DEFFILEMODE)) < 0) + err(1, tracefile); + if (fstat(fd, &sb) != 0 || sb.st_uid != getuid()) + errx(1, "Refuse to append to %s: not owned by you.", + tracefile); + } else { + if (unlink(tracefile) == -1 && errno != ENOENT) + err(1, "unlink %s", tracefile); + if ((fd = open(tracefile, O_CREAT | O_EXCL | O_WRONLY, + DEFFILEMODE)) < 0) + err(1, tracefile); + } (void)umask(omask); (void)close(fd); @@ -183,9 +193,9 @@ usage() void no_ktrace(sig) - int sig; + int sig; { - (void)fprintf(stderr, + (void)fprintf(stderr, "error:\tktrace() system call not supported in the running kernel\n\tre-compile kernel with 'options KTRACE'\n"); - exit(1); + exit(1); } |