Subject: update var directory usage
From: Mike Galbraith <mgalbraith@suse.de>
Date: 2011-11-24 07:07:26 UTC
References: bnc#714625

Don't use /var/lock on systemd equipped releases.

Signed-off-by: Mike Galbraith <mgalbraith@suse.de>
---
 ibm-prtm/ibm-prtm |   29 ++++++++++++++++++++++++-----
 rt-sshd/rt-sshd   |   39 +++++++++++++++++++++++++++++----------
 2 files changed, 53 insertions(+), 15 deletions(-)

--- a/ibm-prtm/ibm-prtm
+++ b/ibm-prtm/ibm-prtm
@@ -22,7 +22,26 @@ RETVAL=0
 prog="ibm-prtmd"
 IBM_PRTMD="/usr/sbin/$prog"
 NAME="IBM Premium Real-Time Daemon"
-PIDFILE="/var/run/ibm-prtmd.pid"
+
+# Make the package capable of dealing with various [open]SUSE releases
+# including those running systemd.
+if [ -d /var/run ]; then
+   rundir=/var/run
+else
+   rundir=/run
+fi
+
+# /var/lock is exclusively for device locks in newer releases, in which
+# case we use $rundir for both pid and lock files.  If the legacy dir
+# exists, use that.
+if [ -d /var/lock/subsys ]; then
+   lockdir=/var/lock/subsys
+else
+   lockdir=$rundir
+fi
+
+PIDFILE="$rundir/$prog.pid"
+LOCKFILE="$lockdir/$prog.lock"
 
 log_msg() {
 	local FLAGS=""
@@ -89,13 +108,13 @@ start() {
 		#$prog failed to start undo state
 		echo 0 > /sys/devices/system/ibm_rtl/state
 		set_bmc_mode 1
-		rm -f /var/lock/subsys/$prog
+		rm -f $LOCKFILE
 		return 1
 	else
 		log_success_msg
 		log_msg "System Management Interrupts have been disabled to"
 		log_msg "allow this system to run in Real-Time Mode."
-		touch /var/lock/subsys/$prog
+		touch $LOCKFILE
 		return 0
 	fi
 }
@@ -110,7 +129,7 @@ stop() {
 	$IBM_PRTMD -k
 	RETVAL=$?
 	if [ $RETVAL -eq 0 ]; then
-		rm -f /var/lock/subsys/$prog
+		rm -f $LOCKFILE
 		log_success_msg
 	else
 		log_failure_msg
@@ -148,7 +167,7 @@ case "$1" in
 	RETVAL=$?
 	;;
   condrestart)
-	if [ -f /var/lock/subsys/$prog ]; then
+	if [ -f $LOCKFILE]; then
 		stop
 		start
 		RETVAL=$?
--- a/rt-sshd/rt-sshd
+++ b/rt-sshd/rt-sshd
@@ -31,13 +31,32 @@
 RETVAL=0
 prog="rt-sshd"
 
+# Make the package capable of dealing with various [open]SUSE releases
+# including those running systemd.
+if [ -d /var/run ]; then
+   rundir=/var/run
+else
+   rundir=/run
+fi
+
+# /var/lock is exclusively for device locks in newer releases, in which
+# case we use $rundir for both pid and lock files.  If the legacy dir
+# exists, use that.
+if [ -d /var/lock/subsys ]; then
+   lockdir=/var/lock/subsys
+else
+   lockdir=$rundir
+fi
+
+PIDFILE="$rundir/$prog.pid"
+LOCKFILE="$lockdir/$prog.lock"
+
 # Some functions to make the below more readable
 KEYGEN=/usr/bin/ssh-keygen
 SSHD=/usr/sbin/sshd
 RSA1_KEY=/etc/ssh/ssh_host_key
 RSA_KEY=/etc/ssh/ssh_host_rsa_key
 DSA_KEY=/etc/ssh/ssh_host_dsa_key
-PID_FILE=/var/run/sshd.pid
 
 success() {
 	echo $0: success $*
@@ -124,19 +143,19 @@ start()
 	do_dsa_keygen
 
 	echo -n $"Starting $prog:"
-	chrt -f 99 $SSHD $OPTIONS -p 9988 -o PidFile=/var/run/rt-sshd.pid -o UseDNS=no && success || failure
+	chrt -f 99 $SSHD $OPTIONS -p 9988 -o PidFile=$PIDFILE -o UseDNS=no && success || failure
 	RETVAL=$?
-	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/rt-sshd
+	[ "$RETVAL" = 0 ] && touch $LOCKFILE
 	echo
 }
 
 stop()
 {
-	if [ -f /var/run/rt-sshd.pid ]; then
+	if [ -f "$PIDFILE" ]; then
 	    echo -n $"Stopping $prog: "
-	    kill -TERM `cat /var/run/rt-sshd.pid`
+	    kill -TERM `cat $PIDFILE`
 	    RETVAL=$?
-	    [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/rt-sshd && success || failure
+	    [ "$RETVAL" = 0 ] && rm -f $LOCKFILE && success || failure
 	    echo
 	else
 	    echo "No pid file found while trying to stop rt-sshd"
@@ -145,11 +164,11 @@ stop()
 
 reload()
 {
-	if [ -f /var/run/rt-sshd.pid ]; then
+	if [ -f "$PIDFILE" ]; then
 	    echo -n $"Reloading $prog: "
-	    kill -HUP `cat /var/run/rt-sshd.pid`
+	    kill -HUP `cat $PIDFILE`
 	    RETVAL=$?
-	    [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/rt-sshd && success || failure
+	    [ "$RETVAL" = 0 ] && rm -f $LOCKFILE && success || failure
 	    echo "done"
 	else
 	    echo "No pid file found while trying to stop rt-sshd"
@@ -171,7 +190,7 @@ case "$1" in
 		reload
 		;;
 	condrestart)
-		if [ -f /var/lock/subsys/rt-sshd ] ; then
+		if [ -f "$LOCKFILE" ] ; then
 			do_restart_sanity_check
 			if [ "$RETVAL" = 0 ] ; then
 				stop
