From patchwork Thu Jan 23 14:29:57 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: 1228065 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=jeX3e82V; 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 483PnS1pC8z9sSL for ; Fri, 24 Jan 2020 01:30:19 +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=HTej6AGbKiafLjRlNJiIpuKrYuohZOPDlgw/MRLRAak=; b=jeX3e82Vx7vWj0 /kTntgn6lmWovP8oo9W6r7IBPo3M/4s9GIkYUYV8PYmrG8Ig6+FaJAFtmYuUM0buXrb6KsEE6AwwV dTbhUSIiKVNtHX6xdxVGcjFqnGcqmVOZXpOxEtoi+TyaetyM+mUi/mJKgTDPYj9IWTxMU3EGZU4RG HVNaLGxsoXslmLdJePqq5LTMe/Gq/RzCfN2T9yXD279JYzmErII7mXIbtIR3GiQudBH1YTokY5Ezm D+qyHj9+4aR+b/1ZqVPOyzi6EVGRx0Zzdol0aafgXGFAm4RzzKkuUUq2aQa1m/0jX8NvDhPlR77Do TyQv1z+VE4jtuFCQyoMQ==; 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 1iudUq-0001R1-PS; Thu, 23 Jan 2020 14:30:12 +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 1iudUn-00018j-L6 for openwrt-devel@lists.openwrt.org; Thu, 23 Jan 2020 14:30:11 +0000 Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id 5683619F4498; Thu, 23 Jan 2020 15:30:08 +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 Ar5q7t98_XZr; Thu, 23 Jan 2020 15:30:05 +0100 (CET) Received: from localhost.localdomain (labsitronics.feld.cvut.cz [147.32.211.25]) by max.feld.cvut.cz (Postfix) with ESMTP id C346419F4474; Thu, 23 Jan 2020 15:30:05 +0100 (CET) From: =?utf-8?q?Ond=C5=99ej_Votava?= To: openwrt-devel@lists.openwrt.org Date: Thu, 23 Jan 2020 15:29:57 +0100 Message-Id: <20200123142957.23546-1-ondrej.votava@cvut.cz> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20200120230504.GH69327@meh.true.cz> References: <20200120230504.GH69327@meh.true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200123_063009_845599_826C41B3 X-CRM114-Status: UNSURE ( 7.88 ) 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: ynezz@true.cz, =?utf-8?q?Ond=C5=99ej_Votava?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 | 22 ++++++++++++++++++++++ service/instance.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/service/instance.c b/service/instance.c index abd1f34..3aad426 100644 --- a/service/instance.c +++ b/service/instance.c @@ -560,6 +560,24 @@ instance_delete(struct service_instance *in) service_stopped(s); } +static int +instance_exit_code(int ret) +{ + if (WIFEXITED(ret)) { + return WEXITSTATUS(ret); + } + + if (WIFSIGNALED(ret)) { + return SIGNALLED_OFFSET + WTERMSIG(ret); + } + + if (WIFSTOPPED(ret)) { + return WSTOPSIG(ret); + } + + return 1; +} + static void instance_exit(struct uloop_process *p, int ret) { @@ -574,6 +592,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 +1110,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 +1144,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..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; @@ -62,6 +63,7 @@ struct service_instance { char *seccomp; char *pidfile; int syslog_facility; + int exit_code; uint32_t term_timeout; uint32_t respawn_timeout;