procd: allow usage of * as procd_running() instance parameter
authorAlin Nastac <alin.nastac@gmail.com>
Thu, 17 Oct 2019 12:06:40 +0000 (14:06 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 18 Oct 2019 17:28:11 +0000 (19:28 +0200)
service_running() implementation in /etc/rc.common use it.
It is preferable to use wildcard than assuming the instance
name is the default one.

jsonfilter returns all matches when wildcards are used, hence
the -l 1 argument used to limit output to only one value.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
package/system/procd/Makefile
package/system/procd/files/procd.sh

index 8ff299626216dbd33982527c49f1314deb997008..27702efc514eefabff33e8780446e1a3f00ea155 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=procd
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/procd.git
index 014b4499e15e57ead2aa709323bc917eedb74e58..b8f9a210f69785b3ad039d918de6a15104fe2db6 100644 (file)
@@ -407,12 +407,12 @@ _procd_add_instance() {
 
 procd_running() {
        local service="$1"
-       local instance="${2:-instance1}"
-       local running
+       local instance="${2:-*}"
+       [ "$instance" = "*" ] || instance="'$instance'"
 
        json_init
        json_add_string name "$service"
-       running=$(_procd_ubus_call list | jsonfilter -e "@['$service'].instances['$instance'].running")
+       local running=$(_procd_ubus_call list | jsonfilter -l 1 -e "@['$service'].instances[$instance].running")
 
        [ "$running" = "true" ]
 }