summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-07-27 21:30:52 +0200
committerLennart Poettering <lennart@poettering.net>2009-10-17 00:28:28 +0200
commit904319153eb271202853fc15c49b6d8199d3c78e (patch)
treee46b54003b64a8cee005f1fe0a884a4bef430cf9
parent03cc20707a3e7b2d8629e84d7a766f41edb8b444 (diff)
dbus-monitor: get rid of SIGINT madness
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().
-rw-r--r--tools/dbus-monitor.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 873108bc..f2f73142 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
@@ -66,12 +64,12 @@ monitor_filter_func (DBusConnection *connection,
void *user_data)
{
print_message (message, FALSE);
-
+
if (dbus_message_is_signal (message,
DBUS_INTERFACE_LOCAL,
"Disconnected"))
exit (0);
-
+
/* Conceptually we want this to be
* DBUS_HANDLER_RESULT_NOT_YET_HANDLED, but this raises
* some problems. See bug 1719.
@@ -195,14 +193,6 @@ usage (char *name, int ecode)
exit (ecode);
}
-static dbus_bool_t sigint_received = FALSE;
-
-static void
-sigint_handler (int signum)
-{
- sigint_received = TRUE;
-}
-
int
main (int argc, char *argv[])
{
@@ -211,9 +201,12 @@ main (int argc, char *argv[])
DBusBusType type = DBUS_BUS_SESSION;
DBusHandleMessageFunction filter_func = monitor_filter_func;
char *address = NULL;
-
+
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];
@@ -340,13 +333,10 @@ main (int argc, char *argv[])
}
/* 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:
fprintf (stderr, "Error: %s\n", error.message);
exit (1);
}
-