mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-09 06:08:01 +02:00
bus signal_handler: don't use _dbus_warn, and don't pretend to be portable
_dbus_warn isn't async-signal-safe, so that's out. We can use write() instead; it's POSIX but not ISO C, but then again, so are signals. Accordingly, guard it with DBUS_UNIX. dbus-sysdeps-util-win doesn't actually implement _dbus_set_signal_handler anyway, so not compiling this code on non-Unix seems more honest. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33336 Reviewed-by: Thiago Macieira <thiago@kde.org>
This commit is contained in:
parent
50c81a35a7
commit
c7ef3ead55
1 changed files with 21 additions and 2 deletions
23
bus/main.c
23
bus/main.c
|
|
@ -35,6 +35,9 @@
|
||||||
#ifdef HAVE_ERRNO_H
|
#ifdef HAVE_ERRNO_H
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h> /* for write() and STDERR_FILENO */
|
||||||
|
#endif
|
||||||
#include "selinux.h"
|
#include "selinux.h"
|
||||||
|
|
||||||
static BusContext *context;
|
static BusContext *context;
|
||||||
|
|
@ -45,6 +48,7 @@ static int reload_pipe[2];
|
||||||
|
|
||||||
static void close_reload_pipe (DBusWatch **);
|
static void close_reload_pipe (DBusWatch **);
|
||||||
|
|
||||||
|
#ifdef DBUS_UNIX
|
||||||
static void
|
static void
|
||||||
signal_handler (int sig)
|
signal_handler (int sig)
|
||||||
{
|
{
|
||||||
|
|
@ -69,14 +73,24 @@ signal_handler (int sig)
|
||||||
* reloaded while draining the pipe buffer, which is what we
|
* reloaded while draining the pipe buffer, which is what we
|
||||||
* wanted. It's harmless that it will be reloaded fewer times than
|
* wanted. It's harmless that it will be reloaded fewer times than
|
||||||
* we asked for, since the reload is delayed anyway, so new changes
|
* we asked for, since the reload is delayed anyway, so new changes
|
||||||
* will be picked up. */
|
* will be picked up.
|
||||||
_dbus_warn ("Unable to write to reload pipe.\n");
|
*
|
||||||
|
* We use write() because _dbus_warn uses vfprintf, which isn't
|
||||||
|
* async-signal-safe.
|
||||||
|
*
|
||||||
|
* This is necessarily Unix-specific, but so are POSIX signals,
|
||||||
|
* so... */
|
||||||
|
static const char message[] =
|
||||||
|
"Unable to write to reload pipe - buffer full?\n";
|
||||||
|
|
||||||
|
write (STDERR_FILENO, message, strlen (message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* DBUS_UNIX */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage (void)
|
usage (void)
|
||||||
|
|
@ -521,12 +535,17 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
setup_reload_pipe (bus_context_get_loop (context));
|
setup_reload_pipe (bus_context_get_loop (context));
|
||||||
|
|
||||||
|
#ifdef DBUS_UNIX
|
||||||
|
/* POSIX signals are Unix-specific, and _dbus_set_signal_handler is
|
||||||
|
* unimplemented (and probably unimplementable) on Windows, so there's
|
||||||
|
* no point in trying to make the handler portable to non-Unix. */
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
_dbus_set_signal_handler (SIGHUP, signal_handler);
|
_dbus_set_signal_handler (SIGHUP, signal_handler);
|
||||||
#endif
|
#endif
|
||||||
#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
|
#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
|
||||||
_dbus_set_signal_handler (SIGIO, signal_handler);
|
_dbus_set_signal_handler (SIGIO, signal_handler);
|
||||||
#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
|
#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
|
||||||
|
#endif /* DBUS_UNIX */
|
||||||
|
|
||||||
_dbus_verbose ("We are on D-Bus...\n");
|
_dbus_verbose ("We are on D-Bus...\n");
|
||||||
_dbus_loop_run (bus_context_get_loop (context));
|
_dbus_loop_run (bus_context_get_loop (context));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue