Skip to content

logger: Make it easier to attach a logger to a shell script

Simon McVittie requested to merge wip/task461 into main
  • !721 (merged)

  • env-overlay test: Exercise environment variables with strange names —applied

  • utils: Add a function to check for syntactically valid shell variables —applied

  • env-overlay: Add and test _srt_env_overlay_to_shell() —applied

  • logger: Use a SrtEnvOverlay to modify the environment

    This will let us convert the environment modifications into other formats, for example a series of shell export statements to be eval'd.

  • logger: Emit environment variables in --sh-syntax

    This will make it easier to set the correct environment variables when attaching it to a shell script like steam.sh.

  • test-logger: Demonstrate logging from a bash script

    Unlike the current logger integration in steam.sh, this uses --background to avoid conflicts with subreapers (steamrt/tasks#460), and --sh-syntax to set environment variables (steamrt/tasks#461).

    The unit test doesn't assert that the output includes the desired environment variables, because we can't assume that the Journal is always available in our test environments, and it's non-trivial to mock up a terminal file descriptor - but when run on a system with a working Journal, it does correctly set SRT_LOGGER_USE_JOURNAL=1.

    steamrt/tasks#461

  • logger: Install srt-logger in ${libexecdir}

    This will make it easier to locate within a $STEAM_RUNTIME.

  • srt-logger --mkfifo: New CLI tool entry point

    If we could rely on mktemp -d being fully portable, then we could do this from shell script, but we probably can't rely on that.

    Similarly, we probably can't rely on $XDG_RUNTIME_DIR being set, or $TMPDIR being a filesystem that is able to hold fifo objects.

    This has the same statically-linked dependencies as srt-logger, so make it part of the srt-logger binary to avoid wasting space.

  • logger-0.bash: Add a convenience bash binding for srt-logger

    There are a few places where we want to log the output of a shell script without having to execute srt-logger wrapped around a second shell script as a subprocess. steam.sh and steamwebhelper.sh already use srt-logger, and bin_steam.sh might follow soon.

    To achieve this, we need to use either a bash coprocess or at least one fifo, because process substitution only creates a one-way pipe. Currently all the scripts where we want to use the logger are bash scripts (as opposed to pure POSIX sh) so we can still take advantage of other bashisms: process substitution and named redirections.

    Even when using those bash features, the synchronization required between the logger and its parent is non-trivial, so putting it in a shell library makes it easier to achieve.

/cc @refi64 @denittis

Edited by Simon McVittie

Merge request reports

Loading