From 37cea1dd47022a4cf4b0fe179339caacbb958014 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 27 Jun 2022 13:37:34 -0500 Subject: [PATCH] dhcpcd: Wait for carrier before active In order to ensure that network interfaces are active, but not necessarily fully configured, before *network.target* is reached, the *dhcpcd.service* unit now waits until at least one interface has processed the `CARRIER` event before being marked as active. This is accomplished using the *sd_notify* infrastructure, via the `systemd-notify` command, executed in a client configuration hook script. --- package/dhcpcd/dhcpcd.mk | 3 +++ package/dhcpcd/dhcpcd.service | 3 ++- package/dhcpcd/ready.hook.sh | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 package/dhcpcd/ready.hook.sh diff --git a/package/dhcpcd/dhcpcd.mk b/package/dhcpcd/dhcpcd.mk index bec7ae7..1de6165 100644 --- a/package/dhcpcd/dhcpcd.mk +++ b/package/dhcpcd/dhcpcd.mk @@ -5,6 +5,9 @@ define DHCPCD_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m u=rw,go=r \ $(BR2_EXTERNAL_metricspi_PATH)/package/dhcpcd/dhcpcd-wait-online.service \ $(TARGET_DIR)/usr/lib/systemd/system/dhcpcd-wait-online.service + $(INSTALL) -D -m u=rwx,go=rx \ + $(BR2_EXTERNAL_metricspi_PATH)/package/dhcpcd/ready.hook.sh \ + $(TARGET_DIR)/usr/lib/dhcpcd/dhcpcd-hooks/01-ready $(INSTALL) -D -m u=rwx,go=rx \ $(BR2_EXTERNAL_metricspi_PATH)/package/dhcpcd/online.hook.sh \ $(TARGET_DIR)/usr/lib/dhcpcd/dhcpcd-hooks/99-online diff --git a/package/dhcpcd/dhcpcd.service b/package/dhcpcd/dhcpcd.service index 86b5a43..e52a251 100644 --- a/package/dhcpcd/dhcpcd.service +++ b/package/dhcpcd/dhcpcd.service @@ -4,7 +4,8 @@ Wants=network.target Before=network.target [Service] -ExecStart=/usr/sbin/dhcpcd -q --nobackground +Type=notify +ExecStart=/usr/sbin/dhcpcd -q --nobackground --env NOTIFY_SOCKET=${NOTIFY_SOCKET} [Install] WantedBy=multi-user.target diff --git a/package/dhcpcd/ready.hook.sh b/package/dhcpcd/ready.hook.sh new file mode 100644 index 0000000..10cc6fb --- /dev/null +++ b/package/dhcpcd/ready.hook.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "${reason}" = CARRIER ]; then + systemd-notify --pid=${pid} --ready +fi