From patchwork Mon Dec 14 12:36:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Eckert X-Patchwork-Id: 1415928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dev.tdt.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=eKPJzBg5; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CvgtV3gPXz9sVH for ; Mon, 14 Dec 2020 23:38:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=y7mWgOxfWy2X1v4huYcW+TZeO38k6Vq6C7qQ3lt/o9E=; b=eKPJzBg5aAnjbx28/tJ2+N3zQ0 EFvAw64Ouc7R7vd7WHkom4VCj4alc2zplU6w+NqLhw4t+fnja25l5Qc9Wsxycq62HpAmBIDiSiiA3 1QNALzL0hHeXl24M6vUrekionBux0ZQejr7UTHIU55du3mbM2iGO4ueOd1wppqgkZc+O9t7bRzp5X sHsj6mMzMNzQJPhvEm1dcOhlCAgPC6Ai/XkukSRT8cHtjoeLN4P/eCppv47GT3GiMeCy8UahAR6qz 75HHUEkce7lXZOJoW/CkuTZRjgAA4b8sSaoNAMUcEtTccGSfJWQPe5gzAL3czCPo0ltv0+xcXA2rI tU0Gx5gQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kon5u-0006zM-4L; Mon, 14 Dec 2020 12:36:50 +0000 Received: from mxout70.expurgate.net ([194.37.255.70]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kon5q-0006xT-Nz for openwrt-devel@lists.openwrt.org; Mon, 14 Dec 2020 12:36:48 +0000 Received: from [127.0.0.1] (helo=localhost) by relay.expurgate.net with smtp (Exim 4.90) (envelope-from ) id 1kon5f-0000Aq-Ut; Mon, 14 Dec 2020 13:36:36 +0100 Received: from [195.243.126.94] (helo=securemail.tdt.de) by relay.expurgate.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90) (envelope-from ) id 1kon5f-0000AU-6b; Mon, 14 Dec 2020 13:36:35 +0100 Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id D7BB9240041; Mon, 14 Dec 2020 13:36:34 +0100 (CET) Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id 85BBC240040; Mon, 14 Dec 2020 13:36:34 +0100 (CET) Received: from feckert.dev.tdt.de (unknown [10.2.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 941E620601; Mon, 14 Dec 2020 13:36:33 +0100 (CET) From: Florian Eckert To: daniel@makrotopia.org Subject: [PATCH] procd: add info json output Date: Mon, 14 Dec 2020 13:36:27 +0100 Message-ID: <20201214123627.23555-1-fe@dev.tdt.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de X-purgate-ID: 151534::1607949395-0000535B-561A4AB9/0/0 X-purgate-type: clean X-purgate: clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_073646_925627_0089E450 X-CRM114-Status: GOOD ( 12.90 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [194.37.255.70 listed in list.dnswl.org] X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openwrt-devel@lists.openwrt.org, Florian Eckert , Florian.Eckert@googlemail.com Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org By adding the extra command `info` it is now possible to retrieve all relevant data from a procd started service directly via the init script. Until now, you have to query the ubus with the command: ubus call service list '{"name":"","verbose":true}' With this change, the init script is now used with the command: /etc/init.d/ info Signed-off-by: Florian Eckert --- package/base-files/files/etc/rc.common | 5 +++++ package/system/procd/files/procd.sh | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common index f39b69464e..c7fde31d41 100755 --- a/package/base-files/files/etc/rc.common +++ b/package/base-files/files/etc/rc.common @@ -121,6 +121,7 @@ extra_command "enabled" "Check if service is started on boot" extra_command "running" "Check if service is running" extra_command "status" "Service status" extra_command "trace" "Start with syscall trace" + extra_command "info" "Dump service info as json" . $IPKG_INSTROOT/lib/functions/procd.sh basescript=$(readlink "$initscript") @@ -173,6 +174,10 @@ extra_command "enabled" "Check if service is started on boot" _procd_status "$(basename ${basescript:-$initscript})" "$1" fi } + + info() { + _procd_info "$(basename ${basescript:-$initscript})" + } } ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}" diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index d86b7219da..1969cdf973 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -474,6 +474,20 @@ _procd_status() { fi } +_procd_info() { + local service="$1" + local data + + data=$(_procd_ubus_call list | jsonfilter -e '@["'"$service"'"]') + [ -z "$data" ] && { echo "not found"; return 3; } + + json_init + json_add_string name "$service" + json_add_boolean verbose "1" + json_add_string name "$service" + _procd_ubus_call list +} + procd_open_data() { local name="$1" json_set_namespace procd __procd_old_cb