#!/bin/bash
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-# ex: ts=8 sw=4 et filetype=sh
#
# logging faciality module for dracut both at build- and boot-time
#
fi
fi
+ if (( $UID != 0 )); then
+ kmsgloglvl=0
+ sysloglvl=0
+ fi
+
if (( $sysloglvl > 0 )); then
- if [[ -d /run/systemd/journal ]] && type -P systemd-cat &>/dev/null && (( $UID == 0 )) ; then
- readonly _dlogdir="$(mktemp --tmpdir="$TMPDIR/" -d -t dracut-log.XXXXXX)"
- readonly _systemdcatfile="$_dlogdir/systemd-cat"
+ if [[ -d /run/systemd/journal ]] \
+ && type -P systemd-cat &>/dev/null \
+ && systemctl --quiet is-active systemd-journald.socket &>/dev/null \
+ && { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then
+ readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat"
mkfifo "$_systemdcatfile"
readonly _dlogfd=15
- systemd-cat -t 'dracut' <"$_systemdcatfile" &
+ systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" &
exec 15>"$_systemdcatfile"
elif ! [ -S /dev/log -a -w /dev/log ] || ! command -v logger >/dev/null; then
# We cannot log to syslog, so turn this facility off.
+ kmsgloglvl=$sysloglvl
sysloglvl=0
ret=1
errmsg="No '/dev/log' or 'logger' included for syslog logging"
# Conversion is done as follows:
#
# <tt>
-# FATAL(1) -> LOG_EMERG (0)
+# none -> LOG_EMERG (0)
# none -> LOG_ALERT (1)
-# none -> LOG_CRIT (2)
+# FATAL(1) -> LOG_CRIT (2)
# ERROR(2) -> LOG_ERR (3)
# WARN(3) -> LOG_WARNING (4)
# none -> LOG_NOTICE (5)
local lvl
case "$1" in
- 1) lvl=0;;
+ 1) lvl=2;;
2) lvl=3;;
3) lvl=4;;
4) lvl=6;;
local msg="$*"
local lmsg="$lvlc: $*"
- (( $lvl <= $stdloglvl )) && echo "$msg" >&2
+ (( $lvl <= $stdloglvl )) && printf -- 'dracut: %s\n' "$msg" >&2
if (( $lvl <= $sysloglvl )); then
if [[ "$_dlogfd" ]]; then
- echo "<$(_dlvl2syslvl $lvl)>$msg" >&$_dlogfd
+ printf -- "<%s>%s\n" "$(($(_dlvl2syslvl $lvl) & 7))" "$msg" >&$_dlogfd
else
- logger -t "dracut[$$]" -p $(_lvl2syspri $lvl) "$msg"
+ logger -t "dracut[$$]" -p $(_lvl2syspri $lvl) -- "$msg"
fi
fi
if (( $# > 1 )); then
_do_dlog "$@"
else
- while read line; do
+ while read line || [ -n "$line" ]; do
_do_dlog "$1" "$line"
done
fi