]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Use systemd-cat for logging on systemd systems, if logfile is empty
authorHarald Hoyer <harald@redhat.com>
Fri, 19 Jul 2013 07:34:45 +0000 (09:34 +0200)
committerHarald Hoyer <harald@redhat.com>
Fri, 19 Jul 2013 07:34:45 +0000 (09:34 +0200)
dracut-logger.sh
dracut.conf.d/fedora.conf.example
dracut.sh
dracut.spec

index 9fa76d4afaa3292213a2e6cd005939be3b81c076..2e3c1ed8eee9a77db36697d71e22199ae546f5ca 100755 (executable)
@@ -117,24 +117,34 @@ dlog_init() {
     if [ -z "$fileloglvl" ]; then
         [ -w "$logfile" ] && fileloglvl=4 || fileloglvl=0
     elif (( $fileloglvl > 0 )); then
-        __oldumask=$(umask)
-        umask 0377
-        ! [ -e "$logfile" ] && >"$logfile"
-        umask $__oldumask
-        if [ -w "$logfile" -a -f "$logfile" ]; then
+        if [[ $logfile ]]; then
+            __oldumask=$(umask)
+            umask 0377
+            ! [ -e "$logfile" ] && >"$logfile"
+            umask $__oldumask
+            if [ -w "$logfile" -a -f "$logfile" ]; then
             # Mark new run in the log file
-            echo >>"$logfile"
-            if command -v date >/dev/null; then
-                echo "=== $(date) ===" >>"$logfile"
+                echo >>"$logfile"
+                if command -v date >/dev/null; then
+                    echo "=== $(date) ===" >>"$logfile"
+                else
+                    echo "===============================================" >>"$logfile"
+                fi
+                echo >>"$logfile"
             else
-                echo "===============================================" >>"$logfile"
-            fi
-            echo >>"$logfile"
-        else
             # We cannot log to file, so turn this facility off.
-            fileloglvl=0
-            ret=1
-            errmsg="'$logfile' is not a writable file"
+                fileloglvl=0
+                ret=1
+                errmsg="'$logfile' is not a writable file"
+            fi
+        fi
+        if type -P systemd-cat &>/dev/null && (( $UID  == 0 )) ; then
+            readonly _dlogdir="$(mktemp --tmpdir="$TMPDIR/" -d -t dracut-log.XXXXXX)"
+            readonly _systemdcatfile="$_dlogdir/systemd-cat"
+            mkfifo "$_systemdcatfile"
+            readonly _dlogfd=15
+            systemd-cat -t 'dracut' <"$_systemdcatfile" &
+            exec 15>"$_systemdcatfile"
         fi
     fi
 
@@ -306,15 +316,22 @@ _dlvl2syslvl() {
 _do_dlog() {
     local lvl="$1"; shift
     local lvlc=$(_lvl2char "$lvl") || return 0
-    local msg="$lvlc: $*"
+    local msg="$*"
+    local lmsg="$lvlc: $*"
 
     (( $lvl <= $stdloglvl )) && echo "$msg" >&2
     if (( $lvl <= $sysloglvl )); then
         logger -t "dracut[$$]" -p $(_lvl2syspri $lvl) "$msg"
     fi
+
     if (( $lvl <= $fileloglvl )) && [[ -w "$logfile" ]] && [[ -f "$logfile" ]]; then
-        echo "$msg" >>"$logfile"
+        echo "$lmsg" >>"$logfile"
+    fi
+
+    if (( $lvl <= $fileloglvl )) && [[ "$_dlogfd" ]]; then
+        echo "<$(_dlvl2syslvl $lvl)>$msg" >&$_dlogfd
     fi
+
     (( $lvl <= $kmsgloglvl )) && \
         echo "<$(_dlvl2syslvl $lvl)>dracut[$$] $msg" >/dev/kmsg
 }
index 37f45424c8c6337a9b6722866a197ab77e057b22..fd94e8389e9abdd2de92d2e7a9990aed2a56a16f 100644 (file)
@@ -5,8 +5,7 @@ i18n_vars="/etc/sysconfig/keyboard:KEYTABLE-KEYMAP /etc/sysconfig/i18n:SYSFONT-F
 i18n_default_font="latarcyrheb-sun16"
 omit_drivers+=' .*/fs/ocfs/.*  i2o_scsi'
 stdloglvl=3
-logfile=/var/log/dracut.log
-fileloglvl=6
+fileloglvl=5
 install_items+=" vi /etc/virc ps grep cat rm "
 prefix="/"
 systemdutildir=/usr/lib/systemd
index f2a680cb221ae631a0a4069091092f818a8ad2f4..8ccec177e920f70f2e1be8016c6b1da73415c6d2 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -683,7 +683,15 @@ if [[ $early_microcode = yes ]]; then
     }
 fi
 # clean up after ourselves no matter how we die.
-trap 'ret=$?;[[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; [[ $microcode_dir ]] && rm -Rf -- "$microcode_dir"; exit $ret; };' EXIT
+trap '
+    ret=$?;
+    [[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";
+    [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
+    [[ $keep ]] && echo "Not removing $microcode_dir." >&2 || { [[ $microcode_dir ]] && rm -Rf -- "$microcode_dir"; };
+    [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
+    exit $ret;
+    ' EXIT
+
 # clean up after ourselves no matter how we die.
 trap 'exit 1;' SIGINT
 
@@ -761,7 +769,7 @@ for ((i=0; i < ${#dracut_args[@]}; i++)); do
         dracut_args[$i]="\"${dracut_args[$i]}\""
         #" keep vim happy
 done
-ddebug "Executing: $0 ${dracut_args[@]}"
+dinfo "Executing: $0 ${dracut_args[@]}"
 
 [[ $do_list = yes ]] && {
     for mod in $dracutbasedir/modules.d/*; do
@@ -1167,11 +1175,6 @@ if [[ $kernel_only != yes ]]; then
     fi
 fi
 
-if (( maxloglvl >= 5 )); then
-    ddebug "Listing sizes of included files:"
-    du -c "$initdir" | sort -n | ddebug
-fi
-
 PRELINK_BIN="$(command -v prelink)"
 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
     if [[ $DRACUT_FIPS_MODE ]]; then
@@ -1258,6 +1261,7 @@ if [[ $early_microcode = yes ]]; then
     done
     (cd "$microcode_dir/d"; find . | cpio -o -H newc --quiet >../ucode.cpio)
 fi
+
 rm -f -- "$outfile"
 dinfo "*** Creating image file ***"
 if [[ $early_microcode = yes ]]; then
@@ -1272,7 +1276,8 @@ fi
 mv -- "$outfile.$$" "$outfile"
 dinfo "*** Creating image file done ***"
 
-dinfo "Wrote $outfile:"
-dinfo "$(ls -l "$outfile")"
+if (( maxloglvl >= 5 )); then
+    lsinitrd "$outfile"| ddebug
+fi
 
 exit 0
index 6583f6aeca8a3e9291e0271a1ac29a60c3189309..a27563a5c0ac9f7ee72625536f36a5d4bfc9f6fb 100644 (file)
@@ -269,9 +269,6 @@ echo 'hostonly="no"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/02-generic-i
 echo 'dracut_rescue_image="yes"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/02-rescue.conf
 %endif
 
-mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
-install -m 0644 dracut.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/dracut_log
-
 # create compat symlink
 mkdir -p $RPM_BUILD_ROOT/sbin
 ln -s /usr/bin/dracut $RPM_BUILD_ROOT/sbin/dracut
@@ -367,7 +364,6 @@ rm -rf -- $RPM_BUILD_ROOT
 %{dracutlibdir}/modules.d/99fs-lib
 %{dracutlibdir}/modules.d/99img-lib
 %{dracutlibdir}/modules.d/99shutdown
-%config(noreplace) %{_sysconfdir}/logrotate.d/dracut_log
 %attr(0644,root,root) %ghost %config(missingok,noreplace) %{_localstatedir}/log/dracut.log
 %dir %{_sharedstatedir}/initramfs
 %if %{defined _unitdir}