[PATCH] 2.4.18-rc2 Fix for get_pid hang

Paul Larson (plars@austin.ibm.com)
22 Feb 2002 16:29:48 -0600


--=-nn1HZrXHkqME9rsPx2CH
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Marcelo,

This was made against 2.4.18-rc2 but applies cleanly against
2.4.18-rc4. This is a fix for a problem where if we run out of
available pids, get_pid will hang the system while it searches through
the tasks for an available pid forever.

Thanks,
Paul Larson

--=-nn1HZrXHkqME9rsPx2CH
Content-Disposition: attachment; filename=getpid.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; charset=ISO-8859-1

diff -Naur linux-2.4.18-rc2/kernel/fork.c linux-getpid/kernel/fork.c
--- linux-2.4.18-rc2/kernel/fork.c Wed Feb 20 09:54:39 2002
+++ linux-getpid/kernel/fork.c Fri Feb 22 15:52:52 2002
@@ -20,6 +20,7 @@
#include <linux/vmalloc.h>
#include <linux/completion.h>
#include <linux/personality.h>
+#include <linux/compiler.h>
=20
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -85,12 +86,13 @@
{
static int next_safe =3D PID_MAX;
struct task_struct *p;
- int pid;
+ int pid, beginpid;
=20
if (flags & CLONE_PID)
return current->pid;
=20
spin_lock(&lastpid_lock);
+ beginpid =3D last_pid;
if((++last_pid) & 0xffff8000) {
last_pid =3D 300; /* Skip daemons etc. */
goto inside;
@@ -110,12 +112,16 @@
last_pid =3D 300;
next_safe =3D PID_MAX;
}
+ if(unlikely(last_pid =3D=3D beginpid))
+ goto nomorepids;
goto repeat;
}
if(p->pid > last_pid && next_safe > p->pid)
next_safe =3D p->pid;
if(p->pgrp > last_pid && next_safe > p->pgrp)
next_safe =3D p->pgrp;
+ if(p->tgid > last_pid && next_safe > p->tgid)
+ next_safe =3D p->tgid;
if(p->session > last_pid && next_safe > p->session)
next_safe =3D p->session;
}
@@ -125,6 +131,11 @@
spin_unlock(&lastpid_lock);
=20
return pid;
+
+nomorepids:
+ read_unlock(&tasklist_lock);
+ spin_unlock(&lastpid_lock);
+ return 0;
}
=20
static inline int dup_mmap(struct mm_struct * mm)
@@ -620,6 +631,8 @@
=20
copy_flags(clone_flags, p);
p->pid =3D get_pid(clone_flags);
+ if (p->pid =3D=3D 0 && current->pid !=3D 0)
+ goto bad_fork_cleanup;
=20
p->run_list.next =3D NULL;
p->run_list.prev =3D NULL;

--=-nn1HZrXHkqME9rsPx2CH--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/