[gnome-system-monitor] systemd: add process view columns for unit, session, seat, owner
- From: Chris KÃhl <chriskuehl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] systemd: add process view columns for unit, session, seat, owner
- Date: Sat, 14 Jan 2012 00:35:12 +0000 (UTC)
commit df292c0fb07d73448fe26048118b127719750729
Author: Lennart Poettering <lennart poettering net>
Date: Thu Jan 12 23:28:38 2012 +0100
systemd: add process view columns for unit, session, seat, owner
This (optionally) hooks up the system monitor with systemd, adding
four new columns to the process view:
1. Unit (i.e. the service name a system process belongs to)
2. Session (i.e. the login session a user process belongs to)
3. Seat (i.e. the physical seat the session of the process belongs to,
only for multi-seat environments)
4. Owner (i.e. the user a process belongs to, which is not influenced
by temporary UID changes like sudo/su/suid.
This patch also enables that the Unit column is shown by default.
If systemd is not around at runtime or at compile time none of the
four new columns are shown.
https://bugzilla.gnome.org/show_bug.cgi?id=667829
configure.ac | 12 +++
src/Makefile.am | 5 +-
src/org.gnome.gnome-system-monitor.gschema.xml.in | 60 ++++++++++++++-
src/procdialogs.cpp | 15 ++++
src/procman.h | 7 ++
src/proctable.cpp | 88 ++++++++++++++++++---
src/proctable.h | 4 +
7 files changed, 174 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a9288a9..cba462e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,17 @@ RSVG_REQUIRED=2.35
PKG_CHECK_MODULES(PROCMAN, glib-2.0 >= $GLIB_REQUIRED libgtop-2.0 >= $LIBGTOP_REQUIRED libwnck-3.0 >= $LIBWNCK_REQUIRED gtk+-3.0 >= $GTK_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gtkmm-3.0 >= $GTKMM_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED librsvg-2.0 >= $RSVG_REQUIRED glibmm-2.4 >= $GLIBMM_REQUIRED giomm-2.4 >= $GIOMM_REQUIRED gmodule-2.0)
+have_systemd=no
+AC_ARG_ENABLE(systemd, AS_HELP_STRING([--disable-systemd], [disable systemd support]))
+if test "x$enable_systemd" != "xno"; then
+ PKG_CHECK_MODULES(SYSTEMD, [ libsystemd-daemon libsystemd-login ],
+ [AC_DEFINE(HAVE_SYSTEMD, 1, [Define if systemd is available]) have_systemd=yes], have_systemd=no)
+ if test "x$have_systemd" = xno -a "x$enable_systemd" = xyes; then
+ AC_MSG_ERROR([*** systemd support requested but libraries not found])
+ fi
+fi
+AM_CONDITIONAL(HAVE_SYSTEMD, [test "$have_systemd" = "yes"])
+
# Compiler warnings
GNOME_COMPILE_WARNINGS([maximum])
@@ -105,4 +116,5 @@ Configuration:
CXXFLAGS: ${CXXFLAGS}
Maintainer mode: ${USER_MAINTAINER_MODE}
Languages: ${ALL_LINGUAS}
+ systemd support: ${have_systemd}
"
diff --git a/src/Makefile.am b/src/Makefile.am
index 05b75d9..ccf76b7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,8 @@ INCLUDES = \
-DPROCMAN_DATADIR=\""$(datadir)/procman/"\" \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-DDATADIR=\""$(datadir)"\" \
- @PROCMAN_CFLAGS@
+ @PROCMAN_CFLAGS@ \
+ @SYSTEMD_CFLAGS@
bin_PROGRAMS = gnome-system-monitor
@@ -47,7 +48,7 @@ gnome_system_monitor_SOURCES = \
$(gnome_system_monitor_cpp_files) \
$(gnome_system_monitor_c_files)
-gnome_system_monitor_LDADD = @PROCMAN_LIBS@ libbacon.la
+gnome_system_monitor_LDADD = @PROCMAN_LIBS@ @SYSTEMD_LIBS@ libbacon.la
noinst_LTLIBRARIES = libbacon.la
libbacon_la_SOURCES = \
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index 6533681..9fd21b0 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -428,14 +428,70 @@
</_summary>
</key>
- <key name="col-18-width" type="i">
+ <key name="col-18-width" type="i">
+ <default>70
+ </default>
+ <_summary>Width of process 'Unit' column
+ </_summary>
+ </key>
+
+ <key name="col-18-visible" type="b">
+ <default>true
+ </default>
+ <_summary>Show process 'Unit' column on startup
+ </_summary>
+ </key>
+
+ <key name="col-19-width" type="i">
+ <default>41
+ </default>
+ <_summary>Width of process 'Session' column
+ </_summary>
+ </key>
+
+ <key name="col-19-visible" type="b">
+ <default>false
+ </default>
+ <_summary>Show process 'Session' column on startup
+ </_summary>
+ </key>
+
+ <key name="col-20-width" type="i">
+ <default>59
+ </default>
+ <_summary>Width of process 'Seat' column
+ </_summary>
+ </key>
+
+ <key name="col-20-visible" type="b">
+ <default>false
+ </default>
+ <_summary>Show process 'Seat' column on startup
+ </_summary>
+ </key>
+
+ <key name="col-21-width" type="i">
+ <default>59
+ </default>
+ <_summary>Width of process 'Owner' column
+ </_summary>
+ </key>
+
+ <key name="col-21-visible" type="b">
+ <default>false
+ </default>
+ <_summary>Show process 'Owner' column on startup
+ </_summary>
+ </key>
+
+ <key name="col-22-width" type="i">
<default>100
</default>
<_summary>Width of process 'Priority' column
</_summary>
</key>
- <key name="col-18-visible" type="b">
+ <key name="col-22-visible" type="b">
<default>true
</default>
<_summary>Show process 'Priority' column on startup
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index d990933..a720ac8 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -24,6 +24,11 @@
#include <signal.h>
#include <string.h>
+
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
#include "procdialogs.h"
#include "proctable.h"
#include "callbacks.h"
@@ -464,6 +469,16 @@ create_field_page(GtkWidget *tree, const char* text)
if ((column_id == COL_CGROUP) && (!cgroups_enabled()))
continue;
+ if ((column_id == COL_UNIT ||
+ column_id == COL_SESSION ||
+ column_id == COL_SEAT ||
+ column_id == COL_OWNER)
+#ifdef HAVE_SYSTEMD
+ && sd_booted() <= 0
+#endif
+ )
+ continue;
+
visible = gtk_tree_view_column_get_visible (column);
gtk_list_store_append (model, &iter);
diff --git a/src/procman.h b/src/procman.h
index f285cc8..f42bacd 100644
--- a/src/procman.h
+++ b/src/procman.h
@@ -139,6 +139,12 @@ MutableProcInfo()
guint pcpu;
gint nice;
gchar *cgroup_name;
+
+ gchar *unit;
+ gchar *session;
+ gchar *seat;
+
+ std::string owner;
};
@@ -173,6 +179,7 @@ class ProcInfo
// adds one more ref to icon
void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
void set_user(guint uid);
+ std::string lookup_user(guint uid);
GtkTreeIter node;
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 4f7cef8..2f33b37 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -44,6 +44,11 @@
#include <set>
#include <list>
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
+#endif
+
#include "procman.h"
#include "selection.h"
#include "proctable.h"
@@ -248,6 +253,10 @@ proctable_new (ProcData * const procdata)
/* xgettext: combined noun, the function the process is waiting in, see wchan ps(1) */
N_("Waiting Channel"),
N_("Control Group"),
+ N_("Unit"),
+ N_("Session"),
+ N_("Seat"),
+ N_("Owner"),
N_("Priority"),
NULL,
"POINTER"
@@ -279,6 +288,10 @@ proctable_new (ProcData * const procdata)
G_TYPE_ULONG, /* Memory */
G_TYPE_STRING, /* wchan */
G_TYPE_STRING, /* Cgroup */
+ G_TYPE_STRING, /* Unit */
+ G_TYPE_STRING, /* Session */
+ G_TYPE_STRING, /* Seat */
+ G_TYPE_STRING, /* Owner */
G_TYPE_STRING, /* Priority */
GDK_TYPE_PIXBUF, /* Icon */
G_TYPE_POINTER, /* ProcInfo */
@@ -463,6 +476,17 @@ proctable_new (ProcData * const procdata)
gtk_tree_view_column_set_visible(column, FALSE);
}
+#ifdef HAVE_SYSTEMD
+ if (sd_booted() <= 0)
+#endif
+ {
+ GtkTreeViewColumn *column;
+
+ for (i = COL_UNIT; i <= COL_OWNER; i++) {
+ column = my_gtk_tree_view_get_column_with_sort_column_id(GTK_TREE_VIEW(proctree), i);
+ gtk_tree_view_column_set_visible(column, FALSE);
+ }
+ }
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree))),
"changed",
@@ -486,6 +510,9 @@ ProcInfo::~ProcInfo()
g_free(this->arguments);
g_free(this->security_context);
g_free(this->cgroup_name);
+ g_free(this->unit);
+ g_free(this->session);
+ g_free(this->seat);
}
@@ -513,16 +540,9 @@ get_process_name (ProcInfo *info,
info->name = g_strdup (cmd);
}
-
-
-void
-ProcInfo::set_user(guint uid)
+std::string
+ProcInfo::lookup_user(guint uid)
{
- if (G_LIKELY(this->uid == uid))
- return;
-
- this->uid = uid;
-
typedef std::pair<ProcInfo::UserMap::iterator, bool> Pair;
ProcInfo::UserMap::value_type hint(uid, "");
Pair p(ProcInfo::users.insert(hint));
@@ -542,10 +562,18 @@ ProcInfo::set_user(guint uid)
}
}
- this->user = p.first->second;
+ return p.first->second;
}
+void
+ProcInfo::set_user(guint uid)
+{
+ if (G_LIKELY(this->uid == uid))
+ return;
+ this->uid = uid;
+ this->user = lookup_user(uid);
+}
static void get_process_memory_writable(ProcInfo *info)
{
@@ -620,6 +648,10 @@ update_info_mutable_cols(ProcInfo *info)
tree_store_update(model, &info->node, COL_MEM, info->mem);
tree_store_update(model, &info->node, COL_WCHAN, info->wchan);
tree_store_update(model, &info->node, COL_CGROUP, info->cgroup_name);
+ tree_store_update(model, &info->node, COL_UNIT, info->unit);
+ tree_store_update(model, &info->node, COL_SESSION, info->session);
+ tree_store_update(model, &info->node, COL_SEAT, info->seat);
+ tree_store_update(model, &info->node, COL_OWNER, info->owner.c_str());
}
@@ -704,7 +736,35 @@ remove_info_from_tree (ProcData *procdata, GtkTreeModel *model,
procman::poison(current->node, 0x69);
}
+static void
+get_process_systemd_info(ProcInfo *info)
+{
+#ifdef HAVE_SYSTEMD
+ uid_t uid;
+
+ if (sd_booted() <= 0)
+ return;
+
+ free(info->unit);
+ info->unit = NULL;
+ sd_pid_get_unit(info->pid, &info->unit);
+
+ free(info->session);
+ info->session = NULL;
+ sd_pid_get_session(info->pid, &info->session);
+ free(info->seat);
+ info->seat = NULL;
+
+ if (info->session != NULL)
+ sd_session_get_seat(info->session, &info->seat);
+
+ if (sd_pid_get_owner_uid(info->pid, &uid) >= 0)
+ info->owner = info->lookup_user(uid);
+ else
+ info->owner = "";
+#endif
+}
static void
update_info (ProcData *procdata, ProcInfo *info)
@@ -739,6 +799,8 @@ update_info (ProcData *procdata, ProcInfo *info)
/* get cgroup data */
get_process_cgroup_info(info);
+
+ get_process_systemd_info(info);
}
@@ -785,10 +847,10 @@ ProcInfo::ProcInfo(pid_t pid)
get_process_selinux_context (info);
info->cgroup_name = NULL;
get_process_cgroup_info(info);
-}
-
-
+ info->unit = info->session = info->seat = NULL;
+ get_process_systemd_info(info);
+}
static void
refresh_list (ProcData *procdata, const pid_t* pid_list, const guint n)
diff --git a/src/proctable.h b/src/proctable.h
index 193288d..dbfeada 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -44,6 +44,10 @@ enum
COL_MEM,
COL_WCHAN,
COL_CGROUP,
+ COL_UNIT,
+ COL_SESSION,
+ COL_SEAT,
+ COL_OWNER,
COL_PRIORITY,
COL_PIXBUF,
COL_POINTER,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]