IN_LINKLOCAL(ntohl(lease->addr.s_addr)))
logger(LOG_WARNING, "using IPV4LL address %s",
inet_ntoa(lease->addr));
- if (configure(iface, state->dhcp, lease, options, 1) == -1 &&
+ if (configure(iface, state->dhcp, lease, options, 1) != 0 &&
!(state->options & DHCPCD_DAEMONISED))
return -1;
}
static int
-handle_dhcp(struct if_state *state, struct dhcp_message *dhcp, const struct options *options)
+handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, const struct options *options)
{
struct timespec ts;
+ struct dhcp_message *dhcp = *dhcpp;
struct interface *iface = state->interface;
struct dhcp_lease *lease = &state->lease;
char *addr;
addr = get_option_string(dhcp, DHCP_MESSAGE);
logger(LOG_INFO, "received NAK: %s", addr);
free(addr);
- free(dhcp);
state->state = STATE_INIT;
state->timeout = 0;
state->xid = 0;
if (state->dhcp)
free(state->dhcp);
state->dhcp = dhcp;
+ *dhcpp = NULL;
if (options->options & DHCPCD_INFORM) {
if (options->request_address.s_addr != 0)
}
state->xid = 0;
-
- if (configure(iface, dhcp, &state->lease, options, 1) == -1 &&
- !(state->options & DHCPCD_DAEMONISED))
+ if (configure(iface, dhcp, &state->lease, options, 1) != 0)
return -1;
- if (!(state->options & DHCPCD_DAEMONISED)
- && state->options & DHCPCD_DAEMONISE) {
+ if (!(state->options & DHCPCD_DAEMONISED) &&
+ state->options & DHCPCD_DAEMONISE)
+ {
switch (daemonise(state->pidfd)) {
case 0:
state->options |= DHCPCD_DAEMONISED;
dhcp->xid, state->xid);
continue;
}
- if (handle_dhcp(state, dhcp, options) == 0)
+ if (handle_dhcp(state, &dhcp, options) == 0)
return 0;
} while (state->buffer_pos != 0);
-
- if (state->options & DHCPCD_FORKED)
- return -1;
-
free(dhcp);
- return 0;
+ return -1;
}
int
#include <errno.h>
#include <signal.h>
-#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "net.h"
#include "signal.h"
-int
-exec_cmd(const char *cmd, const char *args, ...)
+static int
+exec_script(const char *cmd, const char *arg1, const char *arg2)
{
- va_list va;
- char **argv;
- int n = 1;
+ char *const argv[4] = { (char *)cmd, (char *)arg1, (char *)arg2, NULL};
int ret = 0;
pid_t pid;
pid_t wpid;
sigset_t full;
sigset_t old;
- va_start(va, args);
- while (va_arg(va, char *) != NULL)
- n++;
- va_end(va);
- argv = xmalloc(sizeof(char *) * (n + 2));
-
- va_start(va, args);
- n = 2;
- argv[0] = (char *)cmd;
- argv[1] = (char *)args;
- while ((argv[n] = va_arg(va, char *)) != NULL)
- n++;
- va_end(va);
+ logger(LOG_DEBUG, "exec `%s' `%s' `%s'", cmd, arg1, arg2);
/* OK, we need to block signals */
sigfillset(&full);
switch (pid) {
case -1:
- logger(LOG_ERR, "vfork: %s", strerror(errno));
+ logger(LOG_ERR, "fork: %s", strerror(errno));
ret = -1;
break;
case 0:
#ifndef THERE_IS_NO_FORK
signal_reset();
#endif
- sigprocmask (SIG_SETMASK, &old, NULL);
- if (execvp(cmd, argv) && errno != ENOENT)
- logger (LOG_ERR, "error executing \"%s\": %s",
- cmd, strerror(errno));
+ sigprocmask(SIG_SETMASK, &old, NULL);
+ execvp(cmd, argv);
+ logger(LOG_ERR, "%s: %s", cmd, strerror(errno));
_exit(111);
/* NOTREACHED */
}
/* Restore our signals */
sigprocmask(SIG_SETMASK, &old, NULL);
- free(argv);
/* Wait for the script to finish */
do {
ret = WEXITSTATUS(status);
else
ret = -1;
- if (ret != 0)
- logger(LOG_ERR, "%s exited non zero", cmd);
return ret;
}
-/* IMPORTANT: Ensure that the last parameter is NULL when calling */
-static void
-exec_script(const char *script, _unused const char *infofile, const char *arg)
-{
- struct stat buf;
-
- if (stat(script, &buf) == -1) {
- if (strcmp(script, DEFAULT_SCRIPT) != 0)
- logger(LOG_ERR, "`%s': %s", script, strerror(ENOENT));
- return;
- }
-
- logger(LOG_DEBUG, "exec \"%s\" \"%s\" \"%s\"", script, infofile, arg);
- exec_cmd(script, infofile, arg, (char *)NULL);
-}
-
static struct rt *
reverse_routes(struct rt *routes)
{
}
exec_script(options->script, iface->infofile, "down");
-
return 0;
}
logger(LOG_ERR, "write_lease: %s", strerror(errno));
exec_script(options->script, iface->infofile, up ? "new" : "up");
-
return 0;
}