[patch] Make dbus-monitor flush its output on CTRL-C

Olli Salli olli.salli at collabora.co.uk
Wed Nov 8 09:53:22 PST 2006


Uh, right.

This is the _patch_, whistle.

Olli

On Wednesday 08 November 2006 19:47, Olli Salli wrote:
> Hi,
> 
> a fine suggestion indeed. Attached is the updated patch.
> 
> Olli
> 
> On Wednesday 08 November 2006 20:16, Daniel P. Berrange wrote:
> > On Wed, Nov 08, 2006 at 12:29:33PM -0500, Havoc Pennington wrote:
> > > 
> > > 
> > > Olli Salli wrote:
> > > >Hi,
> > > >
> > > >I noticed that when you run dbus-monitor redirecting its output to a file 
> > > >and terminate it, its output in the file will be truncated due to stdio 
> > > >buffers not getting flushed. This patch adds a SIGINT handler which 
> > > >flushes the buffers and exits, so the full output is always present.
> > > >
> > > 
> > > I thought glibc did this anyway? Maybe only for stderr?
> > 
> > Yes, if you call 'exit' then all open streams are flushed.
> > 
> > > I don't think it's technically allowed to do this in a signal handler, 
> > > though of course it's harmless in practice. Patch seems fine. Maybe you 
> > > want to add a comment "this isn't signal-safe but it's a best-effort 
> > > thing" to avoid signal-safety police filing bugs. ;-)
> > 
> > Neither exit or fflush are async-signal safe according to POSIX - if a
> > second SIGINT arrives while flushing the first, then this will almost
> > certainly deadlock due to non-reentrant locking used in the fflush call.
> > 
> > The better way would be to just set a flag in the signal handler & and
> > then have that flag checked in the while loop that dbus-monitor spins
> > in. Assuming we've not set SA_RESTART for the signals, the receiving
> > of the signal ought to cause the poll() to terminate early & thus the
> > current iteration of the loop should finish.
> > 
> > Regards,
> > Dan.
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-monitor-updated-sigint-blast.diff
Type: text/x-diff
Size: 1073 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20061108/fd5934ba/dbus-monitor-updated-sigint-blast.bin


More information about the dbus mailing list