[Pm-utils] [PATCH] Logging infrastructure
Stefan Seyfried
seife at suse.de
Fri Oct 20 06:54:48 PDT 2006
Hi,
It turned out to be pretty trivial. Now just stdout and stderr get redirected:
into the logfile. If somebody does not like that, he can just set the logfile
to /dev/null.
If you want to debug the stuff by running it manually, just set LOGFILE="".
This patch alone does not implement all the needed logging, i just put in a
few echos, those are more intended as examples, but in the hooks it is now
trivial to log: just do _not_ redirect all the messages to /dev/null, and
voila, we will have the output of the service start and stop scripts and lots
of other stuff in the log in case something fails.
Is this an acceptable idea? I explicitly went for the "as simple as possible"
approach, which also makes it trivial for hook writers to use it. All the
alternatives (a log() function or something like that) would have been more
complicated to use IMO.
I also removed all those "rm /var/run/pm-suspend" lines, since it does not
hurt to let this file lay around until the next suspend (of course it is
still deleted then before starting) and it also might contain various hints
on what went wrong.
Index: pm/functions
===================================================================
RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
retrieving revision 1.22
diff -u -p -r1.22 functions
--- pm/functions 11 Oct 2006 22:49:27 -0000 1.22
+++ pm/functions 20 Oct 2006 13:47:40 -0000
@@ -5,14 +5,16 @@ export PATH=/sbin:/usr/sbin:/bin:/usr/bi
# default values go here
HIBERNATE_RESUME_POST_VIDEO=no
SUSPEND_MODULES=""
+LOGFILE=/var/log/pm-suspend.log
[ -f /etc/pm/config ] && . /etc/pm/config
# export them all here
export HIBERNATE_RESUME_POST_VIDEO
export SUSPEND_MODULES
+export LOGFILE
-GLOBAL_CONFIG_VARIABLES="HIBERNATE_RESUME_POST_VIDEO SUSPEND_MODULES"
+GLOBAL_CONFIG_VARIABLES="HIBERNATE_RESUME_POST_VIDEO SUSPEND_MODULES LOGFILE"
source_configs()
{
@@ -49,7 +51,6 @@ take_suspend_lock()
remove_suspend_lock()
{
- rm -f /var/run/pm-suspend
chvt 1
chvt $VT
openvt -- sh -c "usleep $1 ; rm -f /.suspended >/dev/null 2>&1 0<&1" >/dev/null 2>&1 0<&1 &
@@ -60,7 +61,8 @@ run_hooks()
[ -z "$1" ] && return 0
[ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
- rm -f /var/run/pm-suspend
+
+ echo "running $1 hooks:"
files="/etc/pm/hooks/*[^~]"
if [ "$2" = "reverse" ]; then
@@ -69,11 +71,17 @@ run_hooks()
while [ "$filen" -gt 0 ]; do
let filen--
file="${filea[$filen]}"
- [ -x $file ] && $file $1
+ if [ -x $file ]; then
+ echo "$i"
+ $file $1
+ fi
done
else
for file in $files ; do
- [ -x $file ] && $file $1
+ if [ -x $file ]; then
+ echo "$i"
+ $file $1
+ fi
done
fi
}
@@ -99,6 +107,8 @@ get_power_status()
pm_main()
{
+ [ -n "$LOGFILE" ] && ![[ "$LOGFILE" =~ "^/dev/" ] && rm -f $LOGFILE
+ [ -n "$LOGFILE" ] && exec > $LOGFILE 2>&1
take_suspend_lock || exit 1
run_hooks "$1"
sync ; sync ; sync
--
Stefan Seyfried
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."
More information about the Pm-utils
mailing list