Get rid of TCB_INUSE and TCB_STRACE_CHILD
We can use tcb::pid == 0 as an indicator of free tcb,
and we already have strace_child variable which holds
pid of our child, if any.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
diff --git a/defs.h b/defs.h
index fbbe48c..1f1602a 100644
--- a/defs.h
+++ b/defs.h
@@ -393,7 +393,7 @@
/* Trace Control Block */
struct tcb {
int flags; /* See below for TCB_ values */
- int pid; /* Process Id of this entry */
+ int pid; /* If 0, this tcb is free */
int qual_flg; /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
int u_error; /* Error code */
long scno; /* System call number */
@@ -418,10 +418,9 @@
};
/* TCB flags */
-#define TCB_INUSE 00001 /* This table entry is in use */
/* We have attached to this process, but did not see it stopping yet */
-#define TCB_STARTUP 00002
-#define TCB_IGNORE_ONE_SIGSTOP 00004 /* Next SIGSTOP is to be ignored */
+#define TCB_STARTUP 0x01
+#define TCB_IGNORE_ONE_SIGSTOP 0x02 /* Next SIGSTOP is to be ignored */
/*
* Are we in system call entry or in syscall exit?
*
@@ -440,14 +439,13 @@
*
* Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
*/
-#define TCB_INSYSCALL 00010
-#define TCB_ATTACHED 00020 /* It is attached already */
-/* Are we PROG from "strace PROG [ARGS]" invocation? */
-#define TCB_STRACE_CHILD 0040
-#define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
-#define TCB_REPRINT 00200 /* We should reprint this syscall on exit */
-#define TCB_FILTERED 00400 /* This system call has been filtered out */
-/* x86 does not need TCB_WAITEXECVE.
+#define TCB_INSYSCALL 0x04
+#define TCB_ATTACHED 0x08 /* We attached to it already */
+#define TCB_BPTSET 0x10 /* "Breakpoint" set after fork(2) */
+#define TCB_REPRINT 0x20 /* We should reprint this syscall on exit */
+#define TCB_FILTERED 0x40 /* This system call has been filtered out */
+/*
+ * x86 does not need TCB_WAITEXECVE.
* It can detect post-execve SIGTRAP by looking at eax/rax.
* See "not a syscall entry (eax = %ld)\n" message.
*
@@ -468,7 +466,7 @@
/* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
* to happen. (When it is detected, tracee is continued and this bit is cleared.)
*/
-# define TCB_WAITEXECVE 01000
+# define TCB_WAITEXECVE 0x80
#endif
/* qualifier flags */
diff --git a/strace.c b/strace.c
index 3fd35d9..1415aab 100644
--- a/strace.c
+++ b/strace.c
@@ -678,10 +678,9 @@
for (i = 0; i < tcbtabsize; i++) {
tcp = tcbtab[i];
- if ((tcp->flags & TCB_INUSE) == 0) {
+ if (!tcp->pid) {
memset(tcp, 0, sizeof(*tcp));
tcp->pid = pid;
- tcp->flags = TCB_INUSE;
#if SUPPORTED_PERSONALITIES > 1
tcp->currpers = current_personality;
#endif
@@ -959,7 +958,7 @@
for (tcbi = 0; tcbi < tcbtabsize; tcbi++) {
tcp = tcbtab[tcbi];
- if (!(tcp->flags & TCB_INUSE))
+ if (!tcp->pid)
continue;
/* Is this a process we should attach to, but not yet attached? */
@@ -1252,9 +1251,9 @@
}
tcp = alloctcb(pid);
if (!NOMMU_SYSTEM)
- tcp->flags |= TCB_ATTACHED | TCB_STRACE_CHILD | TCB_STARTUP | post_attach_sigstop;
+ tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
else
- tcp->flags |= TCB_ATTACHED | TCB_STRACE_CHILD | TCB_STARTUP;
+ tcp->flags |= TCB_ATTACHED | TCB_STARTUP;
newoutf(tcp);
}
else {
@@ -1916,7 +1915,7 @@
for (i = 0; i < tcbtabsize; i++) {
struct tcb *tcp = tcbtab[i];
- if (tcp->pid == pid && (tcp->flags & TCB_INUSE))
+ if (tcp->pid == pid)
return tcp;
}
@@ -1937,12 +1936,12 @@
for (i = 0; i < tcbtabsize; i++) {
tcp = tcbtab[i];
- if (!(tcp->flags & TCB_INUSE))
+ if (!tcp->pid)
continue;
if (debug_flag)
fprintf(stderr,
"cleanup: looking at pid %u\n", tcp->pid);
- if (tcp->flags & TCB_STRACE_CHILD) {
+ if (tcp->pid == strace_child) {
kill(tcp->pid, SIGCONT);
kill(tcp->pid, fatal_sig);
}