"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 2 | /* script.c |
| 3 | * |
| 4 | * Functions to call the DHCP client notification scripts |
| 5 | * |
| 6 | * Russ Dill <Russ.Dill@asu.edu> July 2001 |
| 7 | * |
Rob Landley | 3f78561 | 2006-05-28 01:06:36 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 11 | #include "common.h" |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 12 | #include "dhcpc.h" |
Denis Vlasenko | 5a3395b | 2006-11-18 19:51:32 +0000 | [diff] [blame] | 13 | #include "options.h" |
| 14 | |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 15 | |
| 16 | /* get a rough idea of how long an option will be (rounding up...) */ |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 17 | static const uint8_t len_of_option_as_string[] = { |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 18 | [OPTION_IP] = sizeof("255.255.255.255 "), |
| 19 | [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2, |
Denys Vlasenko | 97ef654 | 2009-07-03 18:14:03 +0200 | [diff] [blame] | 20 | [OPTION_STATIC_ROUTES]= sizeof("255.255.255.255/32 255.255.255.255 "), |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 21 | [OPTION_STRING] = 1, |
Denis Vlasenko | 35a064b | 2008-11-06 00:49:59 +0000 | [diff] [blame] | 22 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 23 | [OPTION_STR1035] = 1, |
| 24 | #endif |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 25 | [OPTION_BOOLEAN] = sizeof("yes "), |
| 26 | [OPTION_U8] = sizeof("255 "), |
| 27 | [OPTION_U16] = sizeof("65535 "), |
| 28 | [OPTION_S16] = sizeof("-32768 "), |
| 29 | [OPTION_U32] = sizeof("4294967295 "), |
| 30 | [OPTION_S32] = sizeof("-2147483684 "), |
| 31 | }; |
| 32 | |
| 33 | |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 34 | /* note: ip is a pointer to an IP in network order, possibly misaliged */ |
| 35 | static int sprint_nip(char *dest, const char *pre, const uint8_t *ip) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 36 | { |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 37 | return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
| 41 | /* really simple implementation, just count the bits */ |
Denis Vlasenko | 35ff746 | 2007-11-28 19:23:12 +0000 | [diff] [blame] | 42 | static int mton(uint32_t mask) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 43 | { |
Denis Vlasenko | 35ff746 | 2007-11-28 19:23:12 +0000 | [diff] [blame] | 44 | int i = 0; |
| 45 | mask = ntohl(mask); /* 111110000-like bit pattern */ |
| 46 | while (mask) { |
| 47 | i++; |
| 48 | mask <<= 1; |
| 49 | } |
| 50 | return i; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 54 | /* Create "opt_name=opt_value" string */ |
Denys Vlasenko | 97ef654 | 2009-07-03 18:14:03 +0200 | [diff] [blame] | 55 | static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 56 | { |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 57 | unsigned upper_length; |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 58 | int len, type, optlen; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 59 | uint16_t val_u16; |
| 60 | int16_t val_s16; |
| 61 | uint32_t val_u32; |
| 62 | int32_t val_s32; |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 63 | char *dest, *ret; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 64 | |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 65 | /* option points to OPT_DATA, need to go back and get OPT_LEN */ |
| 66 | len = option[OPT_LEN - OPT_DATA]; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 67 | type = type_p->flags & TYPE_MASK; |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 68 | optlen = dhcp_option_lengths[type]; |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 69 | upper_length = len_of_option_as_string[type] * (len / optlen); |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 70 | |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 71 | dest = ret = xmalloc(upper_length + strlen(opt_name) + 2); |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 72 | dest += sprintf(ret, "%s=", opt_name); |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 73 | |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 74 | while (len >= optlen) { |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 75 | switch (type) { |
| 76 | case OPTION_IP_PAIR: |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 77 | dest += sprint_nip(dest, "", option); |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 78 | *dest++ = '/'; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 79 | option += 4; |
| 80 | optlen = 4; |
| 81 | case OPTION_IP: /* Works regardless of host byte order. */ |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 82 | dest += sprint_nip(dest, "", option); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 83 | break; |
| 84 | case OPTION_BOOLEAN: |
| 85 | dest += sprintf(dest, *option ? "yes" : "no"); |
| 86 | break; |
| 87 | case OPTION_U8: |
| 88 | dest += sprintf(dest, "%u", *option); |
| 89 | break; |
| 90 | case OPTION_U16: |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 91 | move_from_unaligned16(val_u16, option); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 92 | dest += sprintf(dest, "%u", ntohs(val_u16)); |
| 93 | break; |
| 94 | case OPTION_S16: |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 95 | move_from_unaligned16(val_s16, option); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 96 | dest += sprintf(dest, "%d", ntohs(val_s16)); |
| 97 | break; |
| 98 | case OPTION_U32: |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 99 | move_from_unaligned32(val_u32, option); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 100 | dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32)); |
| 101 | break; |
| 102 | case OPTION_S32: |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 103 | move_from_unaligned32(val_s32, option); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 104 | dest += sprintf(dest, "%ld", (long) ntohl(val_s32)); |
| 105 | break; |
| 106 | case OPTION_STRING: |
| 107 | memcpy(dest, option, len); |
| 108 | dest[len] = '\0'; |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 109 | return ret; /* Short circuit this case */ |
Denys Vlasenko | 97ef654 | 2009-07-03 18:14:03 +0200 | [diff] [blame] | 110 | case OPTION_STATIC_ROUTES: { |
| 111 | /* Option binary format: |
| 112 | * mask [one byte, 0..32] |
| 113 | * ip [big endian, 0..4 bytes depending on mask] |
| 114 | * router [big endian, 4 bytes] |
| 115 | * may be repeated |
| 116 | * |
| 117 | * We convert it to a string "IP/MASK ROUTER IP2/MASK2 ROUTER2" |
| 118 | */ |
| 119 | const char *pfx = ""; |
| 120 | |
| 121 | while (len >= 1 + 4) { /* mask + 0-byte ip + router */ |
| 122 | uint32_t nip; |
| 123 | uint8_t *p; |
| 124 | unsigned mask; |
| 125 | int bytes; |
| 126 | |
| 127 | mask = *option++; |
| 128 | if (mask > 32) |
| 129 | break; |
| 130 | len--; |
| 131 | |
| 132 | nip = 0; |
| 133 | p = (void*) &nip; |
| 134 | bytes = (mask + 7) / 8; /* 0 -> 0, 1..8 -> 1, 9..16 -> 2 etc */ |
| 135 | while (--bytes >= 0) { |
| 136 | *p++ = *option++; |
| 137 | len--; |
| 138 | } |
| 139 | if (len < 4) |
| 140 | break; |
| 141 | |
| 142 | /* print ip/mask */ |
| 143 | dest += sprint_nip(dest, pfx, (void*) &nip); |
| 144 | pfx = " "; |
| 145 | dest += sprintf(dest, "/%u ", mask); |
| 146 | /* print router */ |
| 147 | dest += sprint_nip(dest, "", option); |
| 148 | option += 4; |
| 149 | len -= 4; |
| 150 | } |
| 151 | |
| 152 | return ret; |
| 153 | } |
Denis Vlasenko | 35a064b | 2008-11-06 00:49:59 +0000 | [diff] [blame] | 154 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 155 | case OPTION_STR1035: |
| 156 | /* unpack option into dest; use ret for prefix (i.e., "optname=") */ |
| 157 | dest = dname_dec(option, len, ret); |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 158 | if (dest) { |
| 159 | free(ret); |
| 160 | return dest; |
| 161 | } |
| 162 | /* error. return "optname=" string */ |
| 163 | return ret; |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 164 | #endif |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 165 | } |
| 166 | option += optlen; |
| 167 | len -= optlen; |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 168 | if (len <= 0) |
| 169 | break; |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 170 | *dest++ = ' '; |
| 171 | *dest = '\0'; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 172 | } |
Denis Vlasenko | 5066473 | 2007-02-27 21:15:08 +0000 | [diff] [blame] | 173 | return ret; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
| 177 | /* put all the parameters into an environment */ |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 178 | static char **fill_envp(struct dhcp_packet *packet) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 179 | { |
| 180 | int num_options = 0; |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 181 | int i; |
| 182 | char **envp, **curr; |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 183 | const char *opt_name; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 184 | uint8_t *temp; |
Denis Vlasenko | bd79c3d | 2009-04-01 12:36:09 +0000 | [diff] [blame] | 185 | uint8_t over = 0; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 186 | |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 187 | if (packet) { |
| 188 | for (i = 0; dhcp_options[i].code; i++) { |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 189 | if (get_option(packet, dhcp_options[i].code)) { |
| 190 | num_options++; |
| 191 | if (dhcp_options[i].code == DHCP_SUBNET) |
| 192 | num_options++; /* for mton */ |
| 193 | } |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 194 | } |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 195 | if (packet->siaddr_nip) |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 196 | num_options++; |
Denis Vlasenko | bd79c3d | 2009-04-01 12:36:09 +0000 | [diff] [blame] | 197 | temp = get_option(packet, DHCP_OPTION_OVERLOAD); |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 198 | if (temp) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 199 | over = *temp; |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 200 | if (!(over & FILE_FIELD) && packet->file[0]) |
| 201 | num_options++; |
| 202 | if (!(over & SNAME_FIELD) && packet->sname[0]) |
| 203 | num_options++; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 206 | curr = envp = xzalloc(sizeof(char *) * (num_options + 3)); |
| 207 | *curr = xasprintf("interface=%s", client_config.interface); |
| 208 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 209 | |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 210 | if (packet == NULL) |
| 211 | return envp; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 212 | |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 213 | *curr = xmalloc(sizeof("ip=255.255.255.255")); |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 214 | sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 215 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 216 | |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 217 | opt_name = dhcp_option_strings; |
| 218 | i = 0; |
| 219 | while (*opt_name) { |
Denis Vlasenko | c90c3f3 | 2006-11-23 12:57:49 +0000 | [diff] [blame] | 220 | temp = get_option(packet, dhcp_options[i].code); |
Denis Vlasenko | c2f5b02 | 2006-11-28 00:21:46 +0000 | [diff] [blame] | 221 | if (!temp) |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 222 | goto next; |
Denys Vlasenko | 7895b91 | 2009-07-03 16:59:59 +0200 | [diff] [blame] | 223 | *curr = xmalloc_optname_optval(temp, &dhcp_options[i], opt_name); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 224 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 225 | |
| 226 | /* Fill in a subnet bits option for things like /24 */ |
| 227 | if (dhcp_options[i].code == DHCP_SUBNET) { |
Denis Vlasenko | 35ff746 | 2007-11-28 19:23:12 +0000 | [diff] [blame] | 228 | uint32_t subnet; |
Denis Vlasenko | efb545b | 2008-12-08 22:56:18 +0000 | [diff] [blame] | 229 | move_from_unaligned32(subnet, temp); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 230 | *curr = xasprintf("mask=%d", mton(subnet)); |
| 231 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 232 | } |
Denis Vlasenko | b539c84 | 2007-11-29 08:17:45 +0000 | [diff] [blame] | 233 | next: |
| 234 | opt_name += strlen(opt_name) + 1; |
| 235 | i++; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 236 | } |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 237 | if (packet->siaddr_nip) { |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 238 | *curr = xmalloc(sizeof("siaddr=255.255.255.255")); |
Denys Vlasenko | 56f2d06 | 2009-06-16 10:25:35 +0200 | [diff] [blame] | 239 | sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 240 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 241 | } |
| 242 | if (!(over & FILE_FIELD) && packet->file[0]) { |
| 243 | /* watch out for invalid packets */ |
| 244 | packet->file[sizeof(packet->file) - 1] = '\0'; |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 245 | *curr = xasprintf("boot_file=%s", packet->file); |
| 246 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 247 | } |
| 248 | if (!(over & SNAME_FIELD) && packet->sname[0]) { |
| 249 | /* watch out for invalid packets */ |
| 250 | packet->sname[sizeof(packet->sname) - 1] = '\0'; |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 251 | *curr = xasprintf("sname=%s", packet->sname); |
| 252 | putenv(*curr++); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 253 | } |
| 254 | return envp; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | /* Call a script with a par file and env vars */ |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 259 | void FAST_FUNC udhcp_run_script(struct dhcp_packet *packet, const char *name) |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 260 | { |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 261 | char **envp, **curr; |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 262 | char *argv[3]; |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 263 | |
| 264 | if (client_config.script == NULL) |
| 265 | return; |
| 266 | |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 267 | envp = fill_envp(packet); |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 268 | |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 269 | /* call script */ |
Denys Vlasenko | 26c64ba | 2009-11-02 18:53:57 +0100 | [diff] [blame] | 270 | log1("Executing %s %s", client_config.script, name); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 271 | argv[0] = (char*) client_config.script; |
| 272 | argv[1] = (char*) name; |
| 273 | argv[2] = NULL; |
| 274 | wait4pid(spawn(argv)); |
| 275 | |
| 276 | for (curr = envp; *curr; curr++) { |
Denys Vlasenko | 6947d2c | 2009-06-17 13:24:03 +0200 | [diff] [blame] | 277 | log2(" %s", *curr); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 278 | bb_unsetenv(*curr); |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 279 | free(*curr); |
Denis Vlasenko | 76ddc2e | 2008-12-30 05:05:31 +0000 | [diff] [blame] | 280 | } |
Denis Vlasenko | fbd2918 | 2007-04-07 01:05:47 +0000 | [diff] [blame] | 281 | free(envp); |
Mike Frysinger | 7031f62 | 2006-05-08 03:20:50 +0000 | [diff] [blame] | 282 | } |