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.
This commit is contained in:
Kyle Evans 2020-01-01 03:59:54 +00:00
parent 767991d2be
commit d6272fce7c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356246
2 changed files with 9 additions and 5 deletions

View File

@ -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 {

View File

@ -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);