From 6c1676c5154bf6cd45fee8721225f82fcb35b2db Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Fri, 16 Aug 2024 09:53:12 -0400 Subject: [PATCH] afsd: Unbuffer output afsd prints output to the stdio streams. Usually afsd is run by an init script or systemd unit, so the output is not directed to the terminal and the stdio streams are buffered. When afsd forks child processes, the forked processes inherit the buffered streams and this causes the output to be duplicated in the child proceses. For example, when running afsd from systemd, the journal contains duplicated output messages: # systemctl start openafs-client ... ... systemd[1]: Starting openafs-client.service - OpenAFS Client Service... ... afsd[292192]: afsd: All AFS daemons started. ... afsd[292170]: afsd: All AFS daemons started. ... fedora systemd[1]: Started openafs-client.service - OpenAFS Client Service. To avoid the duplicated messages, and to ensure output is captured in the event of a crash, set the stdout and stderr streams to be unbuffered using setvbuf() when the afsd process starts. Thanks to Mark Vitale for diagnosing this issue and to Andrew Deason for suggesting the use of setvbuf() to set the stream buffering. Change-Id: I57faac38f6667d431557793ce06a11b7f390a414 Reviewed-on: https://gerrit.openafs.org/15829 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk Reviewed-by: Cheyenne Wills --- src/afsd/afsd_kernel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index 1de54d50be..ad4e15af07 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -656,6 +656,9 @@ main(int argc, char **argv) { int code; + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + afsd_init_syscall_opcodes(); afsd_init();