Skip to content

Commit

Permalink
Use FIFO's in case stdout/stderr are unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanformigoni committed Feb 24, 2024
1 parent 0bd1ad9 commit 6501730
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/scripts/_boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,30 @@ export FIM_COMPRESSION_DIRS="${FIM_COMPRESSION_DIRS:-/usr /opt}"
export FIM_STREAM="${FIM_DEBUG:+/dev/stdout}"
export FIM_STREAM="${FIM_STREAM:-/dev/null}"

# FIFO config
export FIM_FIFO="${FIM_FIFO:-1}"

# Setup daemon to unmount filesystems on exit
chmod +x "$FIM_FPATH_KILLER"
nohup "$FIM_FPATH_KILLER" &>/dev/null & disown

# Check for stdout/stderr
if ! test -t 1 || ! test 2; then
notify-send "Using custom stdout/stderr to ${FIM_DIR_MOUNT}.log" &>"$FIM_STREAM" || true
exec 1> >(while IFS= read -r line; do echo "$line" | tee -a "${FIM_DIR_MOUNT}.log"; done)
exec 2> >(while IFS= read -r line; do echo "$line" | tee -a "${FIM_DIR_MOUNT}.log" >&2; done)
if ! { test -t 1 && test -t 2; } && [[ "$FIM_FIFO" -eq 1 ]]; then
notify-send "Using custom stdout/stderr" &>/dev/null || true

mkfifo "${FIM_DIR_MOUNT}.stdout.pipe"
mkfifo "${FIM_DIR_MOUNT}.stderr.pipe"

dd if="${FIM_DIR_MOUNT}.stdout.pipe" of="${FIM_DIR_MOUNT}.stdout.log" bs=64k &
dd if="${FIM_DIR_MOUNT}.stderr.pipe" of="${FIM_DIR_MOUNT}.stderr.log" bs=64k &

exec 3>"${FIM_DIR_MOUNT}.stdout.pipe"
exec 4>"${FIM_DIR_MOUNT}.stderr.pipe"

exec 1>&3
exec 2>&4

export FIM_STREAM="${FIM_DIR_MOUNT}.stdout.pipe"
fi

# Overlayfs filesystems mounts
Expand Down Expand Up @@ -175,6 +194,7 @@ function _re_mount()
# $* = Termination message
function _die()
{
set +e
# Force debug message
[ -z "$*" ] || FIM_DEBUG=1 _msg "$*"
# Signal exit to killer
Expand Down Expand Up @@ -1343,10 +1363,6 @@ function _main()
"mke2fs" "lsof"
)

# Setup daemon to unmount filesystems on exit
chmod +x "$FIM_FPATH_KILLER"
nohup "$FIM_FPATH_KILLER" &>/dev/null & disown

# Copy static binaries
_copy_tools "${ext_tools[@]}"

Expand Down

0 comments on commit 6501730

Please sign in to comment.