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