[patch] Make dbus-monitor flush its output on CTRL-C
Daniel P. Berrange
dan at berrange.com
Wed Nov 8 10:16:49 PST 2006
On Wed, Nov 08, 2006 at 12:29:33PM -0500, Havoc Pennington wrote:
> Olli Salli wrote:
> >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.
|=- GPG key: http://www.berrange.com/~dan/gpgkey.txt -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- berrange at redhat.com - Daniel Berrange - dan at berrange.com -=|
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20061108/c986925e/attachment-0001.pgp
More information about the dbus