public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled
@ 2013-06-28  3:10 Peng Haitao
  2013-07-01  9:25 ` Wanlong Gao
  2013-07-01 14:12 ` chrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Peng Haitao @ 2013-06-28  3:10 UTC (permalink / raw)
  To: ltp-list

The case will check the /var/log/messages to see if there is a record of
any crontab activity, so make sure syslog daemon is enabld.

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
---
 testcases/commands/cron/cron_tests.sh | 62 +++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/testcases/commands/cron/cron_tests.sh b/testcases/commands/cron/cron_tests.sh
index b53a53a..2c70d1b 100644
--- a/testcases/commands/cron/cron_tests.sh
+++ b/testcases/commands/cron/cron_tests.sh
@@ -57,6 +57,60 @@ else
     LTPBIN=$LTPROOT/testcases/bin
 fi
 
+. cmdlib.sh
+FLAG=0
+SYSLOG_NAME=""
+
+if command -v systemctl >/dev/null 2>&1; then
+	HAVE_SYSTEMCTL=1
+else
+	HAVE_SYSTEMCTL=0
+fi
+
+if command -v syslogd >/dev/null 2>&1; then
+	SYSLOG_INIT_SCRIPT="/etc/init.d/syslog"
+elif command -v syslog-ng >/dev/null 2>&1; then
+	SYSLOG_INIT_SCRIPT="/etc/init.d/syslog-ng"
+elif command -v rsyslogd >/dev/null 2>&1; then
+	SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
+fi
+
+# make sure syslog daemon is enabled
+SVCNAME=$(basename $SYSLOG_INIT_SCRIPT)
+if [ $HAVE_SYSTEMCTL == 1 ]; then
+	for svc in "$SVCNAME" "sysklogd"
+	do
+		if systemctl is-enabled $svc.service >/dev/null 2>&1; then
+			SYSLOG_NAME=$svc
+			break
+		fi
+	done
+else
+	for SYSLOG_INIT_SCRIPT in "$SYSLOG_INIT_SCRIPT" "/etc/init.d/sysklogd"
+	do
+		if [ -x "$SYSLOG_INIT_SCRIPT" ]; then
+			SYSLOG_NAME=$SYSLOG_INIT_SCRIPT
+			break
+		fi
+	done
+fi
+
+if [ -n "$SYSLOG_NAME" ]; then
+	if [ $HAVE_SYSTEMCTL == 1 ]; then
+		status_daemon $SYSLOG_NAME
+		if [ $? -ne 0 ]; then
+			restart_daemon $SYSLOG_NAME
+			FLAG=1
+		fi
+	else
+		$SYSLOG_NAME status >/dev/null 2>&1
+		if [ $? -ne 0 ]; then
+			$SYSLOG_NAME restart >/dev/null 2>&1
+			FLAG=1
+		fi
+	fi
+fi
+
 # Set return code RC variable to 0, it will be set with a non-zero return code
 # in case of error. Set TFAILCNT to 0, increment if there occures a failure.
 
@@ -400,4 +454,12 @@ else
 	TFAILCNT=$(( $TFAILCNT+1 ))
 fi
 
+if [ $FLAG -eq 1 ]; then
+	if [ $HAVE_SYSTEMCTL == 1 ]; then
+		stop_daemon $SYSLOG_NAME
+	else
+		$SYSLOG_NAME stop >/dev/null 2>&1
+	fi
+fi
+
 exit $TFAILCNT
-- 
1.8.1.4


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled
  2013-06-28  3:10 [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled Peng Haitao
@ 2013-07-01  9:25 ` Wanlong Gao
  2013-07-01 14:12 ` chrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Wanlong Gao @ 2013-07-01  9:25 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

On 06/28/2013 11:10 AM, Peng Haitao wrote:
> The case will check the /var/log/messages to see if there is a record of
> any crontab activity, so make sure syslog daemon is enabld.
> 
> Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>

Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled
  2013-06-28  3:10 [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled Peng Haitao
  2013-07-01  9:25 ` Wanlong Gao
@ 2013-07-01 14:12 ` chrubis
       [not found]   ` <51D386E8.8090603@cn.fujitsu.com>
  1 sibling, 1 reply; 4+ messages in thread
From: chrubis @ 2013-07-01 14:12 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

Hi!
> +. cmdlib.sh
> +FLAG=0
> +SYSLOG_NAME=""
> +
> +if command -v systemctl >/dev/null 2>&1; then
> +	HAVE_SYSTEMCTL=1
> +else
> +	HAVE_SYSTEMCTL=0
> +fi
> +
> +if command -v syslogd >/dev/null 2>&1; then
> +	SYSLOG_INIT_SCRIPT="/etc/init.d/syslog"
> +elif command -v syslog-ng >/dev/null 2>&1; then
> +	SYSLOG_INIT_SCRIPT="/etc/init.d/syslog-ng"
> +elif command -v rsyslogd >/dev/null 2>&1; then
> +	SYSLOG_INIT_SCRIPT="/etc/init.d/rsyslog"
> +fi
> +
> +# make sure syslog daemon is enabled
> +SVCNAME=$(basename $SYSLOG_INIT_SCRIPT)
> +if [ $HAVE_SYSTEMCTL == 1 ]; then
> +	for svc in "$SVCNAME" "sysklogd"
> +	do
> +		if systemctl is-enabled $svc.service >/dev/null 2>&1; then
> +			SYSLOG_NAME=$svc
> +			break
> +		fi
> +	done
> +else
> +	for SYSLOG_INIT_SCRIPT in "$SYSLOG_INIT_SCRIPT" "/etc/init.d/sysklogd"
> +	do
> +		if [ -x "$SYSLOG_INIT_SCRIPT" ]; then
> +			SYSLOG_NAME=$SYSLOG_INIT_SCRIPT
> +			break
> +		fi
> +	done
> +fi
> +
> +if [ -n "$SYSLOG_NAME" ]; then
> +	if [ $HAVE_SYSTEMCTL == 1 ]; then
> +		status_daemon $SYSLOG_NAME
> +		if [ $? -ne 0 ]; then
> +			restart_daemon $SYSLOG_NAME
> +			FLAG=1
> +		fi
> +	else
> +		$SYSLOG_NAME status >/dev/null 2>&1
> +		if [ $? -ne 0 ]; then
> +			$SYSLOG_NAME restart >/dev/null 2>&1
> +			FLAG=1
> +		fi
> +	fi
> +fi
> +
>  # Set return code RC variable to 0, it will be set with a non-zero return code
>  # in case of error. Set TFAILCNT to 0, increment if there occures a failure.
>  
> @@ -400,4 +454,12 @@ else
>  	TFAILCNT=$(( $TFAILCNT+1 ))
>  fi
>  
> +if [ $FLAG -eq 1 ]; then
> +	if [ $HAVE_SYSTEMCTL == 1 ]; then
> +		stop_daemon $SYSLOG_NAME
> +	else
> +		$SYSLOG_NAME stop >/dev/null 2>&1
> +	fi
> +fi
> +

We have similar code to restart cron in cron/cron02 and to restart nscd
in sssd/sssd-libs.sh.

What about we create a short library with a common code to restart
system daemons? So that any new testcase would just need to source the
lib and call:

daemon_restart "cron"

or:

daemon_stop "syslog"

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled
       [not found]   ` <51D386E8.8090603@cn.fujitsu.com>
@ 2013-07-03 11:18     ` chrubis
  0 siblings, 0 replies; 4+ messages in thread
From: chrubis @ 2013-07-03 11:18 UTC (permalink / raw)
  To: Peng Haitao; +Cc: ltp-list

Hi!
> ...
> >> +if [ -n "$SYSLOG_NAME" ]; then
> >> +	if [ $HAVE_SYSTEMCTL == 1 ]; then
> >> +		status_daemon $SYSLOG_NAME
> >> +		if [ $? -ne 0 ]; then
> >> +			restart_daemon $SYSLOG_NAME
> >> +			FLAG=1
> >> +		fi
> ...
> >> +if [ $FLAG -eq 1 ]; then
> >> +	if [ $HAVE_SYSTEMCTL == 1 ]; then
> >> +		stop_daemon $SYSLOG_NAME
> >> +	else
> >> +		$SYSLOG_NAME stop >/dev/null 2>&1
> >> +	fi
> >> +fi
> >> +
> > 
> > We have similar code to restart cron in cron/cron02 and to restart nscd
> > in sssd/sssd-libs.sh.
> > 
> > What about we create a short library with a common code to restart
> > system daemons? So that any new testcase would just need to source the
> 
> A short library is in cmdlib.sh.
> stop_daemon, status_daemon and restart_daemon is used in the patch.

Then I do not understand why the patch adds systemctl detection
code to the cron_tests.sh. It is allready present in the cmdlib.sh

> The syslog daemon may be syslog, rsyslog, syslog-ng etc, 
> so I make the patch which is similar to syslog-lib.sh.

Which is why I object to the patch, it copies code from library to the
testcase, which is wrong in terms of longterm maintenance.

Ideal solution would be to move the syslog detection to the cmdlib.sh
and make a canonical name for syslog so that if you request to restart
the daemon in test with:

daemon_restart syslog

Everything is detected automatically, the syslog binary, systemd vs
system V init, etc. And everythig is kept in one file, no code
duplications.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-03 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-28  3:10 [LTP] [PATCH] cron_tests.sh: fix a bug of syslog daemon is disabled Peng Haitao
2013-07-01  9:25 ` Wanlong Gao
2013-07-01 14:12 ` chrubis
     [not found]   ` <51D386E8.8090603@cn.fujitsu.com>
2013-07-03 11:18     ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox