ktrace.c (c115df18cd0d5b01a18af0c608bc8b519b62273b) | ktrace.c (9bedbe6c7dcc2578c7c8f1327d0005adf50258f8) |
---|---|
1/*- 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = | 1/*- 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = |
45 "$Id$"; | 45 "$Id: ktrace.c,v 1.8 1997/02/22 19:55:27 peter Exp $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/stat.h> 50#include <sys/file.h> 51#include <sys/time.h> 52#include <sys/errno.h> 53#include <sys/uio.h> --- 13 unchanged lines hidden (view full) --- 67 char **argv; 68{ 69 extern int optind; 70 extern char *optarg; 71 enum { NOTSET, CLEAR, CLEARALL } clear; 72 int append, ch, fd, inherit, ops, pid, pidset, trpoints; 73 char *tracefile; 74 mode_t omask; | 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/stat.h> 50#include <sys/file.h> 51#include <sys/time.h> 52#include <sys/errno.h> 53#include <sys/uio.h> --- 13 unchanged lines hidden (view full) --- 67 char **argv; 68{ 69 extern int optind; 70 extern char *optarg; 71 enum { NOTSET, CLEAR, CLEARALL } clear; 72 int append, ch, fd, inherit, ops, pid, pidset, trpoints; 73 char *tracefile; 74 mode_t omask; |
75 struct stat sb; |
|
75 76 clear = NOTSET; 77 append = ops = pidset = inherit = 0; 78 trpoints = DEF_POINTS; 79 tracefile = DEF_TRACEFILE; 80 while ((ch = getopt(argc,argv,"aCcdf:g:ip:t:")) != EOF) 81 switch((char)ch) { 82 case 'a': --- 52 unchanged lines hidden (view full) --- 135 ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE; 136 137 if (ktrace(tracefile, ops, trpoints, pid) < 0) 138 err(1, tracefile); 139 exit(0); 140 } 141 142 omask = umask(S_IRWXG|S_IRWXO); | 76 77 clear = NOTSET; 78 append = ops = pidset = inherit = 0; 79 trpoints = DEF_POINTS; 80 tracefile = DEF_TRACEFILE; 81 while ((ch = getopt(argc,argv,"aCcdf:g:ip:t:")) != EOF) 82 switch((char)ch) { 83 case 'a': --- 52 unchanged lines hidden (view full) --- 136 ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE; 137 138 if (ktrace(tracefile, ops, trpoints, pid) < 0) 139 err(1, tracefile); 140 exit(0); 141 } 142 143 omask = umask(S_IRWXG|S_IRWXO); |
143 if ((fd = open(tracefile, O_CREAT | O_WRONLY | (append ? 0 : O_TRUNC), 144 DEFFILEMODE)) < 0) 145 err(1, tracefile); | 144 if (append) { 145 if ((fd = open(tracefile, O_CREAT | O_WRONLY, DEFFILEMODE)) < 0) 146 err(1, tracefile); 147 if (fstat(fd, &sb) != 0 || sb.st_uid != getuid()) 148 errx(1, "Refuse to append to %s not owned by you.", 149 tracefile); 150 } else { 151 if (unlink(tracefile) == -1 && errno != ENOENT) 152 err(1, "unlink %s", tracefile); 153 if ((fd = open(tracefile, O_CREAT | O_EXCL | O_WRONLY, 154 DEFFILEMODE)) < 0) 155 err(1, tracefile); 156 } |
146 (void)umask(omask); 147 (void)close(fd); 148 149 if (*argv) { 150 if (ktrace(tracefile, ops, trpoints, getpid()) < 0) 151 err(1, tracefile); 152 execvp(argv[0], &argv[0]); 153 err(1, "exec of '%s' failed", argv[0]); --- 38 unchanged lines hidden --- | 157 (void)umask(omask); 158 (void)close(fd); 159 160 if (*argv) { 161 if (ktrace(tracefile, ops, trpoints, getpid()) < 0) 162 err(1, tracefile); 163 execvp(argv[0], &argv[0]); 164 err(1, "exec of '%s' failed", argv[0]); --- 38 unchanged lines hidden --- |