From e936dcde086c84c08102f821c99381005acd272a Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Wed, 31 Jul 2013 22:15:05 +0200
Subject: qga fsfreeze main hook: adapt to RHEL-7 (RH only)
RH-Author: Laszlo Ersek <lersek@redhat.com>
Message-id: <1375308906-23405-3-git-send-email-lersek@redhat.com>
Patchwork-id: 52885
O-Subject: [RHEL-7 qemu-kvm PATCH v3 2/3] qga fsfreeze main hook: adapt to RHEL-7 (RH only)
Bugzilla: 969942
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=969942
LOGFILE should look like it does on RHEL-6.
The main fsfreeze script should process hook files like systemd does
[Paolo].
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
diff --git a/scripts/qemu-guest-agent/fsfreeze-hook b/scripts/qemu-guest-agent/fsfreeze-hook
index c27b29f..45514fa 100755
--- a/scripts/qemu-guest-agent/fsfreeze-hook
+++ b/scripts/qemu-guest-agent/fsfreeze-hook
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# This script is executed when a guest agent receives fsfreeze-freeze and
# fsfreeze-thaw command, if it is specified in --fsfreeze-hook (-F)
@@ -7,8 +7,7 @@
# "freeze" argument before the filesystem is frozen. And for fsfreeze-thaw
# request, it is issued with "thaw" argument after filesystem is thawed.
-LOGFILE=/var/log/qga-fsfreeze-hook.log
-FSFREEZE_D=$(dirname -- "$0")/fsfreeze-hook.d
+LOGFILE=/var/log/qemu-ga.fsfreeze-hook.log
# Check whether file $1 is a backup or rpm-generated file and should be ignored
is_ignored_file() {
@@ -19,15 +18,26 @@ is_ignored_file() {
return 1
}
-# Iterate executables in directory "fsfreeze-hook.d" with the specified args
-[ ! -d "$FSFREEZE_D" ] && exit 0
-for file in "$FSFREEZE_D"/* ; do
- is_ignored_file "$file" && continue
- [ -x "$file" ] || continue
- printf "$(date): execute $file $@\n" >>$LOGFILE
- "$file" "$@" >>$LOGFILE 2>&1
+shopt -s nullglob
+RELPATH=qemu-ga/fsfreeze-hook.d
+
+for DIR in lib etc run; do
+ for FILE in /"$DIR/$RELPATH"/*; do
+ if is_ignored_file "$FILE" || ! [ -x "$FILE" ]; then
+ continue
+ fi
+ BNAME=$(basename -- "$FILE")
+ if ( [ lib = "$DIR" ] && ( [ -e /etc/"$RELPATH/$BNAME" ] ||
+ [ -e /run/"$RELPATH/$BNAME" ] ) ) ||
+ ( [ etc = "$DIR" ] && ( [ -e /run/"$RELPATH/$BNAME" ] ) ); then
+ continue
+ fi
+
+ printf "$(date): execute $FILE $@\n" >>$LOGFILE
+ "$FILE" "$@" >>$LOGFILE 2>&1
STATUS=$?
- printf "$(date): $file finished with status=$STATUS\n" >>$LOGFILE
+ printf "$(date): $FILE finished with status=$STATUS\n" >>$LOGFILE
+ done
done
exit 0