summaryrefslogtreecommitdiffstats
path: root/usr.bin/truss/setup.c
diff options
context:
space:
mode:
authorsef <sef@FreeBSD.org>1997-12-07 04:08:48 +0000
committersef <sef@FreeBSD.org>1997-12-07 04:08:48 +0000
commitd1f6ae4ce34df5a70d63e6d996f9bb89d98a2f54 (patch)
treea8a676f4f22593011fc45b0729321e36d7ae6613 /usr.bin/truss/setup.c
parent331974b30d4c7321617009d1dfc50a2023934dff (diff)
downloadFreeBSD-src-d1f6ae4ce34df5a70d63e6d996f9bb89d98a2f54.zip
FreeBSD-src-d1f6ae4ce34df5a70d63e6d996f9bb89d98a2f54.tar.gz
Use the new PF_LINGER flag -- when this is set in a process' proc structure,
said process will not have its event mask cleared (and be restarted) on the last close of a procfs/mem file for that pid. This reduces the chance that a truss-monitored process will be left hanging with these bits set and nobody looking for it. This is the least-tested change of all of these, I'm afraid.
Diffstat (limited to 'usr.bin/truss/setup.c')
-rw-r--r--usr.bin/truss/setup.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c
index 3ee5183..6cc1164 100644
--- a/usr.bin/truss/setup.c
+++ b/usr.bin/truss/setup.c
@@ -3,7 +3,7 @@
* I'm afraid.
*/
/*
- * $Id: setup.c,v 1.2 1997/12/06 08:01:00 sef Exp $
+ * $Id: setup.c,v 1.3 1997/12/06 14:42:58 peter Exp $
*/
#include <stdio.h>
@@ -49,6 +49,14 @@ setup_and_wait(char *command[]) {
fcntl(fd, F_SETFD, 1);
if (ioctl(fd, PIOCBIS, &mask) == -1)
err(3, "PIOCBIS");
+ flags = PF_LINGER;
+ /*
+ * The PF_LINGER flag tells procfs not to wake up the
+ * process on last close; normally, this is the behaviour
+ * we want.
+ */
+ if (ioctl(fd, PIOCSFL, &flags) == -1)
+ perror("cannot set PF_LINGER");
execvp(command[0], command);
mask = ~0;
ioctl(fd, PIOCBIC, &mask);
@@ -92,6 +100,7 @@ start_tracing(int pid, int flags) {
char buf[32];
struct procfs_status tmp;
sprintf(buf, "/proc/%d/mem", pid);
+
fd = open(buf, O_RDWR);
if (fd == -1)
err(8, "cannot open %s", buf);
@@ -104,6 +113,16 @@ start_tracing(int pid, int flags) {
if (ioctl(fd, PIOCBIS, &flags) == -1)
err(9, "cannot set procfs event bit mask");
+ /*
+ * This clears the PF_LINGER set above in setup_and_wait();
+ * if truss happens to die before this, then the process
+ * needs to be woken up via procctl.
+ */
+
+ flags = 0;
+ if (ioctl(fd, PIOCSFL, &flags) == -1)
+ perror("cannot clear PF_LINGER");
+
return fd;
}
OpenPOWER on IntegriCloud