From 838a83e5b3371f2dfc700ee43ccdc0a2261d652a Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 26 May 2023 14:29:28 +0200 Subject: [PATCH] src/confd: fix review issue 'cannot disable dhcp client' - Flip 'enabled' logic, if attribute is missing => 'enabled: false' - Release lease on udhcpc exit - Call initctl with -f (force) when deleting dhcp-$iface.conf otherwise in interactive mode, waiting for (y/N)? question - Also, always use -batch and -quiet modes with initctl Signed-off-by: Joachim Wiberg --- src/confd/src/infix-dhcp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/confd/src/infix-dhcp.c b/src/confd/src/infix-dhcp.c index c2e102ab..bc99406d 100644 --- a/src/confd/src/infix-dhcp.c +++ b/src/confd/src/infix-dhcp.c @@ -22,10 +22,10 @@ static int is_enabled(struct lyd_node *parent, const char *name) const char *attr; attr = lydx_get_cattr(parent, name); - if (!attr || !strcmp(attr, "true")) - return 1; + if (!attr || strcmp(attr, "true")) + return 0; - return 0; + return 1; } static void add(const char *ifname, const char *client_id) @@ -45,16 +45,17 @@ static void add(const char *ifname, const char *client_id) if (args) sprintf(args, "-C -x 61:'\"%s\"'", client_id); } - fprintf(fp, "service name:dhcp :%s udhcpc -f -S -i %s %s -- DHCP client @%s\n", + fprintf(fp, "service name:dhcp :%s udhcpc -f -S -R -i %s %s -- DHCP client @%s\n", ifname, ifname, args ?: "", ifname); fclose(fp); - systemf("initctl enable dhcp-%s", ifname); + if (systemf("initctl -bfq enable dhcp-%s", ifname)) + ERROR("failed enabling DHCP client on %s", ifname); } static void del(const char *ifname) { - systemf("initctl delete dhcp-%s", ifname); + systemf("initctl -bfq delete dhcp-%s", ifname); } static int client_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,