diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-31 23:39:22 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-31 23:39:22 +0200 |
commit | 65c34c52df3ed46f0b811d1858c271a373ab6af5 (patch) | |
tree | 8c9a08f6ff1b442dbb642995d1870cb2efd87a0d /networking/udhcp | |
parent | 91755cb16d496d1094f5d81051a1e1e6f27a21c1 (diff) | |
download | busybox-w32-65c34c52df3ed46f0b811d1858c271a373ab6af5.tar.gz busybox-w32-65c34c52df3ed46f0b811d1858c271a373ab6af5.tar.bz2 busybox-w32-65c34c52df3ed46f0b811d1858c271a373ab6af5.zip |
dhcp: get rid of static data signal_pipe
function old new delta
udhcp_sp_setup 65 110 +45
udhcp_sp_fd_set 60 59 -1
udhcpd_main 1442 1437 -5
udhcpc_main 2684 2679 -5
signal_pipe 8 - -8
packed_usage 33292 33284 -8
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/4 up/down: 45/-27) Total: 18 bytes
text data bss dec hex filename
952746 481 7296 960523 ea80b busybox_old
952768 481 7288 960537 ea819 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp')
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 8 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 8 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 12 | ||||
-rw-r--r-- | networking/udhcp/signalpipe.c | 31 |
4 files changed, 36 insertions, 23 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 15e9f3924..02766ba16 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -1174,6 +1174,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1174 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; | 1174 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; |
1175 | client_data.sockfd = -1; | 1175 | client_data.sockfd = -1; |
1176 | 1176 | ||
1177 | /* Make sure fd 0,1,2 are open */ | ||
1178 | /* Set up the signal pipe on fds 3,4 - must be before openlog() */ | ||
1179 | udhcp_sp_setup(); | ||
1180 | |||
1177 | /* Parse command line */ | 1181 | /* Parse command line */ |
1178 | opt = getopt32long(argv, "^" | 1182 | opt = getopt32long(argv, "^" |
1179 | /* O,x: list; -T,-t,-A take numeric param */ | 1183 | /* O,x: list; -T,-t,-A take numeric param */ |
@@ -1268,14 +1272,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1268 | logmode |= LOGMODE_SYSLOG; | 1272 | logmode |= LOGMODE_SYSLOG; |
1269 | } | 1273 | } |
1270 | 1274 | ||
1271 | /* Make sure fd 0,1,2 are open */ | ||
1272 | bb_sanitize_stdio(); | ||
1273 | /* Create pidfile */ | 1275 | /* Create pidfile */ |
1274 | write_pidfile(client_data.pidfile); | 1276 | write_pidfile(client_data.pidfile); |
1275 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1277 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1276 | bb_info_msg("started, v"BB_VER); | 1278 | bb_info_msg("started, v"BB_VER); |
1277 | /* Set up the signal pipe */ | ||
1278 | udhcp_sp_setup(); | ||
1279 | 1279 | ||
1280 | client_data.state = INIT_SELECTING; | 1280 | client_data.state = INIT_SELECTING; |
1281 | d6_run_script_no_option("deconfig"); | 1281 | d6_run_script_no_option("deconfig"); |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index cb85fa9e3..f040e93f7 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -1271,6 +1271,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1271 | client_data.sockfd = -1; | 1271 | client_data.sockfd = -1; |
1272 | str_V = "udhcp "BB_VER; | 1272 | str_V = "udhcp "BB_VER; |
1273 | 1273 | ||
1274 | /* Make sure fd 0,1,2 are open */ | ||
1275 | /* Set up the signal pipe on fds 3,4 - must be before openlog() */ | ||
1276 | udhcp_sp_setup(); | ||
1277 | |||
1274 | /* Parse command line */ | 1278 | /* Parse command line */ |
1275 | opt = getopt32long(argv, "^" | 1279 | opt = getopt32long(argv, "^" |
1276 | /* O,x: list; -T,-t,-A take numeric param */ | 1280 | /* O,x: list; -T,-t,-A take numeric param */ |
@@ -1385,14 +1389,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1385 | logmode |= LOGMODE_SYSLOG; | 1389 | logmode |= LOGMODE_SYSLOG; |
1386 | } | 1390 | } |
1387 | 1391 | ||
1388 | /* Make sure fd 0,1,2 are open */ | ||
1389 | bb_sanitize_stdio(); | ||
1390 | /* Create pidfile */ | 1392 | /* Create pidfile */ |
1391 | write_pidfile(client_data.pidfile); | 1393 | write_pidfile(client_data.pidfile); |
1392 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1394 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1393 | bb_info_msg("started, v"BB_VER); | 1395 | bb_info_msg("started, v"BB_VER); |
1394 | /* Set up the signal pipe */ | ||
1395 | udhcp_sp_setup(); | ||
1396 | /* We want random_xid to be random... */ | 1396 | /* We want random_xid to be random... */ |
1397 | srand(monotonic_us()); | 1397 | srand(monotonic_us()); |
1398 | 1398 | ||
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 6e426e6a2..022b8721b 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -37,6 +37,8 @@ | |||
37 | //usage: IF_FEATURE_UDHCP_PORT( | 37 | //usage: IF_FEATURE_UDHCP_PORT( |
38 | //usage: "\n -P N Use port N (default 67)" | 38 | //usage: "\n -P N Use port N (default 67)" |
39 | //usage: ) | 39 | //usage: ) |
40 | //usage: "\nSignals:" | ||
41 | //usage: "\n USR1 Update lease file" | ||
40 | 42 | ||
41 | #include <netinet/ether.h> | 43 | #include <netinet/ether.h> |
42 | #include <syslog.h> | 44 | #include <syslog.h> |
@@ -863,6 +865,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
863 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 865 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
864 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 866 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
865 | 867 | ||
868 | /* Make sure fd 0,1,2 are open */ | ||
869 | /* Setup the signal pipe on fds 3,4 - must be before openlog() */ | ||
870 | udhcp_sp_setup(); | ||
871 | |||
866 | opt = getopt32(argv, "^" | 872 | opt = getopt32(argv, "^" |
867 | "fSI:va:"IF_FEATURE_UDHCP_PORT("P:") | 873 | "fSI:va:"IF_FEATURE_UDHCP_PORT("P:") |
868 | "\0" | 874 | "\0" |
@@ -904,9 +910,6 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
904 | if (server_data.auto_time > INT_MAX / 1000) | 910 | if (server_data.auto_time > INT_MAX / 1000) |
905 | server_data.auto_time = INT_MAX / 1000; | 911 | server_data.auto_time = INT_MAX / 1000; |
906 | 912 | ||
907 | /* Make sure fd 0,1,2 are open */ | ||
908 | bb_sanitize_stdio(); | ||
909 | |||
910 | /* Create pidfile */ | 913 | /* Create pidfile */ |
911 | write_pidfile(server_data.pidfile); | 914 | write_pidfile(server_data.pidfile); |
912 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ | 915 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ |
@@ -942,9 +945,6 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
942 | goto ret; | 945 | goto ret; |
943 | } | 946 | } |
944 | 947 | ||
945 | /* Setup the signal pipe */ | ||
946 | udhcp_sp_setup(); | ||
947 | |||
948 | continue_with_autotime: | 948 | continue_with_autotime: |
949 | timeout_end = monotonic_sec() + server_data.auto_time; | 949 | timeout_end = monotonic_sec() + server_data.auto_time; |
950 | while (1) { /* loop until universe collapses */ | 950 | while (1) { /* loop until universe collapses */ |
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 2ff78f0f2..81d1fc01a 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c | |||
@@ -20,14 +20,14 @@ | |||
20 | */ | 20 | */ |
21 | #include "common.h" | 21 | #include "common.h" |
22 | 22 | ||
23 | /* Global variable: we access it from signal handler */ | 23 | #define READ_FD 3 |
24 | static struct fd_pair signal_pipe; | 24 | #define WRITE_FD 4 |
25 | 25 | ||
26 | static void signal_handler(int sig) | 26 | static void signal_handler(int sig) |
27 | { | 27 | { |
28 | int sv = errno; | 28 | int sv = errno; |
29 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ | 29 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ |
30 | if (write(signal_pipe.wr, &ch, 1) != 1) | 30 | if (write(WRITE_FD, &ch, 1) != 1) |
31 | bb_perror_msg("can't send signal"); | 31 | bb_perror_msg("can't send signal"); |
32 | errno = sv; | 32 | errno = sv; |
33 | } | 33 | } |
@@ -36,12 +36,25 @@ static void signal_handler(int sig) | |||
36 | * and installs the signal handler */ | 36 | * and installs the signal handler */ |
37 | void FAST_FUNC udhcp_sp_setup(void) | 37 | void FAST_FUNC udhcp_sp_setup(void) |
38 | { | 38 | { |
39 | struct fd_pair signal_pipe; | ||
40 | |||
41 | /* All callers also want this, so... */ | ||
42 | bb_sanitize_stdio(); | ||
43 | |||
39 | /* was socketpair, but it needs AF_UNIX in kernel */ | 44 | /* was socketpair, but it needs AF_UNIX in kernel */ |
40 | xpiped_pair(signal_pipe); | 45 | xpiped_pair(signal_pipe); |
41 | close_on_exec_on(signal_pipe.rd); | 46 | |
42 | close_on_exec_on(signal_pipe.wr); | 47 | /* usually we get fds 3 and 4, but if we get higher ones... */ |
43 | ndelay_on(signal_pipe.rd); | 48 | if (signal_pipe.rd != READ_FD) |
44 | ndelay_on(signal_pipe.wr); | 49 | xmove_fd(signal_pipe.rd, READ_FD); |
50 | if (signal_pipe.wr != WRITE_FD) | ||
51 | xmove_fd(signal_pipe.wr, WRITE_FD); | ||
52 | |||
53 | close_on_exec_on(READ_FD); | ||
54 | close_on_exec_on(WRITE_FD); | ||
55 | ndelay_on(READ_FD); | ||
56 | ndelay_on(WRITE_FD); | ||
57 | |||
45 | bb_signals(0 | 58 | bb_signals(0 |
46 | + (1 << SIGUSR1) | 59 | + (1 << SIGUSR1) |
47 | + (1 << SIGUSR2) | 60 | + (1 << SIGUSR2) |
@@ -54,7 +67,7 @@ void FAST_FUNC udhcp_sp_setup(void) | |||
54 | */ | 67 | */ |
55 | void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd) | 68 | void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd) |
56 | { | 69 | { |
57 | pfds[0].fd = signal_pipe.rd; | 70 | pfds[0].fd = READ_FD; |
58 | pfds[0].events = POLLIN; | 71 | pfds[0].events = POLLIN; |
59 | pfds[1].fd = -1; | 72 | pfds[1].fd = -1; |
60 | if (extra_fd >= 0) { | 73 | if (extra_fd >= 0) { |
@@ -74,7 +87,7 @@ int FAST_FUNC udhcp_sp_read(void) | |||
74 | unsigned char sig; | 87 | unsigned char sig; |
75 | 88 | ||
76 | /* Can't block here, fd is in nonblocking mode */ | 89 | /* Can't block here, fd is in nonblocking mode */ |
77 | if (safe_read(signal_pipe.rd, &sig, 1) != 1) | 90 | if (safe_read(READ_FD, &sig, 1) != 1) |
78 | return 0; | 91 | return 0; |
79 | 92 | ||
80 | return sig; | 93 | return sig; |