summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <mzqohf@0pointer.de>2009-07-31 12:26:57 -0400
committerColin Walters <walters@verbum.org>2009-07-31 12:27:48 -0400
commit43b1f91865bcaa3929c9039fb4aa1c0ee34f54e8 (patch)
treedfe256b59166aa4df969a38d57e694df07886fe4
parent1116f210aa2bfda9ee96112b81c1f2db100dee95 (diff)
downloaddbus-43b1f91865bcaa3929c9039fb4aa1c0ee34f54e8.tar.gz
dbus-monitor: use unbuffered stdout instead of handling SIGINT
The current SIGINT handling of dbus-monitor ain't making too many people happy since it defers the exit to the next msg received -- which might be quite some time away often enough. This patch replaces the SIGINT handling by simply enabling line-buffered IO for STDOUT so that even if you redirect dbus-monitor into a file no lines get accidently lost and the effect of C-c is still immediate. halfline came up with the great idea to use setvbuf here instead of fflush()ing after each printf(). (Oh and the old signal handler was broken anyway, the flag should have been of type sigatomic_t and be marked volatile) Signed-off-by: Colin Walters <walters@verbum.org>
-rw-r--r--tools/dbus-monitor.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 873108bc..c3681289 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -33,8 +33,6 @@
#include <time.h>
-#include <signal.h>
-
#include "dbus-print-message.h"
#ifdef DBUS_WIN
@@ -214,6 +212,13 @@ main (int argc, char *argv[])
int i = 0, j = 0, numFilters = 0;
char **filters = NULL;
+
+ /* Set stdout to be unbuffered; this is basically so that if people
+ * do dbus-monitor > file, then send SIGINT via Control-C, they
+ * don't lose the last chunk of messages.
+ */
+ setvbuf (stdout, NULL, _IOLBF, 0);
+
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
@@ -339,10 +344,7 @@ main (int argc, char *argv[])
exit (1);
}
- /* we handle SIGINT so exit() is reached and flushes stdout */
- signal (SIGINT, sigint_handler);
- while (dbus_connection_read_write_dispatch(connection, -1)
- && !sigint_received)
+ while (dbus_connection_read_write_dispatch(connection, -1))
;
exit (0);
lose: