[Ovirt-devel] [PATCH node] Moved network configuration work files to a temporary directory.
Darryl L. Pierce
dpierce at redhat.com
Fri Nov 14 21:41:35 UTC 2008
Added a trap call to ensure that the work directory is removed after
the script exits.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
scripts/ovirt-config-networking | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 2f8363c..d2bfc45 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -3,6 +3,13 @@
# Iterates over the list of network devices on the node and prompts the user
# to configure each.
+WORKDIR=$(mktemp -d) || exit 1
+
+# Remove $WORKDIR upon interrupt (and HUP, PIPE, TERM) and upon normal
+# termination, being careful not to change the exit status.
+trap '__st=$?; rm -rf "$WORKDIR"; exit $__st' 0
+trap 'exit $?' 1 2 13 15
+
CONFIG_FILE_ROOT="/file/etc/sysconfig/network-scripts/ifcfg"
CONFIG_LOG_FILE="/var/log/ovirt-network-setup.log"
@@ -10,8 +17,8 @@ function configure_interface
{
NIC=$1
BRIDGE=ovirtbr`echo $NIC | cut -b4-`
- IF_FILENAME="/var/tmp/augtool-$NIC"
- BR_FILENAME="/var/tmp/augtool-$BRIDGE"
+ IF_FILENAME="$WORKDIR/augtool-$NIC"
+ BR_FILENAME="$WORKDIR/augtool-$BRIDGE"
printf "\nConfigure $BRIDGE for use by $NIC..\n\n"
@@ -70,10 +77,6 @@ function setup_menu
PS3="Please select a network interface to configure:"
}
-# clean up any left over configurations
-rm -f /var/tmp/config-augtool
-rm -f /var/tmp/augtool-*
-
setup_menu
select NIC in $NICS
@@ -88,10 +91,10 @@ done
# Merge together all generated files and run augtool
-cat /var/tmp/augtool-* > /var/tmp/config-augtool
-printf "save\n" >> /var/tmp/config-augtool
{
-augtool < /var/tmp/config-augtool
+config="$WORKDIR"/config-augtool
+{ cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
+&& augtool < "$WORKDIR"/config-augtool
+
service network restart
} > $CONFIG_LOG_FILE 2>> $CONFIG_LOG_FILE
-
--
1.5.6.5
More information about the ovirt-devel
mailing list