* strace.c (pid2tcb): Always match pid. Fail for argument <= 0.
[USE_PROCFS] (first_used_tcb): New function.
[USE_PROCFS] (trace): Use that instead of pid2tcb(0).
#endif /* USE_PROCFS */
struct tcb *
-pid2tcb(pid)
-int pid;
+pid2tcb(int pid)
{
int i;
- struct tcb *tcp;
+
+ if (pid <= 0)
+ return NULL;
for (i = 0; i < tcbtabsize; i++) {
- tcp = tcbtab[i];
- if (pid && tcp->pid != pid)
- continue;
- if (tcp->flags & TCB_INUSE)
+ struct tcb *tcp = tcbtab[i];
+ if (tcp->pid == pid && (tcp->flags & TCB_INUSE))
return tcp;
}
+
return NULL;
}
#ifdef USE_PROCFS
+static struct tcb *
+first_used_tcb(void)
+{
+ int i;
+ struct tcb *tcp;
+ for (i = 0; i < tcbtabsize; i++) {
+ tcp = tcbtab[i];
+ if (tcp->flags & TCB_INUSE)
+ return tcp;
+ }
+ return NULL;
+}
+
static struct tcb *
pfd2tcb(pfd)
int pfd;
#ifndef HAVE_POLLABLE_PROCFS
if (proc_poll_pipe[0] == -1) {
#endif
- tcp = pid2tcb(0);
+ tcp = first_used_tcb();
if (!tcp)
continue;
pfd = tcp->pfd;