summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/org.mate.system-monitor.gschema.xml.in.in34
-rw-r--r--src/procdialogs.cpp15
-rw-r--r--src/procman.h7
-rw-r--r--src/proctable.cpp88
-rw-r--r--src/proctable.h4
6 files changed, 137 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 286594f..3c350bb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,8 @@ AM_CPPFLAGS = \
-DPROCMAN_DATADIR=\""$(datadir)/procman/"\" \
-DMATELOCALEDIR=\""$(datadir)/locale"\" \
-DDATADIR=\""$(datadir)"\" \
- @PROCMAN_CFLAGS@
+ @PROCMAN_CFLAGS@ \
+ @SYSTEMD_CFLAGS@
bin_PROGRAMS = mate-system-monitor
@@ -47,7 +48,7 @@ mate_system_monitor_SOURCES = \
$(mate_system_monitor_cpp_files) \
$(mate_system_monitor_c_files)
-mate_system_monitor_LDADD = @PROCMAN_LIBS@ libbacon.la
+mate_system_monitor_LDADD = @PROCMAN_LIBS@ @SYSTEMD_LIBS@ libbacon.la
noinst_LTLIBRARIES = libbacon.la
diff --git a/src/org.mate.system-monitor.gschema.xml.in.in b/src/org.mate.system-monitor.gschema.xml.in.in
index c27c4a8..4a3c9e9 100644
--- a/src/org.mate.system-monitor.gschema.xml.in.in
+++ b/src/org.mate.system-monitor.gschema.xml.in.in
@@ -296,10 +296,42 @@
<_summary>Show process 'Control Group' column on startup</_summary>
</key>
<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</_summary>
</key>
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index c51a769..7d7aace 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"
@@ -469,6 +474,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 91f7ea4..55fea88 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 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)
diff --git a/src/proctable.h b/src/proctable.h
index 5a24803..71df77e 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,