diff mbox

[1/7,v3] package/busybox: Add facility for DHCP hooks

Message ID 1402982507.184367.599670173206.1.gpush@pablo
State Accepted
Headers show

Commit Message

Jeremy Kerr June 17, 2014, 5:21 a.m. UTC
The (u)dhcpc hook installed by the busybox package configures the
network and exits. If we want to do anything further with a DHCP lease,
we'd have to replace the script entirely.

This change introduces a .d directory for hooks (based on the script
filename), which are executed after the interface configuration. This
allows packages to drop a script file in the .d directory to perform
actions on DHCP events.

We'll use this in a later change to notify petitboot of DHCP boot
information.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---
 package/busybox/busybox.mk    |    2 ++
 package/busybox/udhcpc.script |    6 ++++++
 2 files changed, 8 insertions(+)

Comments

Yann E. MORIN July 23, 2014, 9:58 p.m. UTC | #1
Jeremy, All,

On 2014-06-17 13:21 +0800, Jeremy Kerr spake thusly:
> The (u)dhcpc hook installed by the busybox package configures the
> network and exits. If we want to do anything further with a DHCP lease,
> we'd have to replace the script entirely.
> 
> This change introduces a .d directory for hooks (based on the script
> filename), which are executed after the interface configuration. This
> allows packages to drop a script file in the .d directory to perform
> actions on DHCP events.
> 
> We'll use this in a later change to notify petitboot of DHCP boot
> information.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Regards,
Yann E. MORIN.

> ---
>  package/busybox/busybox.mk    |    2 ++
>  package/busybox/udhcpc.script |    6 ++++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> index c368b80..bddeb63 100644
> --- a/package/busybox/busybox.mk
> +++ b/package/busybox/busybox.mk
> @@ -222,6 +222,8 @@ define BUSYBOX_INSTALL_TARGET_CMDS
>  	if [ ! -f $(TARGET_DIR)/usr/share/udhcpc/default.script ]; then \
>  		$(INSTALL) -m 0755 -D package/busybox/udhcpc.script \
>  			$(TARGET_DIR)/usr/share/udhcpc/default.script; \
> +		$(INSTALL) -m 755 -d \
> +			$(TARGET_DIR)/usr/share/udhcpc/default.script.d; \
>  	fi
>  	$(BUSYBOX_INSTALL_MDEV_SCRIPT)
>  	$(BUSYBOX_INSTALL_MDEV_CONF)
> diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
> index e23d1f1..50c52e6 100755
> --- a/package/busybox/udhcpc.script
> +++ b/package/busybox/udhcpc.script
> @@ -64,4 +64,10 @@ case "$1" in
>  		;;
>  esac
>  
> +HOOK_DIR="$0.d"
> +for hook in "${HOOK_DIR}/"*; do
> +    [ -f "${hook}" -a -x "${hook}" ] || continue
> +    "${hook}" "${@}"
> +done
> +
>  exit 0
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Arnout Vandecappelle Oct. 12, 2014, 2:14 p.m. UTC | #2
On 17/06/14 07:21, Jeremy Kerr wrote:
> The (u)dhcpc hook installed by the busybox package configures the
> network and exits. If we want to do anything further with a DHCP lease,
> we'd have to replace the script entirely.
> 
> This change introduces a .d directory for hooks (based on the script
> filename), which are executed after the interface configuration. This
> allows packages to drop a script file in the .d directory to perform
> actions on DHCP events.
> 
> We'll use this in a later change to notify petitboot of DHCP boot
> information.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

 I could do some nitpicking but it's good enough as it is.

 Regards,
 Arnout

> 
> ---
>  package/busybox/busybox.mk    |    2 ++
>  package/busybox/udhcpc.script |    6 ++++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> index c368b80..bddeb63 100644
> --- a/package/busybox/busybox.mk
> +++ b/package/busybox/busybox.mk
> @@ -222,6 +222,8 @@ define BUSYBOX_INSTALL_TARGET_CMDS
>  	if [ ! -f $(TARGET_DIR)/usr/share/udhcpc/default.script ]; then \
>  		$(INSTALL) -m 0755 -D package/busybox/udhcpc.script \
>  			$(TARGET_DIR)/usr/share/udhcpc/default.script; \
> +		$(INSTALL) -m 755 -d \
> +			$(TARGET_DIR)/usr/share/udhcpc/default.script.d; \
>  	fi
>  	$(BUSYBOX_INSTALL_MDEV_SCRIPT)
>  	$(BUSYBOX_INSTALL_MDEV_CONF)
> diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
> index e23d1f1..50c52e6 100755
> --- a/package/busybox/udhcpc.script
> +++ b/package/busybox/udhcpc.script
> @@ -64,4 +64,10 @@ case "$1" in
>  		;;
>  esac
>  
> +HOOK_DIR="$0.d"
> +for hook in "${HOOK_DIR}/"*; do
> +    [ -f "${hook}" -a -x "${hook}" ] || continue
> +    "${hook}" "${@}"
> +done
> +
>  exit 0
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
Thomas Petazzoni Jan. 2, 2015, 6:28 p.m. UTC | #3
Dear Jeremy Kerr,

On Tue, 17 Jun 2014 13:21:47 +0800, Jeremy Kerr wrote:
> The (u)dhcpc hook installed by the busybox package configures the
> network and exits. If we want to do anything further with a DHCP lease,
> we'd have to replace the script entirely.
> 
> This change introduces a .d directory for hooks (based on the script
> filename), which are executed after the interface configuration. This
> allows packages to drop a script file in the .d directory to perform
> actions on DHCP events.
> 
> We'll use this in a later change to notify petitboot of DHCP boot
> information.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Thanks, applied after reworking on top of the latest Buildroot.

Thomas
diff mbox

Patch

diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index c368b80..bddeb63 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -222,6 +222,8 @@  define BUSYBOX_INSTALL_TARGET_CMDS
 	if [ ! -f $(TARGET_DIR)/usr/share/udhcpc/default.script ]; then \
 		$(INSTALL) -m 0755 -D package/busybox/udhcpc.script \
 			$(TARGET_DIR)/usr/share/udhcpc/default.script; \
+		$(INSTALL) -m 755 -d \
+			$(TARGET_DIR)/usr/share/udhcpc/default.script.d; \
 	fi
 	$(BUSYBOX_INSTALL_MDEV_SCRIPT)
 	$(BUSYBOX_INSTALL_MDEV_CONF)
diff --git a/package/busybox/udhcpc.script b/package/busybox/udhcpc.script
index e23d1f1..50c52e6 100755
--- a/package/busybox/udhcpc.script
+++ b/package/busybox/udhcpc.script
@@ -64,4 +64,10 @@  case "$1" in
 		;;
 esac
 
+HOOK_DIR="$0.d"
+for hook in "${HOOK_DIR}/"*; do
+    [ -f "${hook}" -a -x "${hook}" ] || continue
+    "${hook}" "${@}"
+done
+
 exit 0