Skip to content

Commit 9c69fb3

Browse files
committed
eloop: exit all eloops when stopping on signals
1 parent c2068c0 commit 9c69fb3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/dhcpcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ dhcpcd_signal_cb(int sig, void *arg)
15231523
dhcpcd_exiting = true;
15241524
if (!(ctx->options & DHCPCD_TEST))
15251525
stop_all_interfaces(ctx, opts);
1526-
eloop_exit(ctx->eloop, exit_code);
1526+
eloop_exitall(exit_code);
15271527
dhcpcd_exiting = false;
15281528
}
15291529
#endif

src/eloop.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct eloop_timeout {
120120
};
121121

122122
struct eloop {
123+
TAILQ_ENTRY(eloop) next;
123124
TAILQ_HEAD(event_head, eloop_event) events;
124125
size_t nevents;
125126
struct event_head free_events;
@@ -152,6 +153,8 @@ struct eloop {
152153
bool events_invalid;
153154
};
154155

156+
TAILQ_HEAD(eloop_head, eloop) eloops = TAILQ_HEAD_INITIALIZER(eloops);
157+
155158
#ifdef HAVE_REALLOCARRAY
156159
#define eloop_realloca reallocarray
157160
#else
@@ -572,6 +575,17 @@ eloop_exit(struct eloop *eloop, int code)
572575
eloop->exitnow = true;
573576
}
574577

578+
void
579+
eloop_exitall(int code)
580+
{
581+
struct eloop *eloop;
582+
583+
TAILQ_FOREACH(eloop, &eloops, next) {
584+
eloop->exitcode = code;
585+
eloop->exitnow = true;
586+
}
587+
}
588+
575589
#if defined(USE_KQUEUE) || defined(USE_EPOLL)
576590
static int
577591
eloop_open(struct eloop *eloop)
@@ -580,6 +594,8 @@ eloop_open(struct eloop *eloop)
580594

581595
#if defined(HAVE_KQUEUE1)
582596
fd = kqueue1(O_CLOEXEC);
597+
#elif defined(KQUEUE_CLOEXEC)
598+
fd = kqueuex(KQUEUE_CLOEXEC);
583599
#elif defined(USE_KQUEUE)
584600
int flags;
585601

@@ -850,6 +866,7 @@ eloop_new(void)
850866
}
851867
#endif
852868

869+
TAILQ_INSERT_TAIL(&eloops, eloop, next);
853870
return eloop;
854871
}
855872

@@ -886,6 +903,7 @@ eloop_free(struct eloop *eloop)
886903
close(eloop->fd);
887904
#endif
888905
free(eloop->fds);
906+
TAILQ_REMOVE(&eloops, eloop, next);
889907
free(eloop);
890908
}
891909

src/eloop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct eloop *eloop_new(void);
9797
struct eloop *eloop_new_with_signals(struct eloop *);
9898
void eloop_free(struct eloop *);
9999
void eloop_exit(struct eloop *, int);
100+
void eloop_exitall(int);
100101
int eloop_forked(struct eloop *, unsigned short);
101102
int eloop_start(struct eloop *);
102103

0 commit comments

Comments
 (0)