diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-05 11:36:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-05 11:36:22 +0000 |
commit | 4cb576ea98aa8974243e168e2470e3d5d7b7d1f5 (patch) | |
tree | 53aff742d140ed57185c0e0ee374248cc70864e2 | |
parent | a643816fe360c7551ac19c04e10111be620e9dad (diff) | |
download | busybox-w32-4cb576ea98aa8974243e168e2470e3d5d7b7d1f5.tar.gz busybox-w32-4cb576ea98aa8974243e168e2470e3d5d7b7d1f5.tar.bz2 busybox-w32-4cb576ea98aa8974243e168e2470e3d5d7b7d1f5.zip |
inetd: fix a case when we have zero services
-rw-r--r-- | networking/inetd.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/networking/inetd.c b/networking/inetd.c index f80b51052..bf018d774 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -223,7 +223,7 @@ typedef struct servtab_t { | |||
223 | smallint se_checked; /* looked at during merge */ | 223 | smallint se_checked; /* looked at during merge */ |
224 | unsigned se_max; /* allowed instances per minute */ | 224 | unsigned se_max; /* allowed instances per minute */ |
225 | unsigned se_count; /* number started since se_time */ | 225 | unsigned se_count; /* number started since se_time */ |
226 | unsigned se_time; /* whem we started counting */ | 226 | unsigned se_time; /* when we started counting */ |
227 | char *se_user; /* user name to run as */ | 227 | char *se_user; /* user name to run as */ |
228 | char *se_group; /* group name to run as, can be NULL */ | 228 | char *se_group; /* group name to run as, can be NULL */ |
229 | #ifdef INETD_BUILTINS_ENABLED | 229 | #ifdef INETD_BUILTINS_ENABLED |
@@ -295,8 +295,10 @@ struct globals { | |||
295 | struct rlimit rlim_ofile; | 295 | struct rlimit rlim_ofile; |
296 | servtab_t *serv_list; | 296 | servtab_t *serv_list; |
297 | int global_queuelen; | 297 | int global_queuelen; |
298 | int maxsock; /* max fd# in allsock, -1: unknown */ | ||
299 | /* whenever maxsock grows, prev_maxsock is set to new maxsock, | ||
300 | * but if maxsock is set to -1, prev_maxsock is not changed */ | ||
298 | int prev_maxsock; | 301 | int prev_maxsock; |
299 | int maxsock; | ||
300 | unsigned max_concurrency; | 302 | unsigned max_concurrency; |
301 | smallint alarm_armed; | 303 | smallint alarm_armed; |
302 | uid_t real_uid; /* user ID who ran us */ | 304 | uid_t real_uid; /* user ID who ran us */ |
@@ -321,8 +323,8 @@ struct BUG_G_too_big { | |||
321 | #define rlim_ofile (G.rlim_ofile ) | 323 | #define rlim_ofile (G.rlim_ofile ) |
322 | #define serv_list (G.serv_list ) | 324 | #define serv_list (G.serv_list ) |
323 | #define global_queuelen (G.global_queuelen) | 325 | #define global_queuelen (G.global_queuelen) |
324 | #define prev_maxsock (G.prev_maxsock ) | ||
325 | #define maxsock (G.maxsock ) | 326 | #define maxsock (G.maxsock ) |
327 | #define prev_maxsock (G.prev_maxsock ) | ||
326 | #define max_concurrency (G.max_concurrency) | 328 | #define max_concurrency (G.max_concurrency) |
327 | #define alarm_armed (G.alarm_armed ) | 329 | #define alarm_armed (G.alarm_armed ) |
328 | #define real_uid (G.real_uid ) | 330 | #define real_uid (G.real_uid ) |
@@ -459,7 +461,7 @@ static void add_fd_to_set(int fd) | |||
459 | FD_SET(fd, &allsock); | 461 | FD_SET(fd, &allsock); |
460 | if (maxsock >= 0 && fd > maxsock) { | 462 | if (maxsock >= 0 && fd > maxsock) { |
461 | prev_maxsock = maxsock = fd; | 463 | prev_maxsock = maxsock = fd; |
462 | if ((rlim_t)maxsock > rlim_ofile_cur - FD_MARGIN) | 464 | if ((rlim_t)fd > rlim_ofile_cur - FD_MARGIN) |
463 | bump_nofile(); | 465 | bump_nofile(); |
464 | } | 466 | } |
465 | } | 467 | } |
@@ -468,6 +470,10 @@ static void add_fd_to_set(int fd) | |||
468 | static void recalculate_maxsock(void) | 470 | static void recalculate_maxsock(void) |
469 | { | 471 | { |
470 | int fd = 0; | 472 | int fd = 0; |
473 | |||
474 | /* We may have no services, in this case maxsock should still be >= 0 | ||
475 | * (code elsewhere is not happy with maxsock == -1) */ | ||
476 | maxsock = 0; | ||
471 | while (fd <= prev_maxsock) { | 477 | while (fd <= prev_maxsock) { |
472 | if (FD_ISSET(fd, &allsock)) | 478 | if (FD_ISSET(fd, &allsock)) |
473 | maxsock = fd; | 479 | maxsock = fd; |
@@ -1161,7 +1167,8 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1161 | 1167 | ||
1162 | readable = allsock; /* struct copy */ | 1168 | readable = allsock; /* struct copy */ |
1163 | /* if there are no fds to wait on, we will block | 1169 | /* if there are no fds to wait on, we will block |
1164 | * until signal wakes us up */ | 1170 | * until signal wakes us up (maxsock == 0, but readable |
1171 | * never contains fds 0 and 1...) */ | ||
1165 | ready_fd_cnt = select(maxsock + 1, &readable, NULL, NULL, NULL); | 1172 | ready_fd_cnt = select(maxsock + 1, &readable, NULL, NULL, NULL); |
1166 | if (ready_fd_cnt < 0) { | 1173 | if (ready_fd_cnt < 0) { |
1167 | if (errno != EINTR) { | 1174 | if (errno != EINTR) { |
@@ -1418,7 +1425,7 @@ static void echo_dg(int s, servtab_t *sep) | |||
1418 | 1425 | ||
1419 | 1426 | ||
1420 | #if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD | 1427 | #if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD |
1421 | /* Discard service -- ignore data. MMU arches only. */ | 1428 | /* Discard service -- ignore data. */ |
1422 | /* ARGSUSED */ | 1429 | /* ARGSUSED */ |
1423 | static void discard_stream(int s, servtab_t *sep UNUSED_PARAM) | 1430 | static void discard_stream(int s, servtab_t *sep UNUSED_PARAM) |
1424 | { | 1431 | { |