[Pm-utils] [PATCH] Logging infrastructure

Peter Jones pjones at redhat.com
Mon Oct 30 07:26:46 PST 2006


On Mon, 2006-10-30 at 10:29 +0100, Stefan Seyfried wrote:
> On Sat, Oct 21, 2006 at 03:05:57PM -0400, Peter Jones wrote:
> > On Fri, 2006-10-20 at 15:54 +0200, Stefan Seyfried wrote:
> > >  pm_main()
> > >  {
> > > +	[ -n "$LOGFILE" ] && ![[ "$LOGFILE" =~ "^/dev/"  ] && rm -f $LOGFILE
> > 
> > Bad syntax...
> 
> Yes, i should probably run the code before submitting the patches... :-(
> 
> > > +	[ -n "$LOGFILE" ] && exec > $LOGFILE 2>&1
> > 
> > This is really ugly :/
> > Why not:
> > 
> > if [ -n "$LOGFILE ]; then
> >   [ -f "$LOGFILE" ] && rm -f $LOGFILE
> >   touch "$LOGFILE"
> > fi
> 
> It's not equivalent. "exec > $LOGFILE 2>&1" redirects all future stderr and
> stdout to the logfile and that's what we want.

Ah, indeed.  So I've committed this as:

pm_main()
{
        if [ -n "$LOGFILE" ]; then
                [ -f "$LOGFILE" ] && rm -f "$LOGFILE"
                exec > "$LOGFILE" 2>&1
        fi
        take_suspend_lock || exit 1
        run_hooks "$1"
        sync ; sync ; sync
...

> We could actually try to find out if we are running from HAL (=>redirect to
> logfile) or not (interactive => show output on console), but that's not too
> important yet.

If we're going to do something like this, then the best way would be for
HAL to give us a pipe as the logfile, and to set some other
environmental variable that we can test for.  Then we can prefix
specific messages as things we think should be presented to
HAL/g-p-m/whatever as normal UI.

-- 
  Peter



More information about the Pm-utils mailing list