svn commit: r356246 - head/usr.sbin/inetd
Kyle Evans
kevans at FreeBSD.org
Wed Jan 1 03:59:55 UTC 2020
Author: kevans
Date: Wed Jan 1 03:59:54 2020
New Revision: 356246
URL: https://svnweb.freebsd.org/changeset/base/356246
Log:
inetd: add some macros for checking child limits, NFC
The main point here is capturing the maxchild > 0 check. A future change to
inetd will start tracking all of the child pids so that it can give proper
and consistent notification of process exit/signalling.
Modified:
head/usr.sbin/inetd/inetd.c
head/usr.sbin/inetd/inetd.h
Modified: head/usr.sbin/inetd/inetd.c
==============================================================================
--- head/usr.sbin/inetd/inetd.c Wed Jan 1 00:35:02 2020 (r356245)
+++ head/usr.sbin/inetd/inetd.c Wed Jan 1 03:59:54 2020 (r356246)
@@ -925,14 +925,14 @@ addchild(struct servtab *sep, pid_t pid)
if (sep->se_maxchild <= 0)
return;
#ifdef SANITY_CHECK
- if (sep->se_numchild >= sep->se_maxchild) {
+ if (SERVTAB_EXCEEDS_LIMIT(sep)) {
syslog(LOG_ERR, "%s: %d >= %d",
__func__, sep->se_numchild, sep->se_maxchild);
exit(EX_SOFTWARE);
}
#endif
sep->se_pids[sep->se_numchild++] = pid;
- if (sep->se_numchild == sep->se_maxchild)
+ if (SERVTAB_AT_LIMIT(sep))
disable(sep);
}
@@ -958,7 +958,7 @@ reapchild(void)
break;
if (k == sep->se_numchild)
continue;
- if (sep->se_numchild == sep->se_maxchild)
+ if (SERVTAB_AT_LIMIT(sep))
enable(sep);
sep->se_pids[k] = sep->se_pids[--sep->se_numchild];
if (WIFSIGNALED(status) || WEXITSTATUS(status))
@@ -1049,8 +1049,7 @@ config(void)
sep->se_bi = new->se_bi;
/* might need to turn on or off service now */
if (sep->se_fd >= 0) {
- if (sep->se_maxchild > 0
- && sep->se_numchild == sep->se_maxchild) {
+ if (SERVTAB_EXCEEDS_LIMIT(sep)) {
if (FD_ISSET(sep->se_fd, &allsock))
disable(sep);
} else {
Modified: head/usr.sbin/inetd/inetd.h
==============================================================================
--- head/usr.sbin/inetd/inetd.h Wed Jan 1 00:35:02 2020 (r356245)
+++ head/usr.sbin/inetd/inetd.h Wed Jan 1 03:59:54 2020 (r356246)
@@ -124,6 +124,11 @@ struct servtab {
#define se_nomapped se_flags.se_nomapped
#define se_reset se_flags.se_reset
+#define SERVTAB_AT_LIMIT(sep) \
+ ((sep)->se_maxchild > 0 && (sep)->se_numchild == (sep)->se_maxchild)
+#define SERVTAB_EXCEEDS_LIMIT(sep) \
+ ((sep)->se_maxchild > 0 && (sep)->se_numchild >= (sep)->se_maxchild)
+
int check_loop(const struct sockaddr *, const struct servtab *sep);
void inetd_setproctitle(const char *, int);
struct servtab *tcpmux(int);
More information about the svn-src-all
mailing list