aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2026-01-21 19:01:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2026-01-21 19:01:42 +0100
commit71c703c26b1c783a6ba97289416e809db0200aba (patch)
treea675ccc9328dde9d637df61cf040113981144080
parent58b46b7d67c4063aafb94bf82f4e2f3d6e0e3878 (diff)
downloadbusybox-w32-71c703c26b1c783a6ba97289416e809db0200aba.tar.gz
busybox-w32-71c703c26b1c783a6ba97289416e809db0200aba.tar.bz2
busybox-w32-71c703c26b1c783a6ba97289416e809db0200aba.zip
httpd: remove one close() from main loop
function old new delta httpd_main 701 710 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index e96916480..94f6933f4 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2651,6 +2651,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2651static void mini_httpd(int server_socket) NORETURN; 2651static void mini_httpd(int server_socket) NORETURN;
2652static void mini_httpd(int server_socket) 2652static void mini_httpd(int server_socket)
2653{ 2653{
2654 xmove_fd(server_socket, 0);
2654 /* NB: it's best to not use xfuncs in this loop before fork(). 2655 /* NB: it's best to not use xfuncs in this loop before fork().
2655 * Otherwise server may die on transient errors (temporary 2656 * Otherwise server may die on transient errors (temporary
2656 * out-of-memory condition, etc), which is Bad(tm). 2657 * out-of-memory condition, etc), which is Bad(tm).
@@ -2662,7 +2663,7 @@ static void mini_httpd(int server_socket)
2662 2663
2663 /* Wait for connections... */ 2664 /* Wait for connections... */
2664 fromAddr.len = LSA_SIZEOF_SA; 2665 fromAddr.len = LSA_SIZEOF_SA;
2665 n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len); 2666 n = accept(0, &fromAddr.u.sa, &fromAddr.len);
2666 if (n < 0) 2667 if (n < 0)
2667 continue; 2668 continue;
2668//TODO: we can reject connects from denied IPs right away; 2669//TODO: we can reject connects from denied IPs right away;
@@ -2681,8 +2682,7 @@ static void mini_httpd(int server_socket)
2681 /* Do not reload config on HUP */ 2682 /* Do not reload config on HUP */
2682//TODO: can make reload handler check the pid and do nothing in children? 2683//TODO: can make reload handler check the pid and do nothing in children?
2683 signal(SIGHUP, SIG_IGN); 2684 signal(SIGHUP, SIG_IGN);
2684//TODO: can move server_socket to fd 0, making the close here unnecessary? 2685 /* close(0); - server socket. The next line does this for free */
2685 close(server_socket);
2686 xmove_fd(n, 0); 2686 xmove_fd(n, 0);
2687 xdup2(0, 1); 2687 xdup2(0, 1);
2688 2688
@@ -2703,6 +2703,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2703 argv_copy[1] = (char*)"-i"; 2703 argv_copy[1] = (char*)"-i";
2704 memcpy(&argv_copy[2], &argv[1], argc * sizeof(argv[0])); 2704 memcpy(&argv_copy[2], &argv[1], argc * sizeof(argv[0]));
2705 2705
2706 xmove_fd(server_socket, 0);
2706 /* NB: it's best to not use xfuncs in this loop before vfork(). 2707 /* NB: it's best to not use xfuncs in this loop before vfork().
2707 * Otherwise server may die on transient errors (temporary 2708 * Otherwise server may die on transient errors (temporary
2708 * out-of-memory condition, etc), which is Bad(tm). 2709 * out-of-memory condition, etc), which is Bad(tm).
@@ -2712,7 +2713,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2712 int n; 2713 int n;
2713 2714
2714 /* Wait for connections... */ 2715 /* Wait for connections... */
2715 n = accept(server_socket, NULL, NULL); 2716 n = accept(0, NULL, NULL);
2716 if (n < 0) 2717 if (n < 0)
2717 continue; 2718 continue;
2718 2719
@@ -2723,7 +2724,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
2723 /* child */ 2724 /* child */
2724 /* Do not reload config on HUP */ 2725 /* Do not reload config on HUP */
2725 signal(SIGHUP, SIG_IGN); 2726 signal(SIGHUP, SIG_IGN);
2726 close(server_socket); 2727 /* close(0); - server socket. The next line does this for free */
2727 xmove_fd(n, 0); 2728 xmove_fd(n, 0);
2728 xdup2(0, 1); 2729 xdup2(0, 1);
2729 2730