From owner-svn-src-all@freebsd.org Thu Feb 21 06:40:16 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7019614F8B96; Thu, 21 Feb 2019 06:40:16 +0000 (UTC) (envelope-from jah@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1410F9134F; Thu, 21 Feb 2019 06:40:16 +0000 (UTC) (envelope-from jah@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DCAE519BBD; Thu, 21 Feb 2019 06:40:15 +0000 (UTC) (envelope-from jah@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1L6eFHj008434; Thu, 21 Feb 2019 06:40:15 GMT (envelope-from jah@FreeBSD.org) Received: (from jah@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1L6eFVQ008433; Thu, 21 Feb 2019 06:40:15 GMT (envelope-from jah@FreeBSD.org) Message-Id: <201902210640.x1L6eFVQ008433@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jah set sender to jah@FreeBSD.org using -f From: "Jason A. Harmening" Date: Thu, 21 Feb 2019 06:40:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r344422 - stable/12/lib/libcasper/services/cap_syslog X-SVN-Group: stable-12 X-SVN-Commit-Author: jah X-SVN-Commit-Paths: stable/12/lib/libcasper/services/cap_syslog X-SVN-Commit-Revision: 344422 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1410F9134F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.967,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2019 06:40:16 -0000 Author: jah Date: Thu Feb 21 06:40:15 2019 New Revision: 344422 URL: https://svnweb.freebsd.org/changeset/base/344422 Log: MFC r343827: r342089 changed cap_syslog(3) to preserve the stdio descriptors inherited from its parent so that LOG_PERROR would work. However, this caused dhclient(8)'s stdio streams to remain open across daemonization, breaking the ability to capture its foreground output as done in netconfig_ipv4. Fix this by reverting r341692 and instead passing the parent's stderr descriptor as an argument to cap_openlog() only when LOG_PERROR is specified in logopt. PR: 234514 Modified: stable/12/lib/libcasper/services/cap_syslog/cap_syslog.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libcasper/services/cap_syslog/cap_syslog.c ============================================================================== --- stable/12/lib/libcasper/services/cap_syslog/cap_syslog.c Thu Feb 21 06:02:51 2019 (r344421) +++ stable/12/lib/libcasper/services/cap_syslog/cap_syslog.c Thu Feb 21 06:40:15 2019 (r344422) @@ -88,6 +88,9 @@ cap_openlog(cap_channel_t *chan, const char *ident, in } nvlist_add_number(nvl, "logopt", logopt); nvlist_add_number(nvl, "facility", facility); + if (logopt & LOG_PERROR) { + nvlist_add_descriptor(nvl, "stderr", STDERR_FILENO); + } nvl = cap_xfer_nvlist(chan, nvl); if (nvl == NULL) { return; @@ -131,6 +134,7 @@ cap_setlogmask(cap_channel_t *chan, int maskpri) */ static char *LogTag; +static int prev_stderr = -1; static void slog_vsyslog(const nvlist_t *limits __unused, const nvlist_t *nvlin, @@ -146,6 +150,8 @@ slog_openlog(const nvlist_t *limits __unused, const nv nvlist_t *nvlout __unused) { const char *ident; + uint64_t logopt; + int stderr_fd; ident = dnvlist_get_string(nvlin, "ident", NULL); if (ident != NULL) { @@ -153,8 +159,19 @@ slog_openlog(const nvlist_t *limits __unused, const nv LogTag = strdup(ident); } - openlog(LogTag, nvlist_get_number(nvlin, "logopt"), - nvlist_get_number(nvlin, "facility")); + logopt = nvlist_get_number(nvlin, "logopt"); + if (logopt & LOG_PERROR) { + stderr_fd = dnvlist_get_descriptor(nvlin, "stderr", -1); + if (prev_stderr == -1) + prev_stderr = dup(STDERR_FILENO); + if (prev_stderr != -1) + (void)dup2(stderr_fd, STDERR_FILENO); + } else if (prev_stderr != -1) { + (void)dup2(prev_stderr, STDERR_FILENO); + close(prev_stderr); + prev_stderr = -1; + } + openlog(LogTag, logopt, nvlist_get_number(nvlin, "facility")); } static void @@ -166,6 +183,12 @@ slog_closelog(const nvlist_t *limits __unused, const n free(LogTag); LogTag = NULL; + + if (prev_stderr != -1) { + (void)dup2(prev_stderr, STDERR_FILENO); + close(prev_stderr); + prev_stderr = -1; + } } static void @@ -198,4 +221,4 @@ syslog_command(const char *cmd, const nvlist_t *limits return (0); } -CREATE_SERVICE("system.syslog", NULL, syslog_command, CASPER_SERVICE_STDIO); +CREATE_SERVICE("system.syslog", NULL, syslog_command, 0);