diff options
author | Denis Vlasenko | 2007-04-07 01:05:47 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-04-07 01:05:47 +0000 |
commit | fbd2918f5c91723063ed698026217a77a0fe565b (patch) | |
tree | cddfe351592f4a876232cf4c67c23df25bf0563c /networking/udhcp/script.c | |
parent | bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325 (diff) | |
download | busybox-fbd2918f5c91723063ed698026217a77a0fe565b.zip busybox-fbd2918f5c91723063ed698026217a77a0fe565b.tar.gz |
udhcp: MAC_BCAST_ADDR and blank_chaddr are in fact constant, move to rodata.
a few global variables reduced to smallints
function old new delta
add_lease 75 227 +152
static.blank_chaddr - 16 +16
MAC_BCAST_ADDR - 6 +6
sockfd 4 8 +4
udhcp_run_script 1153 1155 +2
state 8 5 -3
listen_mode 4 1 -3
perform_release 152 148 -4
fd 8 4 -4
blank_chaddr 16 - -16
udhcpc_main 2518 2497 -21
.rodata 131864 131832 -32
oldest_expired_lease 61 - -61
clear_lease 127 - -127
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 3/6 up/down: 180/-271) Total: -91 bytes
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r-- | networking/udhcp/script.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index dc8ff7a..98706a5 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c @@ -9,7 +9,6 @@ */ #include "common.h" -#include "dhcpd.h" #include "dhcpc.h" #include "options.h" @@ -77,7 +76,7 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) switch (type) { case OPTION_IP_PAIR: dest += sprintip(dest, "", option); - *(dest++) = '/'; + *dest++ = '/'; option += 4; optlen = 4; case OPTION_IP: /* Works regardless of host byte order. */ @@ -132,34 +131,42 @@ static char **fill_envp(struct dhcpMessage *packet) int num_options = 0; int i, j; char **envp; + char *var; uint8_t *temp; struct in_addr subnet; char over = 0; - if (packet == NULL) - num_options = 0; - else { - for (i = 0; dhcp_options[i].code; i++) + if (packet) { + for (i = 0; dhcp_options[i].code; i++) { if (get_option(packet, dhcp_options[i].code)) { num_options++; if (dhcp_options[i].code == DHCP_SUBNET) num_options++; /* for mton */ } - if (packet->siaddr) num_options++; - if ((temp = get_option(packet, DHCP_OPTION_OVER))) + } + if (packet->siaddr) + num_options++; + temp = get_option(packet, DHCP_OPTION_OVER); + if (temp) over = *temp; - if (!(over & FILE_FIELD) && packet->file[0]) num_options++; - if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++; + if (!(over & FILE_FIELD) && packet->file[0]) + num_options++; + if (!(over & SNAME_FIELD) && packet->sname[0]) + num_options++; } envp = xzalloc(sizeof(char *) * (num_options + 5)); j = 0; envp[j++] = xasprintf("interface=%s", client_config.interface); - envp[j++] = xasprintf("PATH=%s", - getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin"); - envp[j++] = xasprintf("HOME=%s", getenv("HOME") ? : "/"); + var = getenv("PATH"); + if (var) + envp[j++] = xasprintf("PATH=%s", var); + var = getenv("HOME"); + if (var) + envp[j++] = xasprintf("HOME=%s", var); - if (packet == NULL) return envp; + if (packet == NULL) + return envp; envp[j] = xmalloc(sizeof("ip=255.255.255.255")); sprintip(envp[j++], "ip=", (uint8_t *) &packet->yiaddr); @@ -206,19 +213,20 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name) DEBUG("vfork'ing and execle'ing %s", client_config.script); envp = fill_envp(packet); + /* call script */ +// can we use wait4pid(spawn(...)) here? pid = vfork(); - if (pid) { - waitpid(pid, NULL, 0); - for (curr = envp; *curr; curr++) free(*curr); - free(envp); - return; - } else if (pid == 0) { + if (pid < 0) return; + if (pid == 0) { /* close fd's? */ /* exec script */ execle(client_config.script, client_config.script, name, NULL, envp); - bb_perror_msg("script %s failed", client_config.script); - exit(1); + bb_perror_msg_and_die("script %s failed", client_config.script); } + waitpid(pid, NULL, 0); + for (curr = envp; *curr; curr++) + free(*curr); + free(envp); } |