summaryrefslogtreecommitdiff
path: root/src/proctable.cpp
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-12-18 22:24:30 +0100
committerinfirit <[email protected]>2014-12-18 22:29:00 +0100
commit21eeae3b6a844222365b873a8826001af33f1e97 (patch)
treee990971ea17c71652b63f4de14c217a33997eb3b /src/proctable.cpp
parentba876f3e3791741d977dd72e16b760c39a71e047 (diff)
downloadmate-system-monitor-21eeae3b6a844222365b873a8826001af33f1e97.tar.bz2
mate-system-monitor-21eeae3b6a844222365b873a8826001af33f1e97.tar.xz
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. Taken from GSM commit: df292c0fb07d73448fe26048118b127719750729 From: Lennart Poettering <[email protected]> Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=667829
Diffstat (limited to 'src/proctable.cpp')
-rw-r--r--src/proctable.cpp88
1 files changed, 75 insertions, 13 deletions
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 8f993d0..25b1f36 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"
@@ -259,6 +264,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"
@@ -290,6 +299,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 */
@@ -474,6 +487,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",
@@ -500,6 +524,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);
}
@@ -527,16 +554,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));
@@ -556,10 +576,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)
{
@@ -634,6 +662,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());
}
@@ -718,7 +750,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)
@@ -753,6 +813,8 @@ update_info (ProcData *procdata, ProcInfo *info)
/* get cgroup data */
get_process_cgroup_info(info);
+
+ get_process_systemd_info(info);
}
@@ -799,10 +861,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)