Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sup/source - safer way to count kids
details: https://anonhg.NetBSD.org/src/rev/f624441208a3
branches: trunk
changeset: 763301:f624441208a3
user: christos <christos%NetBSD.org@localhost>
date: Wed Mar 16 20:17:00 2011 +0000
description:
- safer way to count kids
- if we are really bombarded with connections, don't bother to fork() and
converse.
diffstat:
usr.sbin/sup/source/supfilesrv.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diffs (51 lines):
diff -r 95550fd8b449 -r f624441208a3 usr.sbin/sup/source/supfilesrv.c
--- a/usr.sbin/sup/source/supfilesrv.c Wed Mar 16 20:15:59 2011 +0000
+++ b/usr.sbin/sup/source/supfilesrv.c Wed Mar 16 20:17:00 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: supfilesrv.c,v 1.44 2010/10/20 17:05:54 christos Exp $ */
+/* $NetBSD: supfilesrv.c,v 1.45 2011/03/16 20:17:00 christos Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -443,6 +443,14 @@
(void) servicekill();
continue;
}
+ /*
+ * If we are being bombarded, don't even spend time forking
+ * or conversing
+ */
+ if (nchildren >= maxchildren + 5) {
+ (void) servicekill();
+ continue;
+ }
sigemptyset(&nset);
sigaddset(&nset, SIGCHLD);
sigprocmask(SIG_BLOCK, &nset, &oset);
@@ -481,10 +489,23 @@
chldsig(int snum __unused)
{
int w;
+ pid_t pid;
- while (wait3((int *) &w, WNOHANG, (struct rusage *) 0) > 0) {
- if (nchildren)
- nchildren--;
+ while ((pid = waitpid(-1, &w, WNOHANG)) > 0) {
+ if (kill(pid, 0) == -1)
+ switch (errno) {
+ case ESRCH:
+ if (nchildren == 0)
+ logerr("no children but pid %jd\n",
+ (intmax_t)pid);
+ nchildren--;
+ break;
+ default:
+ logerr("killing pid %jd: (%s)\n", (intmax_t)
+ pid, strerror(errno));
+ break;
+ }
+
}
}
/*****************************************
Home |
Main Index |
Thread Index |
Old Index