[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 02/05: shepherd: Open log file as O_CLOEXEC.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 02/05: shepherd: Open log file as O_CLOEXEC. |
Date: |
Mon, 29 Aug 2022 11:18:08 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit fc7735f6a74e9f2bb07fdeed89f3aedd04d8ef4b
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Aug 29 17:04:05 2022 +0200
shepherd: Open log file as O_CLOEXEC.
* modules/shepherd/support.scm (buffering): New procedure.
* modules/shepherd.scm (main): Define 'log-flags'. Open log file with
'open' and LOG-FLAGS.
---
modules/shepherd.scm | 10 ++++++++--
modules/shepherd/support.scm | 6 ++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 9fbed1b..860fd30 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -253,6 +253,10 @@ already ~a threads running, disabling 'signalfd' support")
;; the signal thread.
(maybe-signal-port %precious-signals))
+ (define log-flags
+ ;; Flags for 'open' when opening the log file.
+ (logior O_CREAT O_APPEND O_WRONLY O_CLOEXEC))
+
(initialize-cli)
(let ((config-file #f)
@@ -335,11 +339,13 @@ already ~a threads running, disabling 'signalfd' support")
;; Enable logging as first action.
(parameterize ((log-output-port
(cond (logfile
- (open-file logfile "al"))
+ (buffering (open logfile log-flags)
+ 'line))
((zero? (getuid))
(syslog-output-port))
(else
- (open-file (user-default-log-file) "al"))))
+ (buffering (open (user-default-log-file) log-flags)
+ 'line))))
(%current-logfile-date-format
(if (and (not logfile) (zero? (getuid)))
(format #f "shepherd[~d]: " (getpid))
diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm
index a1f9d75..36be3ff 100644
--- a/modules/shepherd/support.scm
+++ b/modules/shepherd/support.scm
@@ -28,6 +28,7 @@
assert
label
+ buffering
catch-system-error
with-system-error-handling
with-atomic-file-output
@@ -94,6 +95,11 @@
(letrec ((NAME PROC))
(apply NAME args))))
+(define (buffering port type . args)
+ "Return PORT after changing its buffering to TYPE and ARGS."
+ (apply setvbuf port type args)
+ port)
+
;; Evaluate `EXPR ...' until a system error occurs, then skip the
;; remaining code.
(define-syntax-rule (catch-system-error EXPR ...)