procd: update to git HEAD and add new script helpers
authorDaniel Golle <daniel@makrotopia.org>
Thu, 5 Aug 2021 01:56:17 +0000 (02:56 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 5 Aug 2021 02:46:21 +0000 (03:46 +0100)
 e10de28 jail: cgroups-bpf: fix compile with musl 1.2
 f5d9b14 hotplug-dispatch: fix rare memory leaks in error paths

Add new init script helpers:
 procd_add_start_mount_trigger
 procd_add_reload_mount_trigger
 procd_get_mountpoints

Both trigger helpers expect a list of paths which are checked against
the mount targets configured in /etc/config/fstab and a trigger for all
mountpoints covered by the list of paths is setup.

procd_get_mountpoints is useful to find out if and which mountpoints
are covered by a list of paths.

Example:
  DATADIRS="/mnt/data/foo /mnt/data/bar /etc/foo/baz /var/lib/doe"

  start_service() {
    [ "$_BOOT" = "1" ] &&
      [ "$(procd_get_mountpoints $DATADIRS)" ] && return 0

    procd_open_instance
    # ...
    procd_close_instance
  }

  boot() {
    _BOOT=1 start
  }

  service_triggers() {
    procd_add_start_mount_trigger $DATADIRS
  }

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
package/system/procd/Makefile
package/system/procd/files/procd.sh

index 33fec22d83b09371067246371c6fff9ac19fcae7..efd2fc32b8abc7a428a213661acbe7cfadd3dc16 100644 (file)
@@ -12,9 +12,9 @@ PKG_RELEASE:=$(AUTORELEASE)
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/procd.git
-PKG_SOURCE_DATE:=2021-08-04
-PKG_SOURCE_VERSION:=516bdf26d4f60dc5fb063da8715fed2bad24dbd0
-PKG_MIRROR_HASH:=670ee1cec775b75c542a5583b59e8b9dc21b22c42d7e3556426caf11eed52b33
+PKG_SOURCE_DATE:=2021-08-05
+PKG_SOURCE_VERSION:=f5d9b14fea85e3272cac5200fb32a5c99ba7fdff
+PKG_MIRROR_HASH:=0be2b84480d63a431721bf01ca95f927717f11c6cecccd1fc7c0e7ea6f2d4e51
 CMAKE_INSTALL:=1
 
 PKG_LICENSE:=GPL-2.0
index d86b7219da81c771655b8e841f30ceeab0a64c83..de30c76878bf75b98d02a824ebd77114c9ef622b 100644 (file)
@@ -329,6 +329,78 @@ _procd_add_config_trigger() {
        json_close_array
 }
 
+_procd_add_mount_trigger() {
+       json_add_array
+       _procd_add_array_data "$1"
+       local action="$2"
+       local multi=0
+       shift ; shift
+
+       json_add_array
+       _procd_add_array_data "if"
+
+       if [ "$2" ]; then
+               json_add_array
+               _procd_add_array_data "or"
+               multi=1
+       fi
+
+       while [ "$1" ]; do
+               json_add_array
+               _procd_add_array_data "eq" "target" "$1"
+               shift
+               json_close_array
+       done
+
+       [ $multi = 1 ] && json_close_array
+
+       json_add_array
+       _procd_add_array_data "run_script" /etc/init.d/$name $action
+       json_close_array
+
+       json_close_array
+       _procd_add_timeout
+       json_close_array
+}
+
+_procd_add_action_mount_trigger() {
+       local script=$(readlink "$initscript")
+       local name=$(basename ${script:-$initscript})
+       local action="$1"
+       local mpath
+       shift
+
+       _procd_open_trigger
+       _procd_add_mount_trigger mount.add $action "$@"
+       _procd_close_trigger
+}
+
+procd_get_mountpoints() {
+       (
+               __procd_check_mount() {
+                       local cfg="$1"
+                       local path="${2%%/}/"
+                       local target
+                       config_get target "$cfg" target
+                       target="${target%%/}/"
+                       [ "$path" != "${path##$target}" ] && echo "${target%%/}"
+               }
+
+               config_load fstab
+               for mpath in "$@"; do
+                       config_foreach __procd_check_mount mount "$mpath"
+               done
+       ) | sort -u
+}
+
+_procd_add_start_mount_trigger() {
+       _procd_add_action_mount_trigger start $(procd_get_mountpoints "$@")
+}
+
+_procd_add_reload_mount_trigger() {
+       _procd_add_action_mount_trigger reload $(procd_get_mountpoints "$@")
+}
+
 _procd_add_raw_trigger() {
        json_add_array
        _procd_add_array_data "$1"
@@ -560,8 +632,11 @@ _procd_wrapper \
        procd_add_raw_trigger \
        procd_add_config_trigger \
        procd_add_interface_trigger \
+       procd_add_mount_trigger \
        procd_add_reload_trigger \
        procd_add_reload_interface_trigger \
+       procd_add_reload_mount_trigger \
+       procd_add_start_mount_trigger \
        procd_open_trigger \
        procd_close_trigger \
        procd_open_instance \