summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <mzqohf@0pointer.de>2009-08-04 22:50:50 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2009-08-04 22:51:52 +0100
commiteca8214088555297591e5561ef5dfd690a85f196 (patch)
tree0096a21b95ddf206be664d1443dc81b98169f54e
parentb4474f1f2350ddca67e1f90d19705e3740f1b65d (diff)
dbus-monitor: get rid of SIGINT madness
(Taken from a patch to dbus upstream; thanks!) 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: Will Thompson <will.thompson@collabora.co.uk>
-rw-r--r--bustle-dbus-monitor.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/bustle-dbus-monitor.c b/bustle-dbus-monitor.c
index e225021..0ebaded 100644
--- a/bustle-dbus-monitor.c
+++ b/bustle-dbus-monitor.c
@@ -39,8 +39,6 @@
#include <time.h>
-#include <signal.h>
-
#include <dbus/dbus.h>
#ifdef DBUS_WIN
@@ -237,14 +235,6 @@ usage (char *name, int ecode)
exit (ecode);
}
-dbus_bool_t sigint_received = FALSE;
-
-static void
-sigint_handler (int signum)
-{
- sigint_received = TRUE;
-}
-
static void
get_well_known_names (DBusConnection *connection)
{
@@ -328,6 +318,9 @@ main (int argc, char *argv[])
int i = 0, j = 0, numFilters = 0;
char **filters = NULL;
+
+ setvbuf(stdout, NULL, _IOLBF, 0);
+
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
@@ -408,10 +401,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, 1000)
- && !sigint_received)
+ while (dbus_connection_read_write_dispatch(connection, 1000))
;
exit (0);
lose: