From d1f6ae4ce34df5a70d63e6d996f9bb89d98a2f54 Mon Sep 17 00:00:00 2001 From: sef Date: Sun, 7 Dec 1997 04:08:48 +0000 Subject: 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. --- usr.bin/truss/setup.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'usr.bin/truss') 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 @@ -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; } -- cgit v1.1