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:
@ -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);
|
||||
|
Reference in New Issue
Block a user