/* We should define a maximum for the NAK exponential backoff */
#define NAKOFF_MAX 60
-/* Wait N nanoseconds between sending a RELEASE and dropping the address.
- * This gives the kernel enough time to actually send it. */
-#define RELEASE_DELAY_S 0
-#define RELEASE_DELAY_NS 10000000
-
#ifndef IPDEFTTL
#define IPDEFTTL 64 /* RFC1340 */
#endif
void
dhcp_drop(struct interface *ifp, const char *reason)
{
- struct dhcp_state *state;
-#ifdef RELEASE_SLOW
- struct timespec ts;
-#endif
+ struct dhcp_state *state = D_STATE(ifp);
- state = D_STATE(ifp);
/* dhcp_start may just have been called and we don't yet have a state
* but we do have a timeout, so punt it. */
if (state == NULL || state->state == DHS_NONE) {
ifp->name, inet_ntoa(state->lease.addr));
dhcp_new_xid(ifp);
send_message(ifp, DHCP_RELEASE, NULL);
-#ifdef RELEASE_SLOW
- /* Give the packet a chance to go */
- ts.tv_sec = RELEASE_DELAY_S;
- ts.tv_nsec = RELEASE_DELAY_NS;
- nanosleep(&ts, NULL);
-#endif
}
}
#ifdef AUTH
dhcp_auth_reset(&state->auth);
#endif
- /* Close DHCP ports so a changed interface family is picked
- * up by a new BPF state. */
- dhcp_close(ifp);
-
state->state = DHS_NONE;
free(state->offer);
state->offer = NULL;
state->lease.addr.s_addr = 0;
ifp->options->options &= ~(DHCPCD_CSR_WARNED |
DHCPCD_ROUTER_HOST_ROUTE_WARNED);
+
+ /* Close DHCP ports so a changed interface family is picked
+ * up by a new BPF state. */
+ dhcp_close(ifp);
}
static int
fprintf(stderr, "%s", log);
}
+static void
+dhcpcd_pidfile_timeout(void *arg)
+{
+ struct dhcpcd_ctx *ctx = arg;
+ pid_t pid;
+
+ pid = pidfile_read(ctx->pidfile);
+
+ if(pid == -1)
+ eloop_exit(ctx->eloop, EXIT_SUCCESS);
+ else if (++ctx->duid_len >= 100) { /* overload duid_len */
+ logerrx("pid %d failed to exit", pid);
+ eloop_exit(ctx->eloop, EXIT_FAILURE);
+ } else
+ eloop_timeout_add_msec(ctx->eloop, 100,
+ dhcpcd_pidfile_timeout, ctx);
+}
+
int
main(int argc, char **argv, char **envp)
{
/* We can still continue and send the command
* via the control socket. */
} else {
- struct timespec ts;
-
if (sig == SIGHUP || sig == SIGUSR1)
goto exit_success;
/* Spin until it exits */
loginfox("waiting for pid %d to exit", pid);
- ts.tv_sec = 0;
- ts.tv_nsec = 100000000; /* 10th of a second */
- for(i = 0; i < 100; i++) {
- nanosleep(&ts, NULL);
- if (pidfile_read(ctx.pidfile) == -1)
- goto exit_success;
- }
- logerrx("pid %d failed to exit", pid);
- goto exit_failure;
+ dhcpcd_pidfile_timeout(&ctx);
+ goto run_loop;
}
}
#endif
#ifdef __NR_munmap
SECCOMP_ALLOW(__NR_munmap),
#endif
-#ifdef __NR_nanosleep
- SECCOMP_ALLOW(__NR_nanosleep), /* XXX should use ppoll instead */
-#endif
#ifdef __NR_newfstatat
SECCOMP_ALLOW(__NR_newfstatat),
#endif