2006-03-29 Dmitry V. Levin <ldv@altlinux.org>
Fix race conditions in tcb allocation.
* process.c (fork_tcb): Return error code as documented. Do not
print "tcb table full" error message.
[USE_PROCFS] (internal_fork): Do not print "tcb table full"
error message.
[SYS_clone || SYS_clone2] (internal_clone, internal_fork): Call
fork_tcb() before alloctcb(). Do not print "tcb table full"
error message.
* strace.c (main): Do not print "tcb table full" error message.
(expand_tcbtab): Print error message in case of memory allocation
failure.
(alloctcb): Print error message when tcb table is full.
(trace): Expand tcb table if necessary prior to allocating
entry there. Do not print "tcb table full" error message.
Fixes RH#180293.
diff --git a/process.c b/process.c
index 1e03ff5..a0db041 100644
--- a/process.c
+++ b/process.c
@@ -412,7 +412,7 @@
if (nprocs == tcbtabsize) {
if (expand_tcbtab()) {
tcp->flags &= ~TCB_FOLLOWFORK;
- fprintf(stderr, "sys_fork: tcb table full\n");
+ return 1;
}
}
@@ -474,10 +474,8 @@
return 0;
if (syserror(tcp))
return 0;
- if ((tcpchild = alloctcb(tcp->u_rval)) == NULL) {
- fprintf(stderr, "sys_fork: tcb table full\n");
+ if ((tcpchild = alloctcb(tcp->u_rval)) == NULL)
return 0;
- }
if (proc_open(tcpchild, 2) < 0)
droptcb(tcpchild);
}
@@ -833,10 +831,9 @@
}
else
#endif
- if ((tcpchild = alloctcb(pid)) == NULL) {
+ if (fork_tcb(tcp) || (tcpchild = alloctcb(pid)) == NULL) {
if (bpt)
clearbpt(tcp);
- fprintf(stderr, " [tcb table full]\n");
kill(pid, SIGKILL); /* XXX */
return 0;
}
@@ -970,8 +967,7 @@
return 0;
pid = tcp->u_rval;
- if ((tcpchild = alloctcb(pid)) == NULL) {
- fprintf(stderr, " [tcb table full]\n");
+ if (fork_tcb(tcp) || (tcpchild = alloctcb(pid)) == NULL) {
kill(pid, SIGKILL); /* XXX */
return 0;
}