]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdcheck: log to stderr from systemd units
authorMartin Wilck <mwilck@suse.com>
Thu, 14 Aug 2025 19:14:21 +0000 (21:14 +0200)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Tue, 4 Nov 2025 07:51:28 +0000 (08:51 +0100)
If the script is run from systemd, simply writing to stderr will
create more concise output. Otherwise, use logger like before.

Use the same logic for other messages printed by the script during
runtime, except for error messages related to the invocation.

Signed-off-by: Martin Wilck <mwilck@suse.com>
misc/mdcheck

index 5ea26cdfaf2def47c9dcefd011b797b425b21a00..b49279848ba0c5bedbcee8b6fe6de3d80f570299 100644 (file)
 # To support '--continue', arrays are identified by UUID and the 'sync_completed'
 # value is stored  in /var/lib/mdcheck/$UUID
 
+# If the script is run from systemd, simply write to the journal on stderr.
+# Otherwise, use logger.
+log() {
+    if [[ "$INVOCATION_ID" ]]; then
+           echo "$@" >&2
+    else
+           logger -p daemon.info "mdcheck: $*"
+    fi
+}
+
 # get device name from sysfs
 devname() {
     local dev
@@ -88,7 +98,7 @@ cleanup() {
        fi
        echo idle > $sys/md/sync_action
        cat $sys/md/sync_min > $fl
-       logger -p daemon.info pause checking $dev at `cat $fl`
+       log pause checking $dev at `cat $fl`
     done
     rm -f "$tmp"
 }
@@ -119,14 +129,14 @@ do
        if [ -z "$cont" ]
        then
                start=0
-               logger -p daemon.info mdcheck start checking $dev
+               log start checking $dev
        elif [ -z "$MD_UUID" -o ! -f "$fl" ]
        then
                # Nothing to continue here
                continue
        else
                start=`cat "$fl"`
-               logger -p daemon.info mdcheck continue checking $dev from $start
+               log continue checking $dev from $start
        fi
 
        : "$((cnt+=1))"
@@ -156,7 +166,7 @@ do
 
                if [ "`cat $sys/md/sync_action`" != 'check' ]
                then
-                       logger -p daemon.info mdcheck finished checking $dev
+                       log finished checking $dev
                        eval MD_${i}_fl=
                        rm -f $fl
                        continue;