From patchwork Thu Jan 23 13:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Votava?= X-Patchwork-Id: 1227925 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=2607:7c80:54:e::133; helo=bombadil.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=cvut.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=u1APokE4; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 483N7f26LJz9sP3 for ; Fri, 24 Jan 2020 00:15:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EZ1125MH0ZVmTUGUaW6CZ8Xjjq2ARmSKWxEQZ9FyCIg=; b=u1APokE4A5UbsT N4WNzllCrZ5fn18clABfLDcmSwlbRk2MS7zkxtx8SXjzIpMXNLLVuLMlPTzyB7mRBYuoH3p9/tHq8 RC1FXSxXMczyRaLeqYpTkz5ECR1Fgg8caTIm/jPNZCvffTXN7v2LfwsjXf4I2QYREYQbZqUyu5m4Y 3jt0b8cTcrYTK1+YNTCBXknFem06yCEuk+KGX8B312q/AFM8XXbYiPYNn5HR/1sr+SXYiAQ9D9mO9 gktDX047wSEBhENP97+cN2vK5WdkJXhz783yE6RQgIo43AYbx1pdJ8SAEpdXoAeL/MaJJ2weD09uu getItfUJzy9yVHE7yvew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iucKw-0003yY-9I; Thu, 23 Jan 2020 13:15:54 +0000 Received: from max.feld.cvut.cz ([147.32.192.36]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iucKt-0003yD-0n for openwrt-devel@lists.openwrt.org; Thu, 23 Jan 2020 13:15:52 +0000 Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id ADFA219F4474; Thu, 23 Jan 2020 14:15:49 +0100 (CET) X-Virus-Scanned: IMAP STYX AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, port 10044) with ESMTP id TPyIqwGiPcjw; Thu, 23 Jan 2020 14:15:47 +0100 (CET) Received: from localhost.localdomain (labsitronics.feld.cvut.cz [147.32.211.25]) by max.feld.cvut.cz (Postfix) with ESMTP id 4D32419F4498; Thu, 23 Jan 2020 14:15:47 +0100 (CET) From: ondrej.votava@cvut.cz To: openwrt-devel@lists.openwrt.org Date: Thu, 23 Jan 2020 14:15:27 +0100 Message-Id: <20200123131527.23003-1-ondrej.votava@cvut.cz> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20200120095305.18132-1-ondrej.votava@cvut.cz> References: <20200120095305.18132-1-ondrej.votava@cvut.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200123_051551_214526_557B62D1 X-CRM114-Status: UNSURE ( 8.91 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [147.32.192.36 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [147.32.192.36 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Subject: [OpenWrt-Devel] [PATCH] procd: show process's exit code X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Ond=C5=99ej_Votava?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Ondřej Votava Adds feature to show exit code of processes launched by procd. The exit code is shown for finished process when ubus's service list method is called. The exit code value is computed according to waitpid(2) and http://tldp.org/LDP/abs/html/exitcodes.html Signed-off-by: Ondřej Votava --- service/instance.c | 16 ++++++++++++++++ service/instance.h | 1 + 2 files changed, 17 insertions(+) diff --git a/service/instance.c b/service/instance.c index abd1f34..13e7d0a 100644 --- a/service/instance.c +++ b/service/instance.c @@ -560,6 +560,18 @@ instance_delete(struct service_instance *in) service_stopped(s); } +static int +instance_exit_code(int ret) +{ + if(WIFEXITED(ret)) { + return WEXITSTATUS(ret); + } + else if (WIFSIGNALED(ret)) { + return 128 + WTERMSIG(ret); + } + return 1; +} + static void instance_exit(struct uloop_process *p, int ret) { @@ -574,6 +586,7 @@ instance_exit(struct uloop_process *p, int ret) DEBUG(2, "Instance %s::%s exit with error code %d after %ld seconds\n", in->srv->name, in->name, ret, runtime); + in->exit_code = instance_exit_code(ret); uloop_timeout_cancel(&in->timeout); service_event("instance.stop", in->srv->name, in->name); @@ -1091,6 +1104,7 @@ instance_init(struct service_instance *in, struct service *s, struct blob_attr * in->proc.cb = instance_exit; in->term_timeout = 5; in->syslog_facility = LOG_DAEMON; + in->exit_code = 0; in->_stdout.fd.fd = -2; in->_stdout.stream.string_data = true; @@ -1124,6 +1138,8 @@ void instance_dump(struct blob_buf *b, struct service_instance *in, int verbose) if (in->command) blobmsg_add_blob(b, in->command); blobmsg_add_u32(b, "term_timeout", in->term_timeout); + if (!in->proc.pending) + blobmsg_add_u32(b, "exit_code", in->exit_code); if (!avl_is_empty(&in->errors.avl)) { struct blobmsg_list_node *var; diff --git a/service/instance.h b/service/instance.h index 42cc4be..05a2fc3 100644 --- a/service/instance.h +++ b/service/instance.h @@ -62,6 +62,7 @@ struct service_instance { char *seccomp; char *pidfile; int syslog_facility; + int exit_code; uint32_t term_timeout; uint32_t respawn_timeout; From patchwork Thu Jan 23 13:36:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Votava?= X-Patchwork-Id: 1227967 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=2607:7c80:54:e::133; helo=bombadil.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=cvut.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=umQovOhU; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 483NcB6NN8z9sP3 for ; Fri, 24 Jan 2020 00:37:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9NZPvDN9IbjwZb8KqtZLA7CqicDmopDYR1NK3ZEOgV4=; b=umQovOhU/ZRv3y 7iYzftJb4y0swIRfQKe+BTM2CIHly51tc8UQ6KdSM9RJXm5IOR0HguDGg5FS1f6n0Rbv517zXIGqk NNPTZNp9Bc9N6GFODP7/yOFKJYOApmKZTZkDAnGJ3oKw4hH4R36Lj/B3K8vfirT2nycs+Ep7z0EsS XK7Q1YPo+ig3f52U4K7j+aKrX/NYIAIPRY3RGgqJ5YExWCdXAOZTdJl/1DL/lkFwDw9Ql/TbbPWEK CwC6Tq5kNc72HYG5TaWSc9+5iWf20jUTDBSSOQUxPf0IPyKIM28pBBtoQL4O+yg2trU5IV6++8cFg WlBh8N7JPnHitCkPQS4A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iucfS-0003PQ-MS; Thu, 23 Jan 2020 13:37:06 +0000 Received: from max.feld.cvut.cz ([147.32.192.36]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iucfP-0003P8-Ll for openwrt-devel@lists.openwrt.org; Thu, 23 Jan 2020 13:37:05 +0000 Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id B087019F44B5; Thu, 23 Jan 2020 14:37:01 +0100 (CET) X-Virus-Scanned: IMAP STYX AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, port 10044) with ESMTP id azcGekIvRoH0; Thu, 23 Jan 2020 14:36:59 +0100 (CET) Received: from localhost.localdomain (labsitronics.feld.cvut.cz [147.32.211.25]) by max.feld.cvut.cz (Postfix) with ESMTP id 45FB419F44BC; Thu, 23 Jan 2020 14:36:59 +0100 (CET) From: ondrej.votava@cvut.cz To: openwrt-devel@lists.openwrt.org Date: Thu, 23 Jan 2020 14:36:50 +0100 Message-Id: <20200123133650.23139-1-ondrej.votava@cvut.cz> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20200123131527.23003-1-ondrej.votava@cvut.cz> References: <20200123131527.23003-1-ondrej.votava@cvut.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200123_053703_865281_3EAFCEEF X-CRM114-Status: UNSURE ( 8.97 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [147.32.192.36 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [147.32.192.36 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Subject: [OpenWrt-Devel] [PATCH 2/2] procd: show process's exit code X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Ond=C5=99ej_Votava?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Ondřej Votava Adds feature to show exit code of processes launched by procd. The exit code is shown for finished process when ubus's service list method is called. The exit code value is computed according to waitpid(2) and http://tldp.org/LDP/abs/html/exitcodes.html Signed-off-by: Ondřej Votava --- service/instance.c | 7 +++---- service/instance.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/service/instance.c b/service/instance.c index 13e7d0a..342888a 100644 --- a/service/instance.c +++ b/service/instance.c @@ -563,11 +563,10 @@ instance_delete(struct service_instance *in) static int instance_exit_code(int ret) { - if(WIFEXITED(ret)) { + if (WIFEXITED(ret)) { return WEXITSTATUS(ret); - } - else if (WIFSIGNALED(ret)) { - return 128 + WTERMSIG(ret); + } else if (WIFSIGNALED(ret)) { + return SIGNALLED_OFFSET + WTERMSIG(ret); } return 1; } diff --git a/service/instance.h b/service/instance.h index 05a2fc3..d7b4319 100644 --- a/service/instance.h +++ b/service/instance.h @@ -21,6 +21,7 @@ #include "../utils/utils.h" #define RESPAWN_ERROR (5 * 60) +#define SIGNALLED_OFFSET 128 struct jail { bool procfs;