ShellApp: Connect applications to systemd journal (if available)
Systemd-for-the-user-session would also do this, but that's a deeply invasive change that I may not actually get to this cycle. This change is tiny and non-invasive, but provides an important benefit: You can actually reliably tell *which* applications are logging which messages (assuming they're launched by the shell). This actually complements a recent change in DBus: See https://bugs.freedesktop.org/show_bug.cgi?id=68559 which does a similar thing for bus activated apps. https://bugzilla.gnome.org/show_bug.cgi?id=711626
This commit is contained in:
parent
52b1a1b835
commit
213ee8d381
18
configure.ac
18
configure.ac
@ -58,6 +58,21 @@ fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_RECORDER, $build_recorder)
|
||||
|
||||
AC_ARG_ENABLE([systemd],
|
||||
AS_HELP_STRING([--enable-systemd], [Use systemd]),
|
||||
[enable_systemd=$enableval],
|
||||
[enable_systemd=auto])
|
||||
AS_IF([test x$enable_systemd != xno], [
|
||||
AC_MSG_CHECKING([for libsystemd-journal])
|
||||
PKG_CHECK_EXISTS([libsystemd-journal],
|
||||
[have_systemd=yes
|
||||
AC_DEFINE([HAVE_SYSTEMD], [1], [Define if we have systemd])],
|
||||
[have_systemd=no])
|
||||
AC_MSG_RESULT($have_systemd)
|
||||
])
|
||||
|
||||
AC_MSG_RESULT($enable_systemd)
|
||||
|
||||
CLUTTER_MIN_VERSION=1.13.4
|
||||
GOBJECT_INTROSPECTION_MIN_VERSION=0.10.1
|
||||
GJS_MIN_VERSION=1.38.1
|
||||
@ -93,6 +108,9 @@ SHARED_PCS="gio-unix-2.0 >= $GIO_MIN_VERSION
|
||||
libnm-glib libnm-util >= $NETWORKMANAGER_MIN_VERSION
|
||||
libnm-gtk >= $NETWORKMANAGER_MIN_VERSION
|
||||
libsecret-unstable gcr-base-3 >= $GCR_MIN_VERSION"
|
||||
if test x$have_systemd = xyes; then
|
||||
SHARED_PCS="${SHARED_PCS} libsystemd-journal"
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(GNOME_SHELL, $SHARED_PCS)
|
||||
PKG_CHECK_MODULES(MUTTER, libmutter >= $MUTTER_MIN_VERSION)
|
||||
|
@ -17,6 +17,12 @@
|
||||
#include "st.h"
|
||||
#include "gtkactionmuxer.h"
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
#include <systemd/sd-journal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
MATCH_NONE,
|
||||
MATCH_SUBSTRING, /* Not prefix, substring */
|
||||
@ -1161,6 +1167,29 @@ _gather_pid_callback (GDesktopAppInfo *gapp,
|
||||
app);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
/* This sets up the launched application to log to the journal
|
||||
* using its own identifier, instead of just "gnome-session".
|
||||
*/
|
||||
static void
|
||||
app_child_setup (gpointer user_data)
|
||||
{
|
||||
const char *appid = user_data;
|
||||
int res;
|
||||
int journalfd = sd_journal_stream_fd (appid, LOG_INFO, FALSE);
|
||||
if (journalfd >= 0)
|
||||
{
|
||||
do
|
||||
res = dup2 (journalfd, 1);
|
||||
while (G_UNLIKELY (res == -1 && errno == EINTR));
|
||||
do
|
||||
res = dup2 (journalfd, 2);
|
||||
while (G_UNLIKELY (res == -1 && errno == EINTR));
|
||||
(void) close (journalfd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* shell_app_launch:
|
||||
* @timestamp: Event timestamp, or 0 for current event timestamp
|
||||
@ -1203,7 +1232,11 @@ shell_app_launch (ShellApp *app,
|
||||
ret = g_desktop_app_info_launch_uris_as_manager (app->info, NULL,
|
||||
G_APP_LAUNCH_CONTEXT (context),
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
#ifdef HAVE_SYSTEMD
|
||||
app_child_setup, (gpointer)shell_app_get_id (app),
|
||||
#else
|
||||
NULL, NULL,
|
||||
#endif
|
||||
_gather_pid_callback, app,
|
||||
error);
|
||||
g_object_unref (context);
|
||||
|
Loading…
Reference in New Issue
Block a user