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 <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
This commit is contained in:
Michael Meffie 2024-08-16 09:53:12 -04:00
parent bd2a7530ad
commit 6c1676c515

View File

@ -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();