public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH] syslog-lib: support distros running systemd
Date: Tue, 17 Jan 2012 12:08:21 +0100	[thread overview]
Message-ID: <4F1556A5.9010604@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]


init.d/ scripts may not be available on distros
using systemd, for example Fedora16.

This patch is using 'systemctl' to restart syslog daemon
on distros running systemd. If systemctl is not available
it falls back to directly calling init script.

Also it drops few upstart TODO comments, current code
works OK with upstart (tested on RHEL6).

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
  testcases/kernel/syscalls/syslog/syslog-lib.sh |   40 
+++++++++++++----------
  1 files changed, 23 insertions(+), 17 deletions(-)



[-- Attachment #2: 0001-syslog-lib-support-distros-running-systemd.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]

diff --git a/testcases/kernel/syscalls/syslog/syslog-lib.sh b/testcases/kernel/syscalls/syslog/syslog-lib.sh
index 91a2e62..3d0c189 100755
--- a/testcases/kernel/syscalls/syslog/syslog-lib.sh
+++ b/testcases/kernel/syscalls/syslog/syslog-lib.sh
@@ -29,11 +29,15 @@ CONFIG_FILE=""
 # rsyslogd .conf specific args.
 RSYSLOG_CONFIG=
 
-# Command for syslog daemon.
-SYSLOG_COMMAND=
+# Command to restart syslog daemon.
+SYSLOG_RESTART_COMMAND=
 
-# Args to pass to $SYSLOG_COMMAND when restarting the daemon.
-SYSLOG_RESTART_COMMAND_ARGS=
+# running under systemd?
+if command -v systemctl >/dev/null 2>&1; then
+	HAVE_SYSTEMCTL=1
+else
+	HAVE_SYSTEMCTL=0
+fi
 
 # number of seconds to wait for another syslog test to complete
 WAIT_COUNT=60
@@ -82,31 +86,33 @@ setup()
 		CONFIG_FILE="/etc/rsyslog.conf"
 		SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
 		RSYSLOG_CONFIG='$ModLoad imuxsock.so'
-	#elif <detect-upstart-jobfile-here>; then
-		# TODO: upstart
 	else
 		tst_resm TCONF "couldn't find syslogd, syslog-ng, or rsyslogd"
 		cleanup	0
 	fi
 
-	if [ -z "$SYSLOG_INIT_SCRIPT" ]; then
-		# TODO: upstart
-		:
+	SVCNAME=$(basename $SYSLOG_INIT_SCRIPT)
+	if [ $HAVE_SYSTEMCTL == 1 ]; then
+		for svc in "$SVCNAME" "syslog"; do
+			if systemctl is-enabled $svc.service >/dev/null 2>&1; then
+				SYSLOG_RESTART_COMMAND="systemctl restart $svc.service"
+				break
+			fi
+		done
 	else
 		# Fallback to /etc/init.d/syslog if $SYSLOG_INIT_SCRIPT
 		# doesn't exist.
 		for SYSLOG_INIT_SCRIPT in "$SYSLOG_INIT_SCRIPT" "/etc/init.d/syslog"; do 
 			if [ -x "$SYSLOG_INIT_SCRIPT" ]; then
+				SYSLOG_RESTART_COMMAND="$SYSLOG_INIT_SCRIPT restart"
 				break
 			fi
 		done
-		if [ ! -x "$SYSLOG_INIT_SCRIPT" ]; then
-			tst_resm TBROK "$SYSLOG_INIT_SCRIPT - no such script"
-			cleanup 1
-		fi
+	fi
 
-		SYSLOG_COMMAND=$SYSLOG_INIT_SCRIPT
-		SYSLOG_RESTART_COMMAND_ARGS=restart
+	if [ -z "$SYSLOG_RESTART_COMMAND" ]; then
+		tst_resm TBROK "Don't know how to restart $SVCNAME"
+		cleanup 1
 	fi
 
 	# Back up configuration file
@@ -146,9 +152,9 @@ restart_syslog_daemon()
 		cleanup_command=$1
 	fi
 
-	tst_resm TINFO "restarting syslog daemon via $SYSLOG_COMMAND $SYSLOG_RESTART_COMMAND_ARGS"
+	tst_resm TINFO "restarting syslog daemon via $SYSLOG_RESTART_COMMAND"
 
-	if $SYSLOG_COMMAND $SYSLOG_RESTART_COMMAND_ARGS >/dev/null 2>&1; then
+	if $SYSLOG_RESTART_COMMAND >/dev/null 2>&1; then
 		# XXX: this really shouldn't exist; if *syslogd isn't ready
 		# once the restart directive has been issued, then it needs to
 		# be fixed.


[-- Attachment #3: Type: text/plain, Size: 381 bytes --]

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

             reply	other threads:[~2012-01-17 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-17 11:08 Jan Stancek [this message]
2012-01-25 15:27 ` [LTP] [PATCH] syslog-lib: support distros running systemd Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F1556A5.9010604@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox