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.
This commit is contained in:
Sean Eric Fagan 1997-12-07 04:08:48 +00:00
parent f2e6e69d92
commit 20fa828fac
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=31597

View File

@ -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;
}