diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-11-05 22:49:23 +0000 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2016-01-18 20:46:10 +0100 |
commit | 35f4e5dccb6aaa818a53bb6b12acb1c1a2f3b465 (patch) | |
tree | c7f0c0e66870f72aa283db20c23d62152cac9fd8 /common/gvfsutils.c | |
parent | 4af662dce03afbf9cd12f73b17a74cf10f9dd47b (diff) | |
download | gvfs-35f4e5dccb6aaa818a53bb6b12acb1c1a2f3b465.tar.gz |
daemon: Allow toggling debug output with SIGUSR2
With dbus hooked up to systemd, it can be useful to toggle debug output
on/off for a running daemon. Respond to SIGUSR2 by toggling debug
output.
E.g. to toggle and then watch debug output on a running sftp mount:
$ pkill -USR2 gvfsd-sftp
$ journalctl -f
https://bugzilla.gnome.org/show_bug.cgi?id=740660
Diffstat (limited to 'common/gvfsutils.c')
-rw-r--r-- | common/gvfsutils.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/common/gvfsutils.c b/common/gvfsutils.c index 47c31176..1c5c2e3a 100644 --- a/common/gvfsutils.c +++ b/common/gvfsutils.c @@ -22,6 +22,7 @@ #include <string.h> #include <glib.h> #include <glib/gstdio.h> +#include <signal.h> #include "gvfsutils.h" #ifdef G_OS_UNIX @@ -30,6 +31,9 @@ #include <unistd.h> #endif +/* Indicates whether debug output is enabled. */ +static gboolean debugging = FALSE; + /** * gvfs_randomize_string: * @str: the string to randomize @@ -86,3 +90,38 @@ out: return FALSE; #endif } + +gboolean +gvfs_get_debug (void) +{ + return debugging; +} + +void +gvfs_set_debug (gboolean debugging_) +{ + debugging = debugging_; +} + +static void +toggle_debugging (int signum) +{ + debugging = !debugging; +} + +/** + * gvfs_setup_debugging_handler: + * + * Sets up a handler for SIGUSR2 that toggles the debugging flag when the + * signal is received. + **/ +void +gvfs_setup_debug_handler (void) +{ + struct sigaction sa; + + sigemptyset (&sa.sa_mask); + sa.sa_handler = toggle_debugging; + sa.sa_flags = 0; + sigaction (SIGUSR2, &sa, NULL); +} |