From fbd2918f5c91723063ed698026217a77a0fe565b Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 7 Apr 2007 01:05:47 +0000 Subject: 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 --- networking/udhcp/script.c | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'networking/udhcp/script.c') diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index dc8ff7a1c..98706a592 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); } -- cgit v1.2.3