When doing the initial open of the proc via procfs, complain if we are

unable to open the /proc/pid/mem file.  Otherwise doing a truss on
a nonexistant pid makes us return success even though no such process
exists.
This commit is contained in:
alfred 2005-03-27 12:53:25 +00:00
parent 187844b0ae
commit fbf5f18034
3 changed files with 14 additions and 8 deletions

View File

@ -32,7 +32,7 @@
*/
extern int setup_and_wait(char **);
extern int start_tracing(int, int, int);
extern int start_tracing(int, int, int, int);
extern void restore_proc(int);
extern const char *ioctlname(register_t val);
extern char *strsig(int sig);

View File

@ -165,12 +165,16 @@ main(int ac, char **av)
char **command;
struct procfs_status pfs;
struct ex_types *funcs;
int in_exec = 0;
char *fname = NULL;
int sigexit = 0;
int in_exec, sigexit, initial_open;
char *fname;
struct trussinfo *trussinfo;
char *signame;
in_exec = 0;
sigexit = 0;
fname = NULL;
initial_open = 1;
/* Initialize the trussinfo struct */
trussinfo = (struct trussinfo *)malloc(sizeof(struct trussinfo));
if (trussinfo == NULL)
@ -246,9 +250,11 @@ main(int ac, char **av)
START_TRACE:
Procfd = start_tracing(
trussinfo->pid, S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
trussinfo->pid, initial_open,
S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
((trussinfo->flags & NOSIGS) ? 0 : S_SIG),
((trussinfo->flags & FOLLOWFORKS) ? PF_FORK : 0));
initial_open = 0;
if (Procfd == -1)
return (0);

View File

@ -129,7 +129,7 @@ setup_and_wait(char *command[])
*/
int
start_tracing(int pid, int eventflags, int flags)
start_tracing(int pid, int failisfatal, int eventflags, int flags)
{
int fd;
char buf[32];
@ -144,8 +144,8 @@ start_tracing(int pid, int eventflags, int flags)
* happens with SUGID programs. So we need to see if it still
* exists before we complain bitterly.
*/
if (kill(pid, 0) == -1)
return -1;
if (!failisfatal && kill(pid, 0) == -1)
return (-1);
err(8, "cannot open %s", buf);
}