Formatting
This commit is contained in:
parent
aac2a19e50
commit
82d42dbb57
@ -830,24 +830,27 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int n, ctrl;
|
|
||||||
fd_set readable;
|
fd_set readable;
|
||||||
|
int ctrl;
|
||||||
|
int n;
|
||||||
|
|
||||||
if (nsock == 0) {
|
if (nsock == 0) {
|
||||||
sigprocmask(SIG_BLOCK, &blockmask, NULL);
|
sigprocmask(SIG_BLOCK, &blockmask, NULL);
|
||||||
while (nsock == 0)
|
while (nsock == 0) {
|
||||||
sigsuspend(&emptymask);
|
sigsuspend(&emptymask);
|
||||||
|
}
|
||||||
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
||||||
}
|
}
|
||||||
readable = allsock;
|
readable = allsock;
|
||||||
if ((n = select(maxsock + 1, &readable, (fd_set *)0,
|
n = select(maxsock + 1, &readable, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
|
||||||
(fd_set *)0, (struct timeval *)0)) <= 0) {
|
if (n <= 0) {
|
||||||
if (n < 0 && errno != EINTR)
|
if (n < 0 && errno != EINTR) {
|
||||||
syslog(LOG_WARNING, "select: %m");
|
syslog(LOG_WARNING, "select: %m");
|
||||||
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (sep = servtab; n && sep; sep = sep->se_next)
|
for (sep = servtab; n && sep; sep = sep->se_next) {
|
||||||
if (sep->se_fd != -1 && FD_ISSET(sep->se_fd, &readable)) {
|
if (sep->se_fd != -1 && FD_ISSET(sep->se_fd, &readable)) {
|
||||||
n--;
|
n--;
|
||||||
if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
|
if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
|
||||||
@ -857,28 +860,30 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
ctrl = accept(sep->se_fd, NULL, NULL);
|
ctrl = accept(sep->se_fd, NULL, NULL);
|
||||||
fcntl(sep->se_fd, F_SETFL, 0);
|
fcntl(sep->se_fd, F_SETFL, 0);
|
||||||
if (ctrl < 0) {
|
if (ctrl < 0) {
|
||||||
if (errno == EINTR || errno == EWOULDBLOCK)
|
if (errno == EINTR || errno == EWOULDBLOCK) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
syslog(LOG_WARNING, "accept (for %s): %m",
|
syslog(LOG_WARNING, "accept (for %s): %m",
|
||||||
sep->se_service);
|
sep->se_service);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
ctrl = sep->se_fd;
|
ctrl = sep->se_fd;
|
||||||
|
}
|
||||||
sigprocmask(SIG_BLOCK, &blockmask, NULL);
|
sigprocmask(SIG_BLOCK, &blockmask, NULL);
|
||||||
pid = 0;
|
pid = 0;
|
||||||
#ifdef INETD_FEATURE_ENABLED
|
#ifdef INETD_FEATURE_ENABLED
|
||||||
if (sep->se_bi == 0 || sep->se_bi->bi_fork)
|
if (sep->se_bi == 0 || sep->se_bi->bi_fork)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (sep->se_count++ == 0)
|
if (sep->se_count++ == 0) {
|
||||||
(void)gettimeofday(&sep->se_time, (struct timezone *)0);
|
gettimeofday(&sep->se_time, (struct timezone *)0);
|
||||||
|
}
|
||||||
else if (sep->se_count >= sep->se_max) {
|
else if (sep->se_count >= sep->se_max) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
(void)gettimeofday(&now, (struct timezone *)0);
|
gettimeofday(&now, (struct timezone *)0);
|
||||||
if (now.tv_sec - sep->se_time.tv_sec >
|
if (now.tv_sec - sep->se_time.tv_sec > CNT_INTVL) {
|
||||||
CNT_INTVL) {
|
|
||||||
sep->se_time = now;
|
sep->se_time = now;
|
||||||
sep->se_count = 1;
|
sep->se_count = 1;
|
||||||
} else {
|
} else {
|
||||||
@ -886,12 +891,11 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
"%s/%s server failing (looping), service terminated",
|
"%s/%s server failing (looping), service terminated",
|
||||||
sep->se_service, sep->se_proto);
|
sep->se_service, sep->se_proto);
|
||||||
FD_CLR(sep->se_fd, &allsock);
|
FD_CLR(sep->se_fd, &allsock);
|
||||||
(void) close(sep->se_fd);
|
close(sep->se_fd);
|
||||||
sep->se_fd = -1;
|
sep->se_fd = -1;
|
||||||
sep->se_count = 0;
|
sep->se_count = 0;
|
||||||
nsock--;
|
nsock--;
|
||||||
sigprocmask(SIG_SETMASK, &emptymask,
|
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
||||||
NULL);
|
|
||||||
if (!timingout) {
|
if (!timingout) {
|
||||||
timingout = 1;
|
timingout = 1;
|
||||||
alarm(RETRYTIME);
|
alarm(RETRYTIME);
|
||||||
@ -902,8 +906,9 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
syslog(LOG_ERR, "fork: %m");
|
syslog(LOG_ERR, "fork: %m");
|
||||||
if (sep->se_socktype == SOCK_STREAM)
|
if (sep->se_socktype == SOCK_STREAM) {
|
||||||
close(ctrl);
|
close(ctrl);
|
||||||
|
}
|
||||||
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
@ -917,9 +922,9 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
sigprocmask(SIG_SETMASK, &emptymask, NULL);
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
#ifdef INETD_FEATURE_ENABLED
|
#ifdef INETD_FEATURE_ENABLED
|
||||||
if (sep->se_bi)
|
if (sep->se_bi) {
|
||||||
(*sep->se_bi->bi_fn)(ctrl, sep);
|
(*sep->se_bi->bi_fn)(ctrl, sep);
|
||||||
else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
struct passwd *pwd = getpwnam(sep->se_user);
|
struct passwd *pwd = getpwnam(sep->se_user);
|
||||||
@ -929,12 +934,9 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
"getpwnam: %s: No such user",
|
"getpwnam: %s: No such user",
|
||||||
sep->se_user);
|
sep->se_user);
|
||||||
}
|
}
|
||||||
if (sep->se_group &&
|
if (sep->se_group && (grp = getgrnam(sep->se_group)) == NULL) {
|
||||||
(grp = getgrnam(sep->se_group)) == NULL) {
|
syslog_err_and_discard_dg(sep->se_socktype,
|
||||||
syslog_err_and_discard_dg(
|
"getgrnam: %s: No such group", sep->se_group);
|
||||||
sep->se_socktype,
|
|
||||||
"getgrnam: %s: No such group",
|
|
||||||
sep->se_group);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Ok. There are four cases here:
|
* Ok. There are four cases here:
|
||||||
@ -949,8 +951,9 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
* given group. In case 3 we do nothing.
|
* given group. In case 3 we do nothing.
|
||||||
*/
|
*/
|
||||||
if (pwd->pw_uid) {
|
if (pwd->pw_uid) {
|
||||||
if (sep->se_group)
|
if (sep->se_group) {
|
||||||
pwd->pw_gid = grp->gr_gid;
|
pwd->pw_gid = grp->gr_gid;
|
||||||
|
}
|
||||||
setgid((gid_t)pwd->pw_gid);
|
setgid((gid_t)pwd->pw_gid);
|
||||||
initgroups(pwd->pw_name, pwd->pw_gid);
|
initgroups(pwd->pw_name, pwd->pw_gid);
|
||||||
setuid((uid_t)pwd->pw_uid);
|
setuid((uid_t)pwd->pw_uid);
|
||||||
@ -964,28 +967,29 @@ extern int inetd_main(int argc, char *argv[])
|
|||||||
dup2(0, 2);
|
dup2(0, 2);
|
||||||
#ifdef RLIMIT_NOFILE
|
#ifdef RLIMIT_NOFILE
|
||||||
if (rlim_ofile.rlim_cur != rlim_ofile_cur) {
|
if (rlim_ofile.rlim_cur != rlim_ofile_cur) {
|
||||||
if (setrlimit(RLIMIT_NOFILE,
|
if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0) {
|
||||||
&rlim_ofile) < 0)
|
|
||||||
syslog(LOG_ERR,"setrlimit: %m");
|
syslog(LOG_ERR,"setrlimit: %m");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
for (ctrl = rlim_ofile_cur-1; --ctrl > 2; )
|
for (ctrl = rlim_ofile_cur-1; --ctrl > 2; ) {
|
||||||
(void)close(ctrl);
|
(void)close(ctrl);
|
||||||
|
}
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = SIG_DFL;
|
sa.sa_handler = SIG_DFL;
|
||||||
sigaction(SIGPIPE, &sa, NULL);
|
sigaction(SIGPIPE, &sa, NULL);
|
||||||
|
|
||||||
execv(sep->se_server, sep->se_argv);
|
execv(sep->se_server, sep->se_argv);
|
||||||
syslog_err_and_discard_dg(sep->se_socktype,
|
syslog_err_and_discard_dg(sep->se_socktype, "execv %s: %m", sep->se_server);
|
||||||
"execv %s: %m", sep->se_server);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
|
if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) {
|
||||||
close(ctrl);
|
close(ctrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user