summaryrefslogtreecommitdiff
path: root/usr.bin/ktrace
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>1997-03-15 10:40:15 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>1997-03-15 10:40:15 +0000
commitdecd933ec9c9c2078c335628613764a227c45841 (patch)
treedf1f30d6151789658a777ac225c94a06abf433f1 /usr.bin/ktrace
parent6cc65521df71c45e308a3ab762f13b160211ab73 (diff)
Notes
Diffstat (limited to 'usr.bin/ktrace')
-rw-r--r--usr.bin/ktrace/ktrace.12
-rw-r--r--usr.bin/ktrace/ktrace.c19
2 files changed, 16 insertions, 5 deletions
diff --git a/usr.bin/ktrace/ktrace.1 b/usr.bin/ktrace/ktrace.1
index 3fe47e4722bb..48a2e646e284 100644
--- a/usr.bin/ktrace/ktrace.1
+++ b/usr.bin/ktrace/ktrace.1
@@ -75,7 +75,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 5b4da266c06d..c315f7f33742 100644
--- a/usr.bin/ktrace/ktrace.c
+++ b/usr.bin/ktrace/ktrace.c
@@ -42,7 +42,7 @@ static char copyright[] =
static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: ktrace.c,v 1.5 1996/06/30 09:40:44 joerg Exp $";
+ "$Id: ktrace.c,v 1.6 1996/09/19 19:50:13 phk Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -72,6 +72,7 @@ main(argc, argv)
int append, ch, fd, inherit, ops, pid, pidset, trpoints;
char *tracefile;
mode_t omask;
+ struct stat sb;
clear = NOTSET;
append = ops = pidset = inherit = 0;
@@ -140,9 +141,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);