From patchwork Thu Apr 11 19:01:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 1084258 X-Patchwork-Delegate: dedeckeh@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=heimpold.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q/tV7OlJ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=heimpold.de header.i=@heimpold.de header.b="XGhZ4Awb"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44g9P85m44z9s4V for ; Fri, 12 Apr 2019 05:01:48 +1000 (AEST) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject: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=p8YJhmMCyvCm6BUmkgWEj4Vpd139a05oCr/gYdPubVQ=; b=q/tV7OlJS4MBzv 1FH1G4ouXDVqh2lPENp1j3gO+n4ElkLpKHMxfzsTx1O7WRGsQk3RChpVk9JmcV7bBRNyyHHRCQLuY bVarqbj5fSdoO8U2171nv+PArAMeC4T5DF4HxkXiGRfr419ZCGGD+i2yCNegWZq98etoEH4HufxqR 5lsEEV/pXZzPIoNlVSeZOb/6rea6gtEdy357YuMQUZ+MPEVxyGfl+pn+6SeJW9rPYrdVrFCSca6nz 8uLHz9nDAPHlaNlYssZu4l7UP480MtQw1uTfs7lTS/p7mUcuDTgSBdAXVfbS61oGTpWaN52qxryXg nps9SYQMi3ZHcq67bxeA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEewy-0001Pe-Ov; Thu, 11 Apr 2019 19:01:28 +0000 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEewn-0001En-H4 for openwrt-devel@lists.openwrt.org; Thu, 11 Apr 2019 19:01:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1555009272; s=strato-dkim-0002; d=heimpold.de; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=5KUFHjiEtHJdsSnmg0jwYpisQ2kfUfbRWCP9f871Lk0=; b=XGhZ4Awb48LXGPJ8tDMnn0AIWmGAdBRDQunAA7uUKpECW3b/Y67NQ+SD4cY8zLT+ta MHDO9b0OPMhf6CaGhiF68sAKss7HSVhjSg+vA/5z0aIkQt7G71iOeL4z7HMYPlkkVs5F BOsbIO+y7uUCHi8TBHpA0LuFt5V4LmFjE+d5D9OHXjv0Ydg0eljZk9my2HNiMgaV/zNB 9in3YUECNtFVvkrQ0aIalFEEwLVftEZIFZY5MiS8Ms9n3kAB61z88AvNIuASxqiTtP1L WWI4MaKUiUgviZCD8CW7wHwCgpEe7UrW8R1z7pRHNEYriBTgOJsK6PYCkY1AkEDQt1qb uMTQ== X-RZG-AUTH: ":O2kGeEG7b/pS1EW8QnKjhhg/vO4pzqdNytq77N6ZKUSN7PfdWTGQORRBv+ASfYPl1MuRMYWiaOxmsXvCwkD1MIXR/qnteHeLGeCatA==" X-RZG-CLASS-ID: mo00 Received: from tonne.mhei.heimpold.itr by smtp.strato.de (RZmta 44.18 AUTH) with ESMTPSA id a05700v3BJ1CGqT (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 11 Apr 2019 21:01:12 +0200 (CEST) Received: from kerker.mhei.heimpold.itr (kerker.mhei.heimpold.itr [192.168.8.1]) by tonne.mhei.heimpold.itr (Postfix) with ESMTP id 6538B149E71; Thu, 11 Apr 2019 21:01:11 +0200 (CEST) From: Michael Heimpold To: openwrt-devel@lists.openwrt.org Date: Thu, 11 Apr 2019 21:01:06 +0200 Message-Id: <20190411190111.11738-1-mhei@heimpold.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_120118_148968_65CB96E8 X-CRM114-Status: GOOD ( 12.44 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [2a01:238:20a:202:5300:0:0:2 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [OpenWrt-Devel] [PATCH procd 1/4] instance: add support for customizable syslog facilities X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker , Michael Heimpold MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Signed-off-by: Michael Heimpold --- service/instance.c | 32 +++++++++++++++++++++++++++++++- service/instance.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/service/instance.c b/service/instance.c index 3512f66..d37d872 100644 --- a/service/instance.c +++ b/service/instance.c @@ -26,6 +26,8 @@ #include #include #include +#define SYSLOG_NAMES +#include #include @@ -57,6 +59,7 @@ enum { INSTANCE_ATTR_PIDFILE, INSTANCE_ATTR_RELOADSIG, INSTANCE_ATTR_TERMTIMEOUT, + INSTANCE_ATTR_FACILITY, __INSTANCE_ATTR_MAX }; @@ -82,6 +85,7 @@ static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = { [INSTANCE_ATTR_PIDFILE] = { "pidfile", BLOBMSG_TYPE_STRING }, [INSTANCE_ATTR_RELOADSIG] = { "reload_signal", BLOBMSG_TYPE_INT32 }, [INSTANCE_ATTR_TERMTIMEOUT] = { "term_timeout", BLOBMSG_TYPE_INT32 }, + [INSTANCE_ATTR_FACILITY] = { "facility", BLOBMSG_TYPE_STRING }, }; enum { @@ -148,6 +152,18 @@ static void closefd(int fd) close(fd); } +/* convert a string into numeric syslog facility or return -1 if no match found */ +static int +syslog_facility_str_to_int(const char *facility) +{ + CODE *p = facilitynames; + + while (p->c_name && strcasecmp(p->c_name, facility)) + p++; + + return p->c_val; +} + static void instance_limits(const char *limit, const char *value) { @@ -466,7 +482,7 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in) arg0 = basename(blobmsg_data(blobmsg_data(in->command))); snprintf(ident, sizeof(ident), "%s[%d]", arg0, in->proc.pid); - ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident); + ulog_open(ULOG_SYSLOG, in->syslog_facility, ident); do { str = ustream_get_read_buf(s, &len); @@ -628,6 +644,9 @@ instance_config_changed(struct service_instance *in, struct service_instance *in if (in->nice != in_new->nice) return true; + if (in->syslog_facility != in_new->syslog_facility) + return true; + if (string_changed(in->user, in_new->user)) return true; @@ -938,6 +957,15 @@ instance_config_parse(struct service_instance *in) if (!instance_fill_array(&in->errors, tb[INSTANCE_ATTR_ERROR], NULL, true)) return false; + if (tb[INSTANCE_ATTR_FACILITY]) { + int facility = syslog_facility_str_to_int(blobmsg_get_string(tb[INSTANCE_ATTR_FACILITY])); + if (facility != -1) { + in->syslog_facility = facility; + DEBUG(3, "setting facility '%s'\n", blobmsg_get_string(tb[INSTANCE_ATTR_FACILITY])); + } else + DEBUG(3, "unknown syslog facility '%s' given, using default (LOG_DAEMON)\n", blobmsg_get_string(tb[INSTANCE_ATTR_FACILITY])); + } + return true; } @@ -974,6 +1002,7 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr in->trace = in_src->trace; in->seccomp = in_src->seccomp; in->node.avl.key = in_src->node.avl.key; + in->syslog_facility = in_src->syslog_facility; free(in->config); in->config = in_src->config; @@ -1022,6 +1051,7 @@ instance_init(struct service_instance *in, struct service *s, struct blob_attr * in->timeout.cb = instance_timeout; in->proc.cb = instance_exit; in->term_timeout = 5; + in->syslog_facility = LOG_DAEMON; in->_stdout.fd.fd = -2; in->_stdout.stream.string_data = true; diff --git a/service/instance.h b/service/instance.h index 771406c..9300d32 100644 --- a/service/instance.h +++ b/service/instance.h @@ -59,6 +59,7 @@ struct service_instance { struct jail jail; char *seccomp; char *pidfile; + int syslog_facility; uint32_t term_timeout; uint32_t respawn_timeout;