* (defined via CONFIG_IFUPDOWN_IFSTATE_PATH) and can be overridden by build
* configuration.
*
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
struct globals {
char **my_environ;
const char *startup_PATH;
-};
+} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static const struct dhcp_client_t ext_dhcp_clients[] = {
{ "dhcpcd",
- "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %clientid%]][[ -l %leasetime%]] %iface%",
+ "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %client%]][[ -l %leasetime%]] %iface%",
"dhcpcd -k %iface%",
},
{ "dhclient",
"pump -i %iface% -k",
},
{ "udhcpc",
- "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]]"
+ "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %client%]]"
"[[ -s %script%]][[ %udhcpc_opts%]]",
"kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
},
bb_error_msg("no dhcp clients found");
return 0;
}
-#elif ENABLE_APP_UDHCPC
+#elif ENABLE_UDHCPC
static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec)
{
#if ENABLE_FEATURE_IFUPDOWN_IP
return 0;
#endif
return execute("udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid "
- "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ %udhcpc_opts%]]",
+ "-i %iface%[[ -H %hostname%]][[ -c %client%]][[ -s %script%]][[ %udhcpc_opts%]]",
ifd, exec);
}
#else
result += static_down(ifd, exec);
return ((result == 3) ? 3 : 0);
}
-#elif ENABLE_APP_UDHCPC
+#elif ENABLE_UDHCPC
static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
{
int result;
- result = execute("kill "
- "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
+ result = execute(
+ "test -f /var/run/udhcpc.%iface%.pid && "
+ "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
+ ifd, exec);
/* Also bring the hardware interface down since
killing the dhcp client alone doesn't do it.
This enables consecutive ifup->ifdown->ifup */
pid_t child;
int status;
- fflush(NULL);
+ fflush_all();
child = vfork();
switch (child) {
case -1: /* failure */
xpiped_pair(infd);
xpiped_pair(outfd);
- fflush(NULL);
- pid = vfork();
+ fflush_all();
+ pid = xvfork();
- switch (pid) {
- case -1: /* failure */
- bb_perror_msg_and_die("vfork");
- case 0: /* child */
+ if (pid == 0) {
+ /* Child */
/* NB: close _first_, then move fds! */
close(infd.wr);
close(outfd.rd);
xmove_fd(infd.rd, 0);
xmove_fd(outfd.wr, 1);
- BB_EXECVP(command, argv);
- _exit(127);
+ BB_EXECVP_or_die(argv);
}
/* parent */
close(infd.rd);
close(outfd.wr);
- *in = fdopen(infd.wr, "w");
- *out = fdopen(outfd.rd, "r");
+ *in = xfdopen_for_write(infd.wr);
+ *out = xfdopen_for_read(outfd.rd);
return pid;
}
int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ifupdown_main(int argc, char **argv)
+int ifupdown_main(int argc UNUSED_PARAM, char **argv)
{
int (*cmds)(struct interface_defn_t *);
struct interfaces_file_t *defn;
}
getopt32(argv, OPTION_STR, &interfaces);
- if (argc - optind > 0) {
+ argv += optind;
+ if (argv[0]) {
if (DO_ALL) bb_show_usage();
} else {
if (!DO_ALL) bb_show_usage();
if (DO_ALL) {
target_list = defn->autointerfaces;
} else {
- llist_add_to_end(&target_list, argv[optind]);
+ llist_add_to_end(&target_list, argv[0]);
}
/* Update the interfaces */