From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 17 Feb 2018 12:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15188700552471 (code B ref -1); Sat, 17 Feb 2018 12:21:02 +0000 Received: (at submit) by debbugs.gnu.org; 17 Feb 2018 12:20:55 +0000 Received: from localhost ([127.0.0.1]:47555 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1U6-0000dn-OQ for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41801) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1U5-0000dc-Vx for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1en1Tz-0005ab-IF for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:48 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:58077) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1en1Tz-0005aX-F1 for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1en1Ty-0000Dl-7Y for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1en1Tv-0005Zd-2g for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:46 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:56608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1en1Tu-0005ZC-Nk for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:42 -0500 Received: from dayas.3.home (178.113.229.194.wireless.dyn.drei.com [178.113.229.194]) by dd26836.kasserver.com (Postfix) with ESMTPSA id AAEEC3360290; Sat, 17 Feb 2018 13:20:40 +0100 (CET) From: Danny Milosavljevic Date: Sat, 17 Feb 2018 13:20:35 +0100 Message-Id: <20180217122035.1443-1-dannym@scratchpost.org> X-Mailer: git-send-email 2.15.1 Tags: patch X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console again - use only /dev/kmsg. * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. (make-shepherd-output-port): Use it. Export. * modules/shepherd/support.scm (default-logfile-date-format): New variable. (default-logfile): Use /dev/kmsg if writable. (default-logfile-date-format): Drop duplicate timestamp. --- modules/shepherd.scm | 6 +++++- modules/shepherd/comm.scm | 11 ++++++----- modules/shepherd/support.scm | 11 ++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..2db56a1 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -141,8 +141,12 @@ ;; Enable logging as first action. (start-logging logfile) + (if (string=? logfile "/dev/kmsg") + ;; Prevent duplicate messages. + (set-current-output-port (%make-void-port "w"))) + ;; Send output to log and clients. - (set-current-output-port shepherd-output-port) + (set-current-output-port (make-shepherd-output-port (current-output-port))) ;; Start the 'root' service. (start root-service) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..6cea6f0 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,7 +51,8 @@ start-logging stop-logging %current-client-socket - shepherd-output-port)) + %current-logfile-date-format + make-shepherd-output-port)) ;; Command for shepherd. @@ -200,6 +201,9 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) +(define %current-logfile-date-format + (make-parameter default-logfile-date-format)) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. @@ -228,7 +232,7 @@ on service '~a':") (let* ((log (lambda (x) (display x log-output-port))) (init-line (lambda () - (log (strftime "%Y-%m-%d %H:%M:%S " + (log (strftime (%current-logfile-date-format) (localtime (current-time))))))) (init-line) (for-each log (reverse buffer)) @@ -259,6 +263,3 @@ on service '~a':") ;; It's an output-only port. "w")) - -(define shepherd-output-port - (make-shepherd-output-port (current-output-port))) diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index bb01edc..585aef9 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -22,6 +22,7 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -43,6 +44,7 @@ user-homedir default-logfile + default-logfile-date-format default-config-file default-socket-dir default-socket-file @@ -282,9 +284,16 @@ TARGET should be a string representing a filepath + name." ;; Logfile. (define default-logfile (if (zero? (getuid)) - (string-append %localstatedir "/log/shepherd.log") + (if (access? "/dev/kmsg" W_OK) + "/dev/kmsg" + (string-append %localstatedir "/log/shepherd.log")) (string-append %user-config-dir "/shepherd.log"))) +(define default-logfile-date-format + (if (and (zero? (getuid)) (string=? default-logfile "/dev/kmsg")) + (format #f "shepherd[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 17 Feb 2018 12:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15188703182937 (code B ref 30498); Sat, 17 Feb 2018 12:26:02 +0000 Received: (at 30498) by debbugs.gnu.org; 17 Feb 2018 12:25:18 +0000 Received: from localhost ([127.0.0.1]:47560 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1YM-0000lJ-Bd for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:25:18 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:47230) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1YK-0000lA-Nu for 30498@debbugs.gnu.org; Sat, 17 Feb 2018 07:25:17 -0500 Received: from localhost (178.113.229.194.wireless.dyn.drei.com [178.113.229.194]) by dd26836.kasserver.com (Postfix) with ESMTPSA id 21F653360290 for <30498@debbugs.gnu.org>; Sat, 17 Feb 2018 13:25:15 +0100 (CET) Date: Sat, 17 Feb 2018 13:25:12 +0100 From: Danny Milosavljevic Message-ID: <20180217132512.7e895e87@scratchpost.org> In-Reply-To: <20180217122035.1443-1-dannym@scratchpost.org> References: <20180217122035.1443-1-dannym@scratchpost.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) It's nice to be able to correlate all the stuff that happens at startup now: Now you can actually see the communication between the processes sometimes :) Example output: $ dmesg ... [ 2.893529] usb 1-6: Manufacturer: Chicony Electronics Co., Ltd. [ 3.056972] shepherd[1]: Service root has been started. [ 3.456744] shepherd[1]: starting services... [ 3.457110] shepherd[1]: Service root-file-system has been started. [ 3.466479] shepherd[1]: waiting for udevd... [ 3.522308] udevd[186]: starting version 3.2.2 [ 3.574506] udevd[186]: starting eudev-3.2.2 [ 3.967420] udevd[186]: no sender credentials received, message ignored [ 4.030350] Non-volatile memory driver v1.3 [ 4.059448] thinkpad_acpi: ThinkPad ACPI Extras v0.25 ... [ 5.298348] ath9k_htc 2-2:1.0 wlp0s29f7u2: renamed from wlan0 [ 5.381098] fbcon: inteldrmfb (fb0) is primary device [ 5.938603] Console: switching to colour frame buffer device 160x50 [ 5.958004] i915 0000:00:02.0: fb0: inteldrmfb frame buffer device [ 5.993028] shepherd[1]: Service udev has been started. [ 10.953719] Btrfs loaded, crc32c=crc32c-generic [ 10.955704] BTRFS: device label dayas-home devid 1 transid 260833 /dev/dm-0 [ 10.983703] shepherd[1]: Service device-mapping-dayas-home has been started. [ 10.984000] shepherd[1]: Service user-file-systems has been started. [ 11.049660] BTRFS info (device dm-0): disk space caching is enabled [ 11.049663] BTRFS info (device dm-0): has skinny extents [ 11.219716] BTRFS info (device dm-0): enabling ssd optimizations [ 11.236633] shepherd[1]: Service file-system-/home has been started. [ 11.237366] shepherd[1]: Service file-system-/dev/pts has been started. [ 11.237997] shepherd[1]: Service file-system-/dev/shm has been started. [ 11.238568] shepherd[1]: Service file-system-/gnu/store has been started. [ 11.239180] shepherd[1]: Service file-system-/run/systemd has been started. [ 11.239839] shepherd[1]: Service file-system-/run/user has been started. [ 11.240465] shepherd[1]: Service file-system-/sys/fs/cgroup has been started. [ 11.241261] shepherd[1]: Service file-system-/sys/fs/cgroup/elogind has been started. [ 16.538532] shepherd[1]: Respawning thermald. ... [ 21.862151] IPv6: ADDRCONF(NETDEV_CHANGE): wlp0s29f7u2: link becomes ready [ 345.176995] shepherd[1]: Respawning xorg-server. [ 345.178541] shepherd[1]: Service xorg-server has been started. [ 764.782498] perf: interrupt took too long (2526 > 2500), lowering kernel.perf_event_max_sample_rate to 79000 From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 17 Feb 2018 16:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.1518886121701 (code B ref 30498); Sat, 17 Feb 2018 16:49:01 +0000 Received: (at 30498) by debbugs.gnu.org; 17 Feb 2018 16:48:41 +0000 Received: from localhost ([127.0.0.1]:48530 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en5fF-0000BF-Bc for submit@debbugs.gnu.org; Sat, 17 Feb 2018 11:48:41 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:38794) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en5fE-0000B8-C6 for 30498@debbugs.gnu.org; Sat, 17 Feb 2018 11:48:40 -0500 Received: from dayas.3.home (178.113.229.194.wireless.dyn.drei.com [178.113.229.194]) by dd26836.kasserver.com (Postfix) with ESMTPSA id B1F4733602D4; Sat, 17 Feb 2018 17:48:38 +0100 (CET) From: Danny Milosavljevic Date: Sat, 17 Feb 2018 17:48:35 +0100 Message-Id: <20180217164835.1178-1-dannym@scratchpost.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180217122035.1443-1-dannym@scratchpost.org> References: <20180217122035.1443-1-dannym@scratchpost.org> Tags: patch X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console again - use only /dev/kmsg. Also redirect stderr to /dev/kmsg in that case. * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. (make-shepherd-output-port): Use it. Export. * modules/shepherd/support.scm (default-logfile-date-format): New variable. (default-logfile): Use /dev/kmsg if writable. (default-logfile-date-format): Drop duplicate timestamp. --- modules/shepherd.scm | 10 +++++++++- modules/shepherd/comm.scm | 20 ++++++++++++-------- modules/shepherd/support.scm | 11 ++++++++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..2893143 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -141,12 +141,20 @@ ;; Enable logging as first action. (start-logging logfile) + (if (string=? logfile "/dev/kmsg") + ;; Prevent duplicate messages. + (set-current-output-port (%make-void-port "w"))) + ;; Send output to log and clients. - (set-current-output-port shepherd-output-port) + (set-current-output-port + (make-shepherd-output-port (current-output-port))) ;; Start the 'root' service. (start root-service) + (set-current-error-port + (make-shepherd-output-port (current-error-port) (const #f))) + ;; This _must_ succeed. (We could also put the `catch' around ;; `main', but it is often useful to get the backtrace, and ;; `caught-error' does not do this yet.) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..dc7d740 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,7 +51,8 @@ start-logging stop-logging %current-client-socket - shepherd-output-port)) + %current-logfile-date-format + make-shepherd-output-port)) ;; Command for shepherd. @@ -200,10 +201,16 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) +(define %current-logfile-date-format + (make-parameter default-logfile-date-format)) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. -(define (make-shepherd-output-port original-output-port) +(define* (make-shepherd-output-port original-output-port + #:optional + (current-client-socket-thunk + %current-client-socket)) (make-soft-port (vector @@ -216,9 +223,9 @@ on service '~a':") (lambda (str) ;; When herd is connected, send it the output; otherwise, in the ;; unlikely case nobody is listening, send to the standard output. - (if (%current-client-socket) + (if (current-client-socket-thunk) (catch-system-error - (display str (%current-client-socket))) + (display str (current-client-socket-thunk))) (display str original-output-port)) ;; Logfile, buffer line-wise and output time for each @@ -228,7 +235,7 @@ on service '~a':") (let* ((log (lambda (x) (display x log-output-port))) (init-line (lambda () - (log (strftime "%Y-%m-%d %H:%M:%S " + (log (strftime (%current-logfile-date-format) (localtime (current-time))))))) (init-line) (for-each log (reverse buffer)) @@ -259,6 +266,3 @@ on service '~a':") ;; It's an output-only port. "w")) - -(define shepherd-output-port - (make-shepherd-output-port (current-output-port))) diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index bb01edc..585aef9 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -22,6 +22,7 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -43,6 +44,7 @@ user-homedir default-logfile + default-logfile-date-format default-config-file default-socket-dir default-socket-file @@ -282,9 +284,16 @@ TARGET should be a string representing a filepath + name." ;; Logfile. (define default-logfile (if (zero? (getuid)) - (string-append %localstatedir "/log/shepherd.log") + (if (access? "/dev/kmsg" W_OK) + "/dev/kmsg" + (string-append %localstatedir "/log/shepherd.log")) (string-append %user-config-dir "/shepherd.log"))) +(define default-logfile-date-format + (if (and (zero? (getuid)) (string=? default-logfile "/dev/kmsg")) + (format #f "shepherd[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 17 Feb 2018 16:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.1518886205851 (code B ref 30498); Sat, 17 Feb 2018 16:51:01 +0000 Received: (at 30498) by debbugs.gnu.org; 17 Feb 2018 16:50:05 +0000 Received: from localhost ([127.0.0.1]:48534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en5ga-0000Df-OR for submit@debbugs.gnu.org; Sat, 17 Feb 2018 11:50:04 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:38888) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en5gY-0000DS-Sa for 30498@debbugs.gnu.org; Sat, 17 Feb 2018 11:50:03 -0500 Received: from localhost (178.113.229.194.wireless.dyn.drei.com [178.113.229.194]) by dd26836.kasserver.com (Postfix) with ESMTPSA id E78EA3361AEE for <30498@debbugs.gnu.org>; Sat, 17 Feb 2018 17:50:01 +0100 (CET) Date: Sat, 17 Feb 2018 17:49:58 +0100 From: Danny Milosavljevic Message-ID: <20180217174958.3fc12621@scratchpost.org> In-Reply-To: <20180217164835.1178-1-dannym@scratchpost.org> References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) (WIP because the cryptsetup passphrase entry prompt is now invisible. Oops? Works if one blindly enters it, though) From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Feb 2018 18:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.151966828827318 (code B ref 30498); Mon, 26 Feb 2018 18:05:02 +0000 Received: (at 30498) by debbugs.gnu.org; 26 Feb 2018 18:04:48 +0000 Received: from localhost ([127.0.0.1]:33808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqN8q-00076X-3B for submit@debbugs.gnu.org; Mon, 26 Feb 2018 13:04:48 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:47018) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqN8o-00076P-Ge for 30498@debbugs.gnu.org; Mon, 26 Feb 2018 13:04:46 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id CC943119AC; Mon, 26 Feb 2018 19:04:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JlUN6S9TLGm0; Mon, 26 Feb 2018 19:04:45 +0100 (CET) Received: from ribbon (unknown [193.50.110.216]) by hera.aquilenet.fr (Postfix) with ESMTPSA id D083D1194B; Mon, 26 Feb 2018 19:04:44 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> Date: Mon, 26 Feb 2018 19:04:44 +0100 In-Reply-To: <20180217164835.1178-1-dannym@scratchpost.org> (Danny Milosavljevic's message of "Sat, 17 Feb 2018 17:48:35 +0100") Message-ID: <87muzvtyo3.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hi! Danny Milosavljevic skribis: > * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console > again - use only /dev/kmsg. Also redirect stderr to /dev/kmsg in > that case. > * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. > (make-shepherd-output-port): Use it. Export. > * modules/shepherd/support.scm (default-logfile-date-format): New variabl= e. > (default-logfile): Use /dev/kmsg if writable. > (default-logfile-date-format): Drop duplicate timestamp. [...] > --- a/modules/shepherd.scm > +++ b/modules/shepherd.scm > @@ -141,12 +141,20 @@ > ;; Enable logging as first action. > (start-logging logfile) >=20=20 > + (if (string=3D? logfile "/dev/kmsg") > + ;; Prevent duplicate messages. > + (set-current-output-port (%make-void-port "w"))) Nitpick: I=E2=80=99d use =E2=80=98when=E2=80=99 here since there=E2=80=99s = no =E2=80=98else=E2=80=99 branch. > +(define %current-logfile-date-format > + (make-parameter default-logfile-date-format)) Please add a one-line comment explaining what the format is. Could you also add a couple of lines in the .texi file explaining that /dev/kmsg is used when it=E2=80=99s available and we=E2=80=99re running as = root? As for cryptsetup, what if the service that runs crypsetup simply parameterizes =E2=80=98log-output-port=E2=80=99 to /dev/console? That woul= d give us the current behavior, right? Apart from that it LGTM, thank you! Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Feb 2018 21:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.151968192330090 (code B ref 30498); Mon, 26 Feb 2018 21:53:01 +0000 Received: (at 30498) by debbugs.gnu.org; 26 Feb 2018 21:52:03 +0000 Received: from localhost ([127.0.0.1]:34039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqQgl-0007pG-Db for submit@debbugs.gnu.org; Mon, 26 Feb 2018 16:52:03 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:45002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqQgi-0007oq-KT for 30498@debbugs.gnu.org; Mon, 26 Feb 2018 16:52:01 -0500 Received: from localhost (77.118.239.24.wireless.dyn.drei.com [77.118.239.24]) by dd26836.kasserver.com (Postfix) with ESMTPSA id 804303360302; Mon, 26 Feb 2018 22:51:58 +0100 (CET) Date: Mon, 26 Feb 2018 22:51:53 +0100 From: Danny Milosavljevic Message-ID: <20180226225153.1d075735@scratchpost.org> In-Reply-To: <87muzvtyo3.fsf@gnu.org> References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/Mw5Pkw5QGMYdBoO6YX93ML8" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --MP_/Mw5Pkw5QGMYdBoO6YX93ML8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Ludo, thanks for the review! Does that mean that I should push to shepherd? If not, new patch attached :) --MP_/Mw5Pkw5QGMYdBoO6YX93ML8 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-shepherd-If-dev-kmsg-is-writable-use-it-for-logging.patch >From 40426570679e83fff25eadbcc20476ebc321740f Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sat, 17 Feb 2018 17:44:34 +0100 Subject: [PATCH v2] shepherd: If /dev/kmsg is writable, use it for logging. Tags: patch * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console again - use only /dev/kmsg. Also redirect stderr to /dev/kmsg in that case. * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. (make-shepherd-output-port): Use it. Export. * modules/shepherd/support.scm (default-logfile-date-format): New variable. (default-logfile): Use /dev/kmsg if writable. (default-logfile-date-format): Drop duplicate timestamp. * doc/shepherd.texi (logging): Document /dev/kmsg. --- doc/shepherd.texi | 3 ++- modules/shepherd.scm | 11 ++++++++++- modules/shepherd/comm.scm | 22 ++++++++++++++-------- modules/shepherd/support.scm | 11 ++++++++++- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 810336c..3c02d92 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -405,7 +405,8 @@ permissions are not as expected. @cindex logging @cindex log file Log output into @var{file}, or if @var{file} is not given, -@code{/var/log/shepherd.log} when running as superuser, +@code{/dev/kmsg} when running as superuser (except when this is not possible -- +then it uses @code{/var/log/shepherd.log}), @code{$XDG_CONFIG_HOME/shepherd/shepherd.log} otherwise. @item --pid[=@var{file}] diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..6acd41e 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -141,8 +141,17 @@ ;; Enable logging as first action. (start-logging logfile) + (when (string=? logfile "/dev/kmsg") + ;; Prevent duplicate messages. + (set-current-output-port (%make-void-port "w"))) + ;; Send output to log and clients. - (set-current-output-port shepherd-output-port) + (set-current-output-port + (make-shepherd-output-port (current-output-port))) + + ;; Send errors to log. + (set-current-error-port + (make-shepherd-output-port (current-error-port) (const #f))) ;; Start the 'root' service. (start root-service) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..99b8d04 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,7 +51,8 @@ start-logging stop-logging %current-client-socket - shepherd-output-port)) + %current-logfile-date-format + make-shepherd-output-port)) ;; Command for shepherd. @@ -200,10 +201,18 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) +;; Every entry in the logfile is prefixed with +;; (strftime %current-logfile-date-format). +(define %current-logfile-date-format + (make-parameter default-logfile-date-format)) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. -(define (make-shepherd-output-port original-output-port) +(define* (make-shepherd-output-port original-output-port + #:optional + (current-client-socket-thunk + %current-client-socket)) (make-soft-port (vector @@ -216,9 +225,9 @@ on service '~a':") (lambda (str) ;; When herd is connected, send it the output; otherwise, in the ;; unlikely case nobody is listening, send to the standard output. - (if (%current-client-socket) + (if (current-client-socket-thunk) (catch-system-error - (display str (%current-client-socket))) + (display str (current-client-socket-thunk))) (display str original-output-port)) ;; Logfile, buffer line-wise and output time for each @@ -228,7 +237,7 @@ on service '~a':") (let* ((log (lambda (x) (display x log-output-port))) (init-line (lambda () - (log (strftime "%Y-%m-%d %H:%M:%S " + (log (strftime (%current-logfile-date-format) (localtime (current-time))))))) (init-line) (for-each log (reverse buffer)) @@ -259,6 +268,3 @@ on service '~a':") ;; It's an output-only port. "w")) - -(define shepherd-output-port - (make-shepherd-output-port (current-output-port))) diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index bb01edc..585aef9 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -22,6 +22,7 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -43,6 +44,7 @@ user-homedir default-logfile + default-logfile-date-format default-config-file default-socket-dir default-socket-file @@ -282,9 +284,16 @@ TARGET should be a string representing a filepath + name." ;; Logfile. (define default-logfile (if (zero? (getuid)) - (string-append %localstatedir "/log/shepherd.log") + (if (access? "/dev/kmsg" W_OK) + "/dev/kmsg" + (string-append %localstatedir "/log/shepherd.log")) (string-append %user-config-dir "/shepherd.log"))) +(define default-logfile-date-format + (if (and (zero? (getuid)) (string=? default-logfile "/dev/kmsg")) + (format #f "shepherd[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the --MP_/Mw5Pkw5QGMYdBoO6YX93ML8-- From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Feb 2018 22:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15196843411172 (code B ref 30498); Mon, 26 Feb 2018 22:33:02 +0000 Received: (at 30498) by debbugs.gnu.org; 26 Feb 2018 22:32:21 +0000 Received: from localhost ([127.0.0.1]:34065 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqRJl-0000Iq-2m for submit@debbugs.gnu.org; Mon, 26 Feb 2018 17:32:21 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:47820) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqRJi-0000Ii-RN for 30498@debbugs.gnu.org; Mon, 26 Feb 2018 17:32:19 -0500 Received: from localhost (77.118.239.24.wireless.dyn.drei.com [77.118.239.24]) by dd26836.kasserver.com (Postfix) with ESMTPSA id B80873360302; Mon, 26 Feb 2018 23:32:17 +0100 (CET) Date: Mon, 26 Feb 2018 23:32:14 +0100 From: Danny Milosavljevic Message-ID: <20180226233214.6fe40fa3@scratchpost.org> In-Reply-To: <87muzvtyo3.fsf@gnu.org> References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Hi Ludo, > As for cryptsetup, what if the service that runs crypsetup simply > parameterizes =E2=80=98log-output-port=E2=80=99 to /dev/console? That wo= uld give us the > current behavior, right? I don't understand why this current-output-port stuff is somehow passed on = to forked processes in the first place (why does cryptsetup care what I do to guile variables?). scheme@(guile-user)> (current-output-port (%make-void-port "w")) scheme@(guile-user)> (system* "ls" "/") scheme@(guile-user)> WTF? It wasn't my intention to inherit them as file descriptors... also, for gui= le buffering ports, how does it inherit those as file descriptors? Will it st= ill do the custom line buffering that shepherd does, also when a child process writes there? From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 27 Feb 2018 09:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15197231911287 (code B ref 30498); Tue, 27 Feb 2018 09:20:02 +0000 Received: (at 30498) by debbugs.gnu.org; 27 Feb 2018 09:19:51 +0000 Received: from localhost ([127.0.0.1]:34284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqbQN-0000Kh-Az for submit@debbugs.gnu.org; Tue, 27 Feb 2018 04:19:51 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:50628) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqbQL-0000KX-UJ for 30498@debbugs.gnu.org; Tue, 27 Feb 2018 04:19:50 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 69ED8103B2; Tue, 27 Feb 2018 10:19:49 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dSpocnggDazg; Tue, 27 Feb 2018 10:19:48 +0100 (CET) Received: from ribbon (unknown [193.50.110.216]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 555B57076; Tue, 27 Feb 2018 10:19:48 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 9 =?UTF-8?Q?Vent=C3=B4se?= an 226 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Tue, 27 Feb 2018 10:19:47 +0100 In-Reply-To: <20180226233214.6fe40fa3@scratchpost.org> (Danny Milosavljevic's message of "Mon, 26 Feb 2018 23:32:14 +0100") Message-ID: <87inai6b7w.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hi Danny, Danny Milosavljevic skribis: >> As for cryptsetup, what if the service that runs crypsetup simply >> parameterizes =E2=80=98log-output-port=E2=80=99 to /dev/console? That w= ould give us the >> current behavior, right? > > I don't understand why this current-output-port stuff is somehow passed o= n to > forked processes in the first place (why does cryptsetup care what I do > to guile variables?). > > scheme@(guile-user)> (current-output-port (%make-void-port "w")) > scheme@(guile-user)> (system* "ls" "/") > scheme@(guile-user)> Funny no? :-) This is in libguile/posix.c, =E2=80=98scm_open_process=E2=80=99 and =E2=80= =98start_child=E2=80=99: when the current input/output/error port isn=E2=80=99t a file port, FDs 0/1/2 in= the child are made to point to /dev/null. Otherwise, they are inherited as file descriptors. For cryptsetup, this should be what we want if we do: (call-with-output-file "/dev/console" (lambda (port) (parameterize ((log-output-port port) (current-input-port port) (current-error-port port)) (invoke "cryptsetup" =E2=80=A6)))) Or do we even need to care about =E2=80=98log-output-port=E2=80=99? Though= ts? > It wasn't my intention to inherit them as file descriptors... also, for g= uile > buffering ports, how does it inherit those as file descriptors? Will it = still > do the custom line buffering that shepherd does, also when a child process > writes there? Shepherd does not process the stdout/err of child processes in any way, so there shouldn=E2=80=99t be buffering there. Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 27 Feb 2018 09:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15197233531553 (code B ref 30498); Tue, 27 Feb 2018 09:23:02 +0000 Received: (at 30498) by debbugs.gnu.org; 27 Feb 2018 09:22:33 +0000 Received: from localhost ([127.0.0.1]:34288 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqbSy-0000Oz-Pf for submit@debbugs.gnu.org; Tue, 27 Feb 2018 04:22:32 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:50656) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eqbSw-0000Or-O4 for 30498@debbugs.gnu.org; Tue, 27 Feb 2018 04:22:31 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 4495810437; Tue, 27 Feb 2018 10:22:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lx_ovF7vcipB; Tue, 27 Feb 2018 10:22:28 +0100 (CET) Received: from ribbon (unknown [193.50.110.216]) by hera.aquilenet.fr (Postfix) with ESMTPSA id ACC9E103B2; Tue, 27 Feb 2018 10:22:28 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226225153.1d075735@scratchpost.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 9 =?UTF-8?Q?Vent=C3=B4se?= an 226 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Tue, 27 Feb 2018 10:22:28 +0100 In-Reply-To: <20180226225153.1d075735@scratchpost.org> (Danny Milosavljevic's message of "Mon, 26 Feb 2018 22:51:53 +0100") Message-ID: <87efl66b3f.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hi! Danny Milosavljevic skribis: > From 40426570679e83fff25eadbcc20476ebc321740f Mon Sep 17 00:00:00 2001 > From: Danny Milosavljevic > Date: Sat, 17 Feb 2018 17:44:34 +0100 > Subject: [PATCH v2] shepherd: If /dev/kmsg is writable, use it for loggin= g. > Tags: patch > > * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console > again - use only /dev/kmsg. Also redirect stderr to /dev/kmsg in > that case. > * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. > (make-shepherd-output-port): Use it. Export. > * modules/shepherd/support.scm (default-logfile-date-format): New variabl= e. > (default-logfile): Use /dev/kmsg if writable. > (default-logfile-date-format): Drop duplicate timestamp. > * doc/shepherd.texi (logging): Document /dev/kmsg. ^ =E2=80=9CLogging=E2=80=9D. > --- a/doc/shepherd.texi > +++ b/doc/shepherd.texi > @@ -405,7 +405,8 @@ permissions are not as expected. > @cindex logging > @cindex log file > Log output into @var{file}, or if @var{file} is not given, > -@code{/var/log/shepherd.log} when running as superuser, > +@code{/dev/kmsg} when running as superuser (except when this is not poss= ible -- > +then it uses @code{/var/log/shepherd.log}), Nitpick: it should be three hyphens without surrounding spaces, leading to an em dash, =E2=80=9Clike---this=E2=80=9D. Let=E2=80=99s just make sure we have a solution for cryptsetup and then you= =E2=80=99re welcome to push it to shepherd.git! Thank you, Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 03 Mar 2018 21:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152011406325215 (code B ref 30498); Sat, 03 Mar 2018 21:55:02 +0000 Received: (at 30498) by debbugs.gnu.org; 3 Mar 2018 21:54:23 +0000 Received: from localhost ([127.0.0.1]:43222 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esF6l-0006Yd-BH for submit@debbugs.gnu.org; Sat, 03 Mar 2018 16:54:23 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:54884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esF6j-0006YV-Ot for 30498@debbugs.gnu.org; Sat, 03 Mar 2018 16:54:22 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 3F184111A6; Sat, 3 Mar 2018 22:54:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K740IazV6DdV; Sat, 3 Mar 2018 22:54:20 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 771FB1A3; Sat, 3 Mar 2018 22:54:20 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> <87inai6b7w.fsf@gnu.org> Date: Sat, 03 Mar 2018 22:54:19 +0100 In-Reply-To: <87inai6b7w.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 27 Feb 2018 10:19:47 +0100") Message-ID: <87bmg46d10.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hey Danny, Looks like we=E2=80=99ve accumulated stuff that justifies a new Shepherd re= lease this time. It=E2=80=99d be nice if we could get this patch in as well! Wh= at are we missing? Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 03 Mar 2018 22:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152011664529250 (code B ref 30498); Sat, 03 Mar 2018 22:38:02 +0000 Received: (at 30498) by debbugs.gnu.org; 3 Mar 2018 22:37:25 +0000 Received: from localhost ([127.0.0.1]:43284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esFmP-0007bi-10 for submit@debbugs.gnu.org; Sat, 03 Mar 2018 17:37:25 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:55316) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esFmM-0007bY-7J for 30498@debbugs.gnu.org; Sat, 03 Mar 2018 17:37:23 -0500 Received: from localhost (77.118.252.91.wireless.dyn.drei.com [77.118.252.91]) by dd26836.kasserver.com (Postfix) with ESMTPSA id 735463360092; Sat, 3 Mar 2018 23:37:20 +0100 (CET) Date: Sat, 3 Mar 2018 23:37:15 +0100 From: Danny Milosavljevic Message-ID: <20180303233715.7ec8a08c@scratchpost.org> In-Reply-To: <87bmg46d10.fsf@gnu.org> References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> <87inai6b7w.fsf@gnu.org> <87bmg46d10.fsf@gnu.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/EoBWwCLfQr0JvEKz8V5uaAv"; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --Sig_/EoBWwCLfQr0JvEKz8V5uaAv Content-Type: multipart/mixed; boundary="MP_/MmnShyv31=IPi5TGbYGeqiS" --MP_/MmnShyv31=IPi5TGbYGeqiS Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I think that just something like this is missing: diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 83600e4..481203d 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -728,20 +728,37 @@ false." ;; it for something unrelated, which can confuse some packages. (dup2 (open-fdes "/dev/null" O_RDONLY) 0) =20 - (when log-file - (catch #t - (lambda () - ;; Redirect stout and stderr to use LOG-FILE. - (catch-system-error (close-fdes 1)) - (catch-system-error (close-fdes 2)) - (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 1) - (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 2)) - (lambda (key . args) - (format (current-error-port) - "failed to open log-file ~s:~%" log-file) - (print-exception (current-error-port) #f key args) - (primitive-exit 1)))) - + (if log-file + (catch #t + (lambda () + ;; Redirect stout and stderr to use LOG-FILE. + (catch-system-error (close-fdes 1)) + (catch-system-error (close-fdes 2)) + (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 1) + (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 2)) + (lambda (key . args) + (format (current-error-port) + "failed to open log-file ~s:~%" log-file) + (print-exception (current-error-port) #f key args) + (primitive-exit 1))) + (catch #t + (lambda () + ;; Make sure the child has stdout/stderr that can be used. + ;; We sometimes set current-error-port to a softport. + ;; libguile would then autoconnect /dev/null - + ;; which we don't want. + ;; Also, cryptsetup interactively asks for a password, + ;; so we don't want /dev/kmsg either. + ;; In a user shepherd all this is not necessary - + ;; but then, port->fdes will not fail. + (when (not (false-if-exception (port->fdes (current-output-= port)))) + (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 1)) + (when (not (false-if-exception (port->fdes (current-error-p= ort)))) + (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 2))) + (lambda (key . args) + (format (current-error-port) "failed to open stdout/stderr\= n") + (print-exception (current-error-port) #f key args) + (primitive-exit 1)))) (let loop ((i 3)) (when (< i max-fd) ;; First try to close any ports associated with file descriptor= I. Patch starting from master attached for convenience. --MP_/MmnShyv31=IPi5TGbYGeqiS Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=shepherd-klog.patch diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 810336c..88b39e3 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -405,7 +405,7 @@ permissions are not as expected. @cindex logging @cindex log file Log output into @var{file}, or if @var{file} is not given, -@code{/var/log/shepherd.log} when running as superuser, +@code{/dev/kmsg} when running as superuser (except when this is not possib= le---then it uses @code{/var/log/shepherd.log}), @code{$XDG_CONFIG_HOME/shepherd/shepherd.log} otherwise. =20 @item --pid[=3D@var{file}] diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..6acd41e 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -141,8 +141,17 @@ ;; Enable logging as first action. (start-logging logfile) =20 + (when (string=3D? logfile "/dev/kmsg") + ;; Prevent duplicate messages. + (set-current-output-port (%make-void-port "w"))) + ;; Send output to log and clients. - (set-current-output-port shepherd-output-port) + (set-current-output-port + (make-shepherd-output-port (current-output-port))) + + ;; Send errors to log. + (set-current-error-port + (make-shepherd-output-port (current-error-port) (const #f))) =20 ;; Start the 'root' service. (start root-service) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..99b8d04 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,7 +51,8 @@ start-logging stop-logging %current-client-socket - shepherd-output-port)) + %current-logfile-date-format + make-shepherd-output-port)) =20 =0C ;; Command for shepherd. @@ -200,10 +201,18 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) =20 +;; Every entry in the logfile is prefixed with +;; (strftime %current-logfile-date-format). +(define %current-logfile-date-format + (make-parameter default-logfile-date-format)) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. -(define (make-shepherd-output-port original-output-port) +(define* (make-shepherd-output-port original-output-port + #:optional + (current-client-socket-thunk + %current-client-socket)) (make-soft-port (vector =20 @@ -216,9 +225,9 @@ on service '~a':") (lambda (str) ;; When herd is connected, send it the output; otherwise, in the ;; unlikely case nobody is listening, send to the standard output. - (if (%current-client-socket) + (if (current-client-socket-thunk) (catch-system-error - (display str (%current-client-socket))) + (display str (current-client-socket-thunk))) (display str original-output-port)) =20 ;; Logfile, buffer line-wise and output time for each @@ -228,7 +237,7 @@ on service '~a':") (let* ((log (lambda (x) (display x log-output-port))) (init-line (lambda () - (log (strftime "%Y-%m-%d %H:%M:%S " + (log (strftime (%current-logfile-date-form= at) (localtime (current-time)))= )))) (init-line) (for-each log (reverse buffer)) @@ -259,6 +268,3 @@ on service '~a':") =20 ;; It's an output-only port. "w")) - -(define shepherd-output-port - (make-shepherd-output-port (current-output-port))) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 83600e4..481203d 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -728,20 +728,37 @@ false." ;; it for something unrelated, which can confuse some packages. (dup2 (open-fdes "/dev/null" O_RDONLY) 0) =20 - (when log-file - (catch #t - (lambda () - ;; Redirect stout and stderr to use LOG-FILE. - (catch-system-error (close-fdes 1)) - (catch-system-error (close-fdes 2)) - (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 1) - (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 2)) - (lambda (key . args) - (format (current-error-port) - "failed to open log-file ~s:~%" log-file) - (print-exception (current-error-port) #f key args) - (primitive-exit 1)))) - + (if log-file + (catch #t + (lambda () + ;; Redirect stout and stderr to use LOG-FILE. + (catch-system-error (close-fdes 1)) + (catch-system-error (close-fdes 2)) + (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 1) + (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 2)) + (lambda (key . args) + (format (current-error-port) + "failed to open log-file ~s:~%" log-file) + (print-exception (current-error-port) #f key args) + (primitive-exit 1))) + (catch #t + (lambda () + ;; Make sure the child has stdout/stderr that can be used. + ;; We sometimes set current-error-port to a softport. + ;; libguile would then autoconnect /dev/null - + ;; which we don't want. + ;; Also, cryptsetup interactively asks for a password, + ;; so we don't want /dev/kmsg either. + ;; In a user shepherd all this is not necessary - + ;; but then, port->fdes will not fail. + (when (not (false-if-exception (port->fdes (current-output-= port)))) + (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 1)) + (when (not (false-if-exception (port->fdes (current-error-p= ort)))) + (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 2))) + (lambda (key . args) + (format (current-error-port) "failed to open stdout/stderr\= n") + (print-exception (current-error-port) #f key args) + (primitive-exit 1)))) (let loop ((i 3)) (when (< i max-fd) ;; First try to close any ports associated with file descriptor= I. diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index bb01edc..585aef9 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -22,6 +22,7 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -43,6 +44,7 @@ =20 user-homedir default-logfile + default-logfile-date-format default-config-file default-socket-dir default-socket-file @@ -282,9 +284,16 @@ TARGET should be a string representing a filepath + na= me." ;; Logfile. (define default-logfile (if (zero? (getuid)) - (string-append %localstatedir "/log/shepherd.log") + (if (access? "/dev/kmsg" W_OK) + "/dev/kmsg" + (string-append %localstatedir "/log/shepherd.log")) (string-append %user-config-dir "/shepherd.log"))) =20 +(define default-logfile-date-format + (if (and (zero? (getuid)) (string=3D? default-logfile "/dev/kmsg")) + (format #f "shepherd[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the --MP_/MmnShyv31=IPi5TGbYGeqiS-- --Sig_/EoBWwCLfQr0JvEKz8V5uaAv Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlqbI5sACgkQ5xo1VCww uqWvwgf/WpjVhzjdtyUrbgBy57DT+lHn7YSJbzIlolWnTu8EVKt2e6Ejr78xkaWH hpyH1SxklOeVO38FO5uC+pbn7sagfTuYfOzhFtP76rQzCBHYf/8q1Dqw6VFqdHrq cHfFTACgVzjfJz/DNEZPKdpwQ5lfK4CDHET5EC3oZL0G/kGdm/caLVhBwqaQNrFD EbW3hkdbWqpUB70cdWloVitgI58jlH0nhZChfVGWvFVN9ZoTVEm67S5pOfOT+Pl6 a4A3tldtmiPlRQbxFqqE5yZ0g8twrtSDv6rycnFYduv6uX5JelOZSeNjHZDIPM9X x6gAUzi0lymib7grPhBGAZD+B42JTA== =kF9P -----END PGP SIGNATURE----- --Sig_/EoBWwCLfQr0JvEKz8V5uaAv-- From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 05 Mar 2018 16:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152026870815226 (code B ref 30498); Mon, 05 Mar 2018 16:52:02 +0000 Received: (at 30498) by debbugs.gnu.org; 5 Mar 2018 16:51:48 +0000 Received: from localhost ([127.0.0.1]:46136 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1estL2-0003xW-7o for submit@debbugs.gnu.org; Mon, 05 Mar 2018 11:51:48 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:39506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1estL0-0003xN-DD for 30498@debbugs.gnu.org; Mon, 05 Mar 2018 11:51:46 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 3BD8811EAA; Mon, 5 Mar 2018 17:51:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AxMVx6sfetR7; Mon, 5 Mar 2018 17:51:44 +0100 (CET) Received: from ribbon (unknown [193.50.110.134]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 93F3111C3D; Mon, 5 Mar 2018 17:51:44 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> <87inai6b7w.fsf@gnu.org> <87bmg46d10.fsf@gnu.org> <20180303233715.7ec8a08c@scratchpost.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 =?UTF-8?Q?Vent=C3=B4se?= an 226 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 05 Mar 2018 17:51:44 +0100 In-Reply-To: <20180303233715.7ec8a08c@scratchpost.org> (Danny Milosavljevic's message of "Sat, 3 Mar 2018 23:37:15 +0100") Message-ID: <87371ea2jj.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Heya, I took the liberty to split this in several patches, which I think makes it easier to follow. I omitted the bits about redirecting stderr, for now, to simplify things. I tested it in a GuixSD VM and it works as advertised! \o/ There=E2=80=99s one thing we need to improve though: syslogd reads /proc/km= sg and prefixes everything that comes from there with =E2=80=9Cvmunix=E2=80=9D= (as if it came from the kernel). That=E2=80=99s inconvenient because it makes it impossible to have syslogd rules to filter shepherd messages. So I think we need to do instead use a =E2=80=98syslog=E2=80=99-style inter= face and, similar to what =E2=80=98syslog=E2=80=99 does in glibc, write to /dev/log u= nless it=E2=80=99s unavailable, in which case we fall back to /dev/kmsg. Thoughts? I=E2=80=99ll see if I can give it a try. Thanks, Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: Danny Milosavljevic Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 06 Mar 2018 08:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152032376422487 (code B ref 30498); Tue, 06 Mar 2018 08:10:02 +0000 Received: (at 30498) by debbugs.gnu.org; 6 Mar 2018 08:09:24 +0000 Received: from localhost ([127.0.0.1]:46800 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1et7f2-0005qc-ET for submit@debbugs.gnu.org; Tue, 06 Mar 2018 03:09:24 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:33346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1et7ey-0005qP-0l for 30498@debbugs.gnu.org; Tue, 06 Mar 2018 03:09:20 -0500 Received: from localhost (77.118.199.63.wireless.dyn.drei.com [77.118.199.63]) by dd26836.kasserver.com (Postfix) with ESMTPSA id E823E33614A4; Tue, 6 Mar 2018 09:09:17 +0100 (CET) Date: Tue, 6 Mar 2018 09:09:05 +0100 From: Danny Milosavljevic Message-ID: <20180306090905.77f528a9@scratchpost.org> In-Reply-To: <87371ea2jj.fsf@gnu.org> References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> <87inai6b7w.fsf@gnu.org> <87bmg46d10.fsf@gnu.org> <20180303233715.7ec8a08c@scratchpost.org> <87371ea2jj.fsf@gnu.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/Wk_unt5IA62ejG146VS/FoR"; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --Sig_/Wk_unt5IA62ejG146VS/FoR Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, On Mon, 05 Mar 2018 17:51:44 +0100 ludo@gnu.org (Ludovic Court=C3=A8s) wrote: > I tested it in a GuixSD VM and it works as advertised! \o/ Yay! > There=E2=80=99s one thing we need to improve though: syslogd reads /proc/= kmsg > and prefixes everything that comes from there with =E2=80=9Cvmunix=E2=80= =9D (as if it > came from the kernel). =20 Also, apparently syslogd uses the timestamp of "when it read the messages out of /dev/kmsg" as syslog entry timestamp *although* /dev/kmsg contains i= ts own timestamps (as offsets-from-bootup). Hrmmm... >That=E2=80=99s inconvenient because it makes it > impossible to have syslogd rules to filter shepherd messages. I've added a shepherd "prefix" in the shepherd messages, so it should end up as "vmunix: shepherd[1]: ..." (or so). The somewhat heavyhanded way to fix it would be to replace strcpy (line, "vmunix: "); by strcpy (line, ""); in inetutils-1.9.4/src/syslogd.c . Or use another syslogd :) According to the Linux kernel documentation the /dev/kmsg ring buffer is specifically allowed to be used by user processes (although they must not impersonate the kernel - if they try, the specified priority is ignored), so we're in the clear there. > So I think we need to do instead use a =E2=80=98syslog=E2=80=99-style int= erface and, > similar to what =E2=80=98syslog=E2=80=99 does in glibc, write to /dev/log= unless it=E2=80=99s > unavailable, in which case we fall back to /dev/kmsg. Yes, in the long run, we should do that. I think for this shepherd release it would be fine to use only /dev/kmsg - it's still an improvement - and the risk that we introduced a new bug by this is basically nonexistent. Later on, we should use /dev/log and fall back to /dev/kmsg and then again use /dev/log as it gets available etc. I'm not sure how to do the synchronisation (from shepherd's point of view, syslogd asynchronously reads from /dev/kmsg and puts the messages into its output files - so if we write to /dev/kmsg, then to /dev/log, then to /dev/kmsg, then to /dev/log, is the message order guaranteed?) >I=E2=80=99ll see if I can give it a try. Thanks :) --Sig_/Wk_unt5IA62ejG146VS/FoR Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlqeTKEACgkQ5xo1VCww uqUBXQgAmNwQh/An5wPAfhFKO4FwnRpdlRcIAP2HbFwQsr/VLOp639tREQM/bSYg T+IoTLPkFy0a/8jCI/xpOfK7HjPGtRRNQ7Dvj+i//yfukGCkuDOvoNH4+rEPKObL Av4AOfBenL8GUAuiKMkn4EXkz4FFdmdXSApLGtvvceK094B1xsvTdlyIzXKDwS5J NzZjii5GZ9y6G8dtwQoVnB80ukcAEHrozGMof8wLGhvqg4LR5rm7F/uK/XuFkezy hXegQ0hDZ4p37/dS+u7zvZ+O115OsK6leAJ+vBgoWzLv5hOENmuyD1jkNvnalGIR lhluoxEwpxQYl3EToaiFsJOIc3uQmg== =6BVe -----END PGP SIGNATURE----- --Sig_/Wk_unt5IA62ejG146VS/FoR-- From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH 2/3] Simplify 'make-shepherd-output-port'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 11:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152042073317237 (code B ref 30498); Wed, 07 Mar 2018 11:06:02 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 11:05:33 +0000 Received: from localhost ([127.0.0.1]:48469 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt3-0004Tw-7b for submit@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt1-0004Tc-RK for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etWsv-0000So-MY for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:26 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etWss-0000Rc-9J; Wed, 07 Mar 2018 06:05:22 -0500 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:43224 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1etWsr-0004lE-S2; Wed, 07 Mar 2018 06:05:22 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 7 Mar 2018 12:04:53 +0100 Message-Id: <20180307110454.17110-3-ludo@gnu.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307110454.17110-1-ludo@gnu.org> References: <87371ea2jj.fsf@gnu.org> <20180307110454.17110-1-ludo@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) * modules/shepherd/comm.scm (%not-newline): New variable. (make-shepherd-output-port): Rewrite second method to simplify and make a single 'display' call per line. --- modules/shepherd/comm.scm | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 596a258..e686bfa 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -216,6 +216,9 @@ on service '~a':") ;; 'strftime' format strings for entries in the log file. (make-parameter default-logfile-date-format)) +(define %not-newline + (char-set-complement (char-set #\newline))) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. @@ -242,26 +245,19 @@ on service '~a':") ;; completed line. (if (not (string-index str #\newline)) (set! buffer (cons str buffer)) - (let* ((log (lambda (x) - (display x (log-output-port)))) - (init-line (lambda () - (log (strftime (%current-logfile-date-format) - (localtime (current-time))))))) - (init-line) - (for-each log (reverse buffer)) - (let* ((lines (string-split str #\newline)) - (last-line (car (take-right lines 1))) - (is-first #t)) - (for-each (lambda (line) - (if is-first - (set! is-first #f) - (init-line)) - (log line) - (log #\newline)) - (drop-right lines 1)) - (set! buffer (if (string-null? last-line) - '() - (list last-line)))))))) + (let* ((str (string-concatenate-reverse (cons str buffer))) + (lines (string-tokenize str %not-newline))) + (define prefix + (strftime (%current-logfile-date-format) + (localtime (current-time)))) + + ;; Make exactly one 'display' call per line to make sure we + ;; don't create several entries for each line. + (for-each (lambda (line) + (display (string-append prefix line "\n") + (log-output-port))) + lines) + (set! buffer '()))))) ;; Flush output. (lambda () -- 2.16.2 From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH 0/3] Log to syslog whenever possible Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 11:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152042073317243 (code B ref 30498); Wed, 07 Mar 2018 11:06:02 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 11:05:33 +0000 Received: from localhost ([127.0.0.1]:48471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt3-0004Ty-Ek for submit@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt1-0004Td-RP for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etWsv-0000Sq-NG for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:26 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etWsp-0000Qa-PW; Wed, 07 Mar 2018 06:05:19 -0500 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:43224 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1etWsp-0004lE-94; Wed, 07 Mar 2018 06:05:19 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 7 Mar 2018 12:04:51 +0100 Message-Id: <20180307110454.17110-1-ludo@gnu.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <87371ea2jj.fsf@gnu.org> References: <87371ea2jj.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello! These patches allow shepherd to use syslog, when /dev/log is reachable, and to fall back to /dev/kmsg otherwise. That leads to unified logging, which is nice. By looking at /var/log/messages one can see the sequence of events, which is often more convenient than having to look at separate log files. And we can filter things via syslogd’s config. However! The downside is that messages upon shutdown written after syslogd has been killed are lost: they go to /dev/kmsg, which goes to the console at that point, but they’re not written anywhere. Until now, everything until the root file system is unmounted (see ‘stop-logging’ call in (gnu services base)) would be written to /var/log/shepherd.log, which is useful to debug shutdown (that’s how I discovered the issue fixed by Guix commit 6c4458172d12dbda969c2eae5b3b6be19a068780, for instance.) So, I don’t know. Can we do better? Should we switch to /var/log/shepherd.log when syslogd disappears? Ideas? That’s a situation where having syslogd inside PID 1 helps… Ludo’. Ludovic Courtès (3): Turn 'log-output-port' into a parameter. Simplify 'make-shepherd-output-port'. Use syslog for logging when running as root. doc/shepherd.texi | 18 +++- modules/shepherd.scm | 209 +++++++++++++++++++++++-------------------- modules/shepherd/comm.scm | 119 ++++++++++++++++++------ modules/shepherd/support.scm | 19 ++-- 4 files changed, 224 insertions(+), 141 deletions(-) -- 2.16.2 From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH 1/3] Turn 'log-output-port' into a parameter. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 11:06:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152042073717260 (code B ref 30498); Wed, 07 Mar 2018 11:06:04 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 11:05:37 +0000 Received: from localhost ([127.0.0.1]:48474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt6-0004UK-ML for submit@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41866) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWt5-0004Th-1X for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etWsy-0000Td-1p for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:29 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etWsr-0000RE-5E; Wed, 07 Mar 2018 06:05:21 -0500 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:43224 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1etWsq-0004lE-GU; Wed, 07 Mar 2018 06:05:21 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 7 Mar 2018 12:04:52 +0100 Message-Id: <20180307110454.17110-2-ludo@gnu.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307110454.17110-1-ludo@gnu.org> References: <87371ea2jj.fsf@gnu.org> <20180307110454.17110-1-ludo@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) * modules/shepherd/comm.scm (log-output-port): Turn into a parameter and publish it. (start-logging, stop-logging): Adjust accordingly and mark as deprecated. (make-shepherd-output-port): Adjust accordingly. * modules/shepherd/support.scm (default-logfile): Remove. (user-default-log-file): New procedure. (default-logfile-date-format): Remove 'if'. * modules/shepherd.scm (main): Have LOGFILE default to #f. Parameterize 'log-output-port' and 'current-output-port'. --- modules/shepherd.scm | 209 +++++++++++++++++++++++-------------------- modules/shepherd/comm.scm | 19 ++-- modules/shepherd/support.scm | 19 ++-- 3 files changed, 129 insertions(+), 118 deletions(-) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index c869464..39fbe14 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -21,6 +21,7 @@ (define-module (shepherd) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:use-module (ice-9 rdelim) ;; Line-based I/O. #:autoload (ice-9 readline) (activate-readline) ;for interactive use #:use-module (oop goops) ;; Defining classes and methods. @@ -77,7 +78,7 @@ (socket-file default-socket-file) (pid-file #f) (secure #t) - (logfile default-logfile)) + (logfile #f)) ;; Process command line arguments. (process-args (program-name) args "" @@ -161,104 +162,116 @@ ;; We do this early so that we can abort early if necessary. (and socket-file (verify-dir (dirname socket-file) #:secure? secure)) - ;; Enable logging as first action. - (start-logging logfile) - - (when (string=? logfile "/dev/kmsg") - ;; By default we'd write both to /dev/kmsg and to stdout. Redirect - ;; stdout to the bitbucket so we don't log twice. - (set-current-output-port (%make-void-port "w"))) - - ;; Send output to log and clients. - (set-current-output-port (make-shepherd-output-port)) - - ;; Start the 'root' service. - (start root-service) - - ;; This _must_ succeed. (We could also put the `catch' around - ;; `main', but it is often useful to get the backtrace, and - ;; `caught-error' does not do this yet.) - (catch #t - (lambda () - (load-in-user-module (or config-file (default-config-file)))) - (lambda (key . args) - (caught-error key args) - (quit 1))) - ;; Start what was started last time. - (and persistency - (catch 'system-error - (lambda () - (start-in-order (read (open-input-file - persistency-state-file)))) - (lambda (key . args) - (apply format #f (gettext (cadr args)) (caddr args)) - (quit 1)))) - - (when (provided? 'threads) - ;; XXX: This terrible hack allows us to make sure that signal handlers - ;; get a chance to run in a timely fashion. Without it, after an EINTR, - ;; we could restart the accept(2) call below before the corresponding - ;; async has been queued. See the thread at - ;; . - (sigaction SIGALRM (lambda _ (alarm 1))) - (alarm 1)) - - ;; Stop everything when we get SIGINT. When running as PID 1, that means - ;; rebooting; this is what happens when pressing ctrl-alt-del, see - ;; ctrlaltdel(8). - (sigaction SIGINT - (lambda _ - (stop root-service))) - ;; Stop everything when we get SIGTERM. - (sigaction SIGTERM - (lambda _ - (stop root-service))) - - ;; Stop everything when we get SIGHUP. - (sigaction SIGHUP - (lambda _ - (stop root-service))) - - ;; Ignore SIGPIPE so that we don't die if a client closes the connection - ;; prematurely. - (sigaction SIGPIPE SIG_IGN) - - (if (not socket-file) - ;; Get commands from the standard input port. - (process-textual-commands (current-input-port)) - ;; Process the data arriving at a socket. - (let ((sock (open-server-socket socket-file)) - - ;; With Guile <= 2.0.9, we can get a system-error exception for - ;; EINTR, which happens anytime we receive a signal, such as - ;; SIGCHLD. Thus, wrap the 'accept' call. - (accept (EINTR-safe accept))) - - ;; Possibly write out our PID, which means we're ready to accept - ;; connections. XXX: What if we daemonized already? - (match pid-file - ((? string? file) - (with-atomic-file-output pid-file - (cute display (getpid) <>))) - (#t (display (getpid))) - (_ #t)) - - (let next-command () - (define (read-from sock) - (match (accept sock) - ((command-source . client-address) - (setvbuf command-source _IOFBF 1024) - (process-connection command-source)) - (_ #f))) - (match (select (list sock) (list) (list) (if poll-services? 0.5 #f)) - (((sock) _ _) - (read-from sock)) - (_ - #f)) - (when poll-services? - (check-for-dead-services)) - (next-command)))))) + ;; Enable logging as first action. + (parameterize ((log-output-port + (cond (logfile + (open-file logfile "al")) + ((zero? (getuid)) + (open-file "/dev/kmsg" "wl")) + (else + (open-file (user-default-log-file) "al")))) + (%current-logfile-date-format + (if (and (not logfile) (zero? (getuid))) + (format #f "shepherd[~d]: " (getpid)) + default-logfile-date-format)) + (current-output-port + ;; Send output to log and clients. + (make-shepherd-output-port + (if (and (zero? (getuid)) (not logfile)) + ;; By default we'd write both to /dev/kmsg and to + ;; stdout. Redirect stdout to the bitbucket so we + ;; don't log twice. + (%make-void-port "w") + (current-output-port))))) + + ;; Start the 'root' service. + (start root-service) + + ;; This _must_ succeed. (We could also put the `catch' around + ;; `main', but it is often useful to get the backtrace, and + ;; `caught-error' does not do this yet.) + (catch #t + (lambda () + (load-in-user-module (or config-file (default-config-file)))) + (lambda (key . args) + (caught-error key args) + (quit 1))) + ;; Start what was started last time. + (and persistency + (catch 'system-error + (lambda () + (start-in-order (read (open-input-file + persistency-state-file)))) + (lambda (key . args) + (apply format #f (gettext (cadr args)) (caddr args)) + (quit 1)))) + + (when (provided? 'threads) + ;; XXX: This terrible hack allows us to make sure that signal handlers + ;; get a chance to run in a timely fashion. Without it, after an EINTR, + ;; we could restart the accept(2) call below before the corresponding + ;; async has been queued. See the thread at + ;; . + (sigaction SIGALRM (lambda _ (alarm 1))) + (alarm 1)) + + ;; Stop everything when we get SIGINT. When running as PID 1, that means + ;; rebooting; this is what happens when pressing ctrl-alt-del, see + ;; ctrlaltdel(8). + (sigaction SIGINT + (lambda _ + (stop root-service))) + + ;; Stop everything when we get SIGTERM. + (sigaction SIGTERM + (lambda _ + (stop root-service))) + + ;; Stop everything when we get SIGHUP. + (sigaction SIGHUP + (lambda _ + (stop root-service))) + + ;; Ignore SIGPIPE so that we don't die if a client closes the connection + ;; prematurely. + (sigaction SIGPIPE SIG_IGN) + + (if (not socket-file) + ;; Get commands from the standard input port. + (process-textual-commands (current-input-port)) + ;; Process the data arriving at a socket. + (let ((sock (open-server-socket socket-file)) + + ;; With Guile <= 2.0.9, we can get a system-error exception for + ;; EINTR, which happens anytime we receive a signal, such as + ;; SIGCHLD. Thus, wrap the 'accept' call. + (accept (EINTR-safe accept))) + + ;; Possibly write out our PID, which means we're ready to accept + ;; connections. XXX: What if we daemonized already? + (match pid-file + ((? string? file) + (with-atomic-file-output pid-file + (cute display (getpid) <>))) + (#t (display (getpid))) + (_ #t)) + + (let next-command () + (define (read-from sock) + (match (accept sock) + ((command-source . client-address) + (setvbuf command-source _IOFBF 1024) + (process-connection command-source)) + (_ #f))) + (match (select (list sock) (list) (list) (if poll-services? 0.5 #f)) + (((sock) _ _) + (read-from sock)) + (_ + #f)) + (when poll-services? + (check-for-dead-services)) + (next-command))))))) (define (process-connection sock) "Process client connection SOCK, reading and processing commands." diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index aeb138e..596a258 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -49,6 +49,7 @@ result->sexp report-command-error + log-output-port start-logging stop-logging make-shepherd-output-port @@ -194,16 +195,18 @@ on service '~a':") -;; Port for logging. This must always be a valid port, never `#f'. -(define log-output-port (%make-void-port "w")) -(define (start-logging file) +(define log-output-port + ;; Port for logging. This must always be a valid port, never `#f'. + (make-parameter (%make-void-port "w"))) + +(define (start-logging file) ;deprecated (let ((directory (dirname file))) (unless (file-exists? directory) (mkdir directory))) - (set! log-output-port (open-file file "al"))) ; line-buffered port -(define (stop-logging) - (close-port log-output-port) - (set! log-output-port (%make-void-port "w"))) + (log-output-port (open-file file "al"))) +(define (stop-logging) ;deprecated + (close-port (log-output-port)) + (log-output-port (%make-void-port "w"))) (define %current-client-socket ;; Socket of the client currently talking to the daemon. @@ -240,7 +243,7 @@ on service '~a':") (if (not (string-index str #\newline)) (set! buffer (cons str buffer)) (let* ((log (lambda (x) - (display x log-output-port))) + (display x (log-output-port)))) (init-line (lambda () (log (strftime (%current-logfile-date-format) (localtime (current-time))))))) diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index 45a2030..380866e 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -23,7 +23,6 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) - #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -47,7 +46,7 @@ display-line user-homedir - default-logfile + user-default-log-file default-logfile-date-format default-config-file default-socket-dir @@ -308,19 +307,15 @@ TARGET should be a string representing a filepath + name." ""(for-each start '()) "))))) -;; Logfile. -(define default-logfile - (if (zero? (getuid)) - (if (access? "/dev/kmsg" W_OK) - "/dev/kmsg" - (string-append %localstatedir "/log/shepherd.log")) - (string-append %user-config-dir "/shepherd.log"))) +;; Logging. +(define (user-default-log-file) + "Return the file name of the user's default log file." + (mkdir-p %user-config-dir #o700) + (string-append %user-config-dir "/shepherd.log")) (define default-logfile-date-format ;; 'strftime' format string to prefix each entry in the log. - (if (string=? default-logfile "/dev/kmsg") - (format #f "shepherd[~d]: " (getpid)) - "%Y-%m-%d %H:%M:%S ")) + "%Y-%m-%d %H:%M:%S ") ;; Configuration file. (define (default-config-file) -- 2.16.2 From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH 3/3] Use syslog for logging when running as root. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 11:06:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.152042074717289 (code B ref 30498); Wed, 07 Mar 2018 11:06:05 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 11:05:47 +0000 Received: from localhost ([127.0.0.1]:48477 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWtH-0004Um-CF for submit@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41945) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etWtG-0004UV-0f for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etWt4-0000Vh-On for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 06:05:41 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etWst-0000S2-H2; Wed, 07 Mar 2018 06:05:23 -0500 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:43224 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1etWst-0004lE-0K; Wed, 07 Mar 2018 06:05:23 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 7 Mar 2018 12:04:54 +0100 Message-Id: <20180307110454.17110-4-ludo@gnu.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307110454.17110-1-ludo@gnu.org> References: <87371ea2jj.fsf@gnu.org> <20180307110454.17110-1-ludo@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) * modules/shepherd/comm.scm (call-with-syslog-port, syslog-output-port): New procedures. * modules/shepherd.scm (main): Set 'log-output-port' to (syslog-output-port) when running as root. * doc/shepherd.texi (Invoking shepherd): Adjust accordingly. --- doc/shepherd.texi | 18 ++++++++++--- modules/shepherd.scm | 2 +- modules/shepherd/comm.scm | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 01d8050..7946f8b 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -406,13 +406,23 @@ permissions are not as expected. @cindex log file Log output into @var{file}. -The default behavior is to write to @file{/dev/kmsg} when running as -superuser. This special device is GNU/Linux-specific; when it does not -exist, write to @file{/var/log/shepherd.log} instead. - For unprivileged users, the default log file is @file{$XDG_CONFIG_HOME/shepherd/shepherd.log}. +@cindex syslog +When running as root, the default behavior is to connect to +@file{/dev/log}, the @dfn{syslog} socket (@pxref{Overview of Syslog,,, +libc, The GNU C Library Reference Manual}). A syslog daemon, +@command{syslogd}, is expected to read messages from there +(@pxref{syslogd invocation, syslogd,, libc, GNU Inetutils}). + +When @file{/dev/log} is unavailable, for instance because +@command{syslogd} is not running, as is the case during system startup +and shutdown, @command{shepherd} falls back to the Linux kernel +@dfn{ring buffer}, @file{/dev/kmsg}. If @file{/dev/kmsg} is missing, as +is the case on other operating systems, it falls back to +@file{/dev/console}. + @item --pid[=@var{file}] When @command{shepherd} is ready to accept connections, write its PID to @var{file} or to the standard output if @var{file} is omitted. diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 39fbe14..fede338 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -168,7 +168,7 @@ (cond (logfile (open-file logfile "al")) ((zero? (getuid)) - (open-file "/dev/kmsg" "wl")) + (syslog-output-port)) (else (open-file (user-default-log-file) "al")))) (%current-logfile-date-format diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index e686bfa..cbd8686 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -50,6 +50,7 @@ report-command-error log-output-port + syslog-output-port start-logging stop-logging make-shepherd-output-port @@ -216,6 +217,71 @@ on service '~a':") ;; 'strftime' format strings for entries in the log file. (make-parameter default-logfile-date-format)) +(define call-with-syslog-port + (let ((port #f)) ;connection to /dev/log + (lambda (proc) + "Call PROC with an open output port. The output port corresponds to +/dev/log (aka. syslog) or, if that is unavailable, a degraded logging +mechanism." + (define (call/syslog) + (catch 'system-error + (lambda () + (proc port)) + (lambda args + (if (memv (system-error-errno args) + (list ENOTCONN ECONNREFUSED EPIPE)) + (begin + (set! port #f) + (call-with-syslog-port proc)) + (apply throw args))))) + + (or (and port (not (port-closed? port)) (call/syslog)) + (let ((sock (socket AF_UNIX SOCK_DGRAM 0))) + (catch 'system-error + (lambda () + (connect sock AF_UNIX "/dev/log") + (setvbuf sock _IOLBF) + (set! port sock) + (call/syslog)) + (lambda args + (close-port sock) + (if (memv (system-error-errno args) + (list ENOENT ECONNREFUSED)) + (catch 'system-error + (lambda () + (call-with-output-file "/dev/kmsg" + (lambda (port) + (setvbuf port _IOFBF) + (proc port)))) + (lambda args + (if (memv (system-error-errno args) + (list ENOENT EACCES EPERM)) + (call-with-output-file "/dev/console" + (lambda (port) + (setvbuf port _IONBF) + (proc port))) + (apply throw args)))) + (apply throw args))))))))) + +(define (syslog-output-port) + "Return the output port to write to syslog or /dev/kmsg, whichever is +available." + (make-soft-port + (vector + (lambda (char) ;write char + (call-with-syslog-port + (lambda (port) + (write-char char port)))) + (lambda (str) ;write string + (call-with-syslog-port + (lambda (port) + (display str port)))) + (const #t) ;flush + #f ;get char + (lambda () ;close + (call-with-syslog-port close-port))) + "w")) ;output port + (define %not-newline (char-set-complement (char-set #\newline))) -- 2.16.2 From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 12:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 30498@debbugs.gnu.org Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15204267942742 (code B ref 30498); Wed, 07 Mar 2018 12:47:01 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 12:46:34 +0000 Received: from localhost ([127.0.0.1]:48510 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etYSo-0000iA-IG for submit@debbugs.gnu.org; Wed, 07 Mar 2018 07:46:34 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:44860) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etYSn-0000i3-Ak for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 07:46:33 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id B594D10F77; Wed, 7 Mar 2018 13:46:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Uzb5Y8XsacUc; Wed, 7 Mar 2018 13:46:31 +0100 (CET) Received: from ribbon (vpn-0-27.aquilenet.fr [IPv6:2a0c:e300:4:27::]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 1635E104F5; Wed, 7 Mar 2018 13:46:31 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180217122035.1443-1-dannym@scratchpost.org> <20180217164835.1178-1-dannym@scratchpost.org> <87muzvtyo3.fsf@gnu.org> <20180226233214.6fe40fa3@scratchpost.org> <87inai6b7w.fsf@gnu.org> <87bmg46d10.fsf@gnu.org> <20180303233715.7ec8a08c@scratchpost.org> <87371ea2jj.fsf@gnu.org> <20180306090905.77f528a9@scratchpost.org> Date: Wed, 07 Mar 2018 13:46:22 +0100 In-Reply-To: <20180306090905.77f528a9@scratchpost.org> (Danny Milosavljevic's message of "Tue, 6 Mar 2018 09:09:05 +0100") Message-ID: <87po4gt5nl.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hello, Danny Milosavljevic skribis: >> There=E2=80=99s one thing we need to improve though: syslogd reads /proc= /kmsg >> and prefixes everything that comes from there with =E2=80=9Cvmunix=E2=80= =9D (as if it >> came from the kernel).=20=20 > > Also, apparently syslogd uses the timestamp of "when it read the messages > out of /dev/kmsg" as syslog entry timestamp *although* /dev/kmsg contains= its > own timestamps (as offsets-from-bootup). Hrmmm... Yeah, we could teach Inetutils=E2=80=99s syslogd to interpret those timesta= mps, although that=E2=80=99s a Linux-specific thing so care must be taken. > According to the Linux kernel documentation the /dev/kmsg ring buffer is > specifically allowed to be used by user processes (although they must not > impersonate the kernel - if they try, the specified priority is ignored), > so we're in the clear there. Yeah but still. From syslogd=E2=80=99s viewpoint, you can only assume that these messages originate in the kernel. > Later on, we should use /dev/log and fall back to /dev/kmsg and > then again use /dev/log as it gets available etc. I'm not sure > how to do the synchronisation (from shepherd's point of view, > syslogd asynchronously reads from /dev/kmsg and puts the messages > into its output files - so if we write to /dev/kmsg, then to > /dev/log, then to /dev/kmsg, then to /dev/log, is the message order > guaranteed?) syslogd will read a batch of messages from /dev/kmsg when it starts, so the order is not really honored in this case. I think that=E2=80=99s OK th= ough, because we don=E2=80=99t expect users to keep stopping/starting syslogd. = :-) Thanks, Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#30498] [PATCH 0/3] Log to syslog whenever possible Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Mar 2018 15:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30498 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 30498@debbugs.gnu.org Cc: Danny Milosavljevic Received: via spool by 30498-submit@debbugs.gnu.org id=B30498.15204363412425 (code B ref 30498); Wed, 07 Mar 2018 15:26:02 +0000 Received: (at 30498) by debbugs.gnu.org; 7 Mar 2018 15:25:41 +0000 Received: from localhost ([127.0.0.1]:49687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etawn-0000d3-Cn for submit@debbugs.gnu.org; Wed, 07 Mar 2018 10:25:41 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:45764) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etawl-0000ct-13 for 30498@debbugs.gnu.org; Wed, 07 Mar 2018 10:25:39 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8F2D011FA3; Wed, 7 Mar 2018 16:25:38 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sjIA11yBukU5; Wed, 7 Mar 2018 16:25:37 +0100 (CET) Received: from ribbon (vpn-0-27.aquilenet.fr [IPv6:2a0c:e300:4:27::]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 352E611D05; Wed, 7 Mar 2018 16:25:37 +0100 (CET) From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <87371ea2jj.fsf@gnu.org> <20180307110454.17110-1-ludo@gnu.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 17 =?UTF-8?Q?Vent=C3=B4se?= an 226 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Wed, 07 Mar 2018 16:25:28 +0100 In-Reply-To: <20180307110454.17110-1-ludo@gnu.org> ("Ludovic \=\?utf-8\?Q\?Cou\?\= \=\?utf-8\?Q\?rt\=C3\=A8s\=22's\?\= message of "Wed, 7 Mar 2018 12:04:51 +0100") Message-ID: <871sgvsyaf.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Ludovic Court=C3=A8s skribis: > However! The downside is that messages upon shutdown written after > syslogd has been killed are lost: they go to /dev/kmsg, which goes to > the console at that point, but they=E2=80=99re not written anywhere. I should point out that this is already the case in shepherd master. Ludo=E2=80=99. From unknown Sun Jun 22 03:57:24 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Danny Milosavljevic Subject: bug#30498: closed (Re: [bug#30498] [PATCH 0/3] Log to syslog whenever possible) Message-ID: References: <87h8phtgtg.fsf@gnu.org> <20180217122035.1443-1-dannym@scratchpost.org> X-Gnu-PR-Message: they-closed 30498 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 30498@debbugs.gnu.org Date: Thu, 15 Mar 2018 17:01:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1521133262-10209-1" This is a multi-part message in MIME format... ------------=_1521133262-10209-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #30498: [PATCH shepherd] shepherd: If /dev/kmsg is writable, use it for log= ging. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 30498@debbugs.gnu.org. --=20 30498: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D30498 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1521133262-10209-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 30498-done) by debbugs.gnu.org; 15 Mar 2018 17:00:16 +0000 Received: from localhost ([127.0.0.1]:35339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewWEi-0002dM-EL for submit@debbugs.gnu.org; Thu, 15 Mar 2018 13:00:16 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:57372) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewWEg-0002dE-Su for 30498-done@debbugs.gnu.org; Thu, 15 Mar 2018 13:00:15 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 9F80912CBC; Thu, 15 Mar 2018 18:00:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P5VNHUySK7TK; Thu, 15 Mar 2018 18:00:12 +0100 (CET) Received: from ribbon (vpn-0-27.aquilenet.fr [IPv6:2a0c:e300:4:27::]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5EC7312CBA; Thu, 15 Mar 2018 18:00:12 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: 30498-done@debbugs.gnu.org Subject: Re: [bug#30498] [PATCH 0/3] Log to syslog whenever possible References: <87371ea2jj.fsf@gnu.org> <20180307110454.17110-1-ludo@gnu.org> Date: Thu, 15 Mar 2018 18:00:11 +0100 In-Reply-To: <20180307110454.17110-1-ludo@gnu.org> ("Ludovic \=\?utf-8\?Q\?Cou\?\= \=\?utf-8\?Q\?rt\=C3\=A8s\=22's\?\= message of "Wed, 7 Mar 2018 12:04:51 +0100") Message-ID: <87h8phtgtg.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30498-done Cc: Danny Milosavljevic X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s skribis: > Turn 'log-output-port' into a parameter. > Simplify 'make-shepherd-output-port'. > Use syslog for logging when running as root. Pushed! For the record, this can be tested on GuixSD by running =E2=80=9Cmake dist= =E2=80=9D in the Shepherd and then applying something like the patch below in Guix: --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm index ad31bc498..04cb69e1b 100644 --- a/gnu/packages/admin.scm +++ b/gnu/packages/admin.scm @@ -47,6 +47,7 @@ #:use-module (guix build-system perl) #:use-module (guix build-system python) #:use-module (guix build-system trivial) + #:use-module (guix gexp) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages check) @@ -159,16 +160,8 @@ and provides a \"top-like\" mode (monitoring).") (define-public shepherd (package (name "shepherd") - (version "0.3.2") - (source (origin - (method url-fetch) - (uri (string-append "ftp://alpha.gnu.org/gnu/dmd/shepherd-" - version ".tar.gz")) - (sha256 - (base32 - "174q1qg7yg6w1hfvlfv720hr6hid4h5xzw15y3ycfpspllzldhcb")) - (patches (search-patches "shepherd-close-fds.patch" - "shepherd-herd-status-sorted.patch")))) + (version "0.3.3") + (source (local-file "/data/src/shepherd/shepherd-0.3.2.tar.gz")) (build-system gnu-build-system) (arguments '(#:configure-flags '("--localstatedir=/var"))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQpMdWRv4oCZLg0K --=-=-=-- ------------=_1521133262-10209-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 17 Feb 2018 12:20:55 +0000 Received: from localhost ([127.0.0.1]:47555 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1U6-0000dn-OQ for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41801) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1en1U5-0000dc-Vx for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1en1Tz-0005ab-IF for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:48 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:58077) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1en1Tz-0005aX-F1 for submit@debbugs.gnu.org; Sat, 17 Feb 2018 07:20:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1en1Ty-0000Dl-7Y for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1en1Tv-0005Zd-2g for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:46 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:56608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1en1Tu-0005ZC-Nk for guix-patches@gnu.org; Sat, 17 Feb 2018 07:20:42 -0500 Received: from dayas.3.home (178.113.229.194.wireless.dyn.drei.com [178.113.229.194]) by dd26836.kasserver.com (Postfix) with ESMTPSA id AAEEC3360290; Sat, 17 Feb 2018 13:20:40 +0100 (CET) From: Danny Milosavljevic To: guix-patches@gnu.org Subject: [PATCH shepherd] shepherd: If /dev/kmsg is writable, use it for logging. Date: Sat, 17 Feb 2018 13:20:35 +0100 Message-Id: <20180217122035.1443-1-dannym@scratchpost.org> X-Mailer: git-send-email 2.15.1 Tags: patch X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit Cc: Danny Milosavljevic X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) * modules/shepherd.scm (main): If /dev/kmsg is used, don't log to console again - use only /dev/kmsg. * modules/shepherd/comm.scm (%current-logfile-date-format): New variable. (make-shepherd-output-port): Use it. Export. * modules/shepherd/support.scm (default-logfile-date-format): New variable. (default-logfile): Use /dev/kmsg if writable. (default-logfile-date-format): Drop duplicate timestamp. --- modules/shepherd.scm | 6 +++++- modules/shepherd/comm.scm | 11 ++++++----- modules/shepherd/support.scm | 11 ++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..2db56a1 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -141,8 +141,12 @@ ;; Enable logging as first action. (start-logging logfile) + (if (string=? logfile "/dev/kmsg") + ;; Prevent duplicate messages. + (set-current-output-port (%make-void-port "w"))) + ;; Send output to log and clients. - (set-current-output-port shepherd-output-port) + (set-current-output-port (make-shepherd-output-port (current-output-port))) ;; Start the 'root' service. (start root-service) diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..6cea6f0 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,7 +51,8 @@ start-logging stop-logging %current-client-socket - shepherd-output-port)) + %current-logfile-date-format + make-shepherd-output-port)) ;; Command for shepherd. @@ -200,6 +201,9 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) +(define %current-logfile-date-format + (make-parameter default-logfile-date-format)) + ;; We provide our own output mechanism, because we have certain ;; special needs; most importantly, we want to send output to herd ;; sometimes. @@ -228,7 +232,7 @@ on service '~a':") (let* ((log (lambda (x) (display x log-output-port))) (init-line (lambda () - (log (strftime "%Y-%m-%d %H:%M:%S " + (log (strftime (%current-logfile-date-format) (localtime (current-time))))))) (init-line) (for-each log (reverse buffer)) @@ -259,6 +263,3 @@ on service '~a':") ;; It's an output-only port. "w")) - -(define shepherd-output-port - (make-shepherd-output-port (current-output-port))) diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index bb01edc..585aef9 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -22,6 +22,7 @@ (define-module (shepherd support) #:use-module (shepherd config) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:export (call/ec caught-error assert @@ -43,6 +44,7 @@ user-homedir default-logfile + default-logfile-date-format default-config-file default-socket-dir default-socket-file @@ -282,9 +284,16 @@ TARGET should be a string representing a filepath + name." ;; Logfile. (define default-logfile (if (zero? (getuid)) - (string-append %localstatedir "/log/shepherd.log") + (if (access? "/dev/kmsg" W_OK) + "/dev/kmsg" + (string-append %localstatedir "/log/shepherd.log")) (string-append %user-config-dir "/shepherd.log"))) +(define default-logfile-date-format + (if (and (zero? (getuid)) (string=? default-logfile "/dev/kmsg")) + (format #f "shepherd[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the ------------=_1521133262-10209-1--