mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] 2.4.19-pre8 get_pid() hang fix again
@ 2002-05-22 21:46 Paul Larson
  2002-05-23 21:14 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Larson @ 2002-05-22 21:46 UTC (permalink / raw)
  To: Marcelo Tosati; +Cc: lkml

Marcelo, I originally submitted this patch against 2.4.18-rc2 and I
noticed that it has not been picked up yet.  I've repatched it against
2.4.19-pre8 and retested it.  This is to fix the problem where if you
run out of available pids, get_pid will cause a hang as it loops forever
through the tasks to try to find an available pid that doesn't exist.

Thanks,
Paul Larson

--- linux-2.4.19-pre8/kernel/fork.c	Mon May 20 10:55:14 2002
+++ linux-getpid/kernel/fork.c	Wed May 22 16:07:29 2002
@@ -21,6 +21,7 @@
 #include <linux/completion.h>
 #include <linux/namespace.h>
 #include <linux/personality.h>
+#include <linux/compiler.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -86,12 +87,13 @@
 {
 	static int next_safe = PID_MAX;
 	struct task_struct *p;
-	int pid;
+	int pid, beginpid;
 
 	if (flags & CLONE_PID)
 		return current->pid;
 
 	spin_lock(&lastpid_lock);
+	beginpid = last_pid;
 	if((++last_pid) & 0xffff8000) {
 		last_pid = 300;		/* Skip daemons etc. */
 		goto inside;
@@ -111,12 +113,16 @@
 						last_pid = 300;
 					next_safe = PID_MAX;
 				}
+				if(unlikely(last_pid == beginpid))
+					goto nomorepids;
 				goto repeat;
 			}
 			if(p->pid > last_pid && next_safe > p->pid)
 				next_safe = p->pid;
 			if(p->pgrp > last_pid && next_safe > p->pgrp)
 				next_safe = p->pgrp;
+			if(p->tgid > last_pid && next_safe > p->tgid)
+				next_safe = p->tgid;
 			if(p->session > last_pid && next_safe > p->session)
 				next_safe = p->session;
 		}
@@ -126,6 +132,11 @@
 	spin_unlock(&lastpid_lock);
 
 	return pid;
+
+nomorepids:
+	read_unlock(&tasklist_lock);
+	spin_unlock(&lastpid_lock);
+	return 0;
 }
 
 static inline int dup_mmap(struct mm_struct * mm)
@@ -624,6 +635,8 @@
 
 	copy_flags(clone_flags, p);
 	p->pid = get_pid(clone_flags);
+	if (p->pid == 0 && current->pid != 0)
+		goto bad_fork_cleanup;
 
 	p->run_list.next = NULL;
 	p->run_list.prev = NULL;




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] 2.4.19-pre8 get_pid() hang fix again
  2002-05-22 21:46 [PATCH] 2.4.19-pre8 get_pid() hang fix again Paul Larson
@ 2002-05-23 21:14 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2002-05-23 21:14 UTC (permalink / raw)
  To: Paul Larson; +Cc: lkml


Applied... thanks.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-23 22:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-22 21:46 [PATCH] 2.4.19-pre8 get_pid() hang fix again Paul Larson
2002-05-23 21:14 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®