Skip to content

Commit fde51c7

Browse files
committed
Make reconf_reboot logic more understandable
1 parent a0c4051 commit fde51c7

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/dhcpcd.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,27 +1402,36 @@ reload_config(struct dhcpcd_ctx *ctx)
14021402
}
14031403

14041404
static void
1405-
reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi)
1405+
reconf_reboot(struct dhcpcd_ctx *ctx,
1406+
const int reboot_else_applyaddr,
1407+
const int argc, char **argv,
1408+
const int first_iface_arg)
14061409
{
14071410
int i;
14081411
struct interface *ifp;
1412+
bool args_empty = argc == first_iface_arg;
14091413

14101414
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
1411-
for (i = oi; i < argc; i++) {
1415+
// Find ifp in iface args
1416+
for (i = first_iface_arg; i < argc; i++) {
14121417
if (strcmp(ifp->name, argv[i]) == 0)
14131418
break;
14141419
}
1415-
if (oi != argc && i == argc)
1416-
continue;
1420+
1421+
bool iface_found = i != argc;
1422+
1423+
if (!args_empty && !iface_found)
1424+
continue; // try to find other ifaces
1425+
// Note: if args_empty affect all interfaces
1426+
14171427
if (ifp->active == IF_ACTIVE_USER) {
1418-
if (action)
1428+
if (reboot_else_applyaddr)
14191429
if_reboot(ifp, argc, argv);
14201430
#ifdef INET
14211431
else
14221432
ipv4_applyaddr(ifp);
14231433
#endif
1424-
} else if (i != argc) {
1425-
/* iface wasnt found above -> it's new. start it. */
1434+
} else if (iface_found) {
14261435
ifp->active = IF_ACTIVE_USER;
14271436
dhcpcd_initstate1(ifp, argc, argv, 0); // control cmd args
14281437

@@ -1539,7 +1548,7 @@ dhcpcd_signal_cb(int sig, void *arg)
15391548
reload_config(ctx);
15401549
/* Preserve any options passed on the commandline
15411550
* when we were started. */
1542-
reconf_reboot(ctx, 1, ctx->argc, ctx->argv,
1551+
reconf_reboot(ctx, 1 /*1=if_reboot*/, ctx->argc, ctx->argv,
15431552
ctx->argc - ctx->ifc);
15441553
return;
15451554
case SIGUSR1:

0 commit comments

Comments
 (0)