diff options
Diffstat (limited to 'networking/inetd.c')
-rw-r--r-- | networking/inetd.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/networking/inetd.c b/networking/inetd.c index 0ddfa6b45..b931aa1e0 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1331,10 +1331,10 @@ int inetd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
1331 | continue; /* -> check next fd in fd set */ | 1331 | continue; /* -> check next fd in fd set */ |
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | /* we are either child or didn't fork at all */ | 1334 | /* we are either child or didn't vfork at all */ |
1335 | #ifdef INETD_BUILTINS_ENABLED | 1335 | #ifdef INETD_BUILTINS_ENABLED |
1336 | if (sep->se_builtin) { | 1336 | if (sep->se_builtin) { |
1337 | if (pid) { /* "pid" is -1: we did fork */ | 1337 | if (pid) { /* "pid" is -1: we did vfork */ |
1338 | close(sep->se_fd); /* listening socket */ | 1338 | close(sep->se_fd); /* listening socket */ |
1339 | logmode = 0; /* make xwrite etc silent */ | 1339 | logmode = 0; /* make xwrite etc silent */ |
1340 | } | 1340 | } |
@@ -1343,8 +1343,8 @@ int inetd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
1343 | sep->se_builtin->bi_stream_fn(ctrl, sep); | 1343 | sep->se_builtin->bi_stream_fn(ctrl, sep); |
1344 | else | 1344 | else |
1345 | sep->se_builtin->bi_dgram_fn(ctrl, sep); | 1345 | sep->se_builtin->bi_dgram_fn(ctrl, sep); |
1346 | if (pid) /* we did fork */ | 1346 | if (pid) /* we did vfork */ |
1347 | _exit(0); | 1347 | _exit(1); |
1348 | maybe_close(accepted_fd); | 1348 | maybe_close(accepted_fd); |
1349 | continue; /* -> check next fd in fd set */ | 1349 | continue; /* -> check next fd in fd set */ |
1350 | } | 1350 | } |
@@ -1430,11 +1430,15 @@ static void echo_stream(int s, servtab_t *sep ATTRIBUTE_UNUSED) | |||
1430 | xwrite(s, line, sz); | 1430 | xwrite(s, line, sz); |
1431 | } | 1431 | } |
1432 | #else | 1432 | #else |
1433 | /* We are after vfork here! */ | ||
1433 | static const char *const args[] = { "cat", NULL }; | 1434 | static const char *const args[] = { "cat", NULL }; |
1434 | /* no error messages */ | 1435 | /* move network socket to stdin */ |
1436 | xmove_fd(s, STDIN_FILENO); | ||
1437 | xdup2(STDIN_FILENO, STDOUT_FILENO); | ||
1438 | /* no error messages please... */ | ||
1435 | xmove_fd(xopen("/dev/null", O_WRONLY), STDERR_FILENO); | 1439 | xmove_fd(xopen("/dev/null", O_WRONLY), STDERR_FILENO); |
1436 | BB_EXECVP("cat", (char**)args); | 1440 | BB_EXECVP("cat", (char**)args); |
1437 | _exit(1); | 1441 | /* on failure we return to main, which does exit(1) */ |
1438 | #endif | 1442 | #endif |
1439 | } | 1443 | } |
1440 | static void echo_dg(int s, servtab_t *sep) | 1444 | static void echo_dg(int s, servtab_t *sep) |
@@ -1463,11 +1467,15 @@ static void discard_stream(int s, servtab_t *sep ATTRIBUTE_UNUSED) | |||
1463 | while (safe_read(s, line, LINE_SIZE) > 0) | 1467 | while (safe_read(s, line, LINE_SIZE) > 0) |
1464 | continue; | 1468 | continue; |
1465 | #else | 1469 | #else |
1470 | /* We are after vfork here! */ | ||
1466 | static const char *const args[] = { "dd", "of=/dev/null", NULL }; | 1471 | static const char *const args[] = { "dd", "of=/dev/null", NULL }; |
1472 | /* move network socket to stdin */ | ||
1473 | xmove_fd(s, STDIN_FILENO); | ||
1474 | xdup2(STDIN_FILENO, STDOUT_FILENO); | ||
1467 | /* no error messages */ | 1475 | /* no error messages */ |
1468 | xmove_fd(xopen("/dev/null", O_WRONLY), STDERR_FILENO); | 1476 | xmove_fd(xopen("/dev/null", O_WRONLY), STDERR_FILENO); |
1469 | BB_EXECVP("dd", (char**)args); | 1477 | BB_EXECVP("dd", (char**)args); |
1470 | _exit(1); | 1478 | /* on failure we return to main, which does exit(1) */ |
1471 | #endif | 1479 | #endif |
1472 | } | 1480 | } |
1473 | /* ARGSUSED */ | 1481 | /* ARGSUSED */ |