[gnome-system-monitor] Move all code related to systemd in systemd.{cpp, h} to have a clean interface instead of #ifdef all
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Move all code related to systemd in systemd.{cpp, h} to have a clean interface instead of #ifdef all
- Date: Mon, 2 Mar 2015 18:05:34 +0000 (UTC)
commit 2a7f1be18435e0d6541db46a0e05f909884254bd
Author: Benoit Dejean <bdejean gmail com>
Date: Sat Feb 28 06:03:19 2015 +0100
Move all code related to systemd in systemd.{cpp,h} to have a clean interface instead of #ifdef all over
the place.
Signed-off-by: Robert Roth <robert roth off gmail com>
src/Makefile.am | 1 +
src/prefsdialog.cpp | 7 ++---
src/proctable.cpp | 40 ++------------------------------
src/systemd.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/systemd.h | 12 ++++++++++
src/util.h | 3 --
6 files changed, 81 insertions(+), 44 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index e4206e2..122316c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,6 +26,7 @@ gnome_system_monitor_cpp_files = \
smooth_refresh.cpp \
disks.cpp \
selinux.cpp \
+ systemd.cpp \
cgroups.cpp \
gsm_gnomesu.cpp \
gsm_gksu.cpp \
diff --git a/src/prefsdialog.cpp b/src/prefsdialog.cpp
index 0c14682..0484253 100644
--- a/src/prefsdialog.cpp
+++ b/src/prefsdialog.cpp
@@ -11,6 +11,7 @@
#include "proctable.h"
#include "selinux.h"
#include "settings-keys.h"
+#include "systemd.h"
#include "util.h"
static GtkWidget *prefs_dialog = NULL;
@@ -179,10 +180,8 @@ create_field_page(GtkBuilder* builder, GtkWidget *tree, const gchar *widgetname)
column_id == COL_SESSION ||
column_id == COL_SEAT ||
column_id == COL_OWNER)
-#ifdef HAVE_SYSTEMD
- && !LOGIND_RUNNING()
-#endif
- )
+ && !procman::systemd_logind_running()
+ )
continue;
visible = gtk_tree_view_column_get_visible (column);
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 370d8be..0549ef2 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -43,10 +43,6 @@
#include <set>
#include <list>
-#ifdef HAVE_SYSTEMD
-#include <systemd/sd-login.h>
-#endif
-
#ifdef HAVE_WNCK
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
@@ -61,6 +57,7 @@
#include "settings-keys.h"
#include "cgroups.h"
#include "treeview.h"
+#include "systemd.h"
ProcInfo::UserMap ProcInfo::users;
ProcInfo::List ProcInfo::all;
@@ -554,9 +551,7 @@ proctable_new (GsmApplication * const app)
if (!cgroups_enabled ())
gsm_tree_view_add_excluded_column (GSM_TREE_VIEW (proctree), COL_CGROUP);
-#ifdef HAVE_SYSTEMD
- if (!LOGIND_RUNNING ())
-#endif
+ if (!procman::systemd_logind_running())
{
gsm_tree_view_add_excluded_column (GSM_TREE_VIEW (proctree), COL_UNIT);
gsm_tree_view_add_excluded_column (GSM_TREE_VIEW (proctree), COL_SESSION);
@@ -853,35 +848,6 @@ remove_info_from_tree (GsmApplication *app, GtkTreeModel *model,
procman::poison(current->node, 0x69);
}
-static void
-get_process_systemd_info(ProcInfo *info)
-{
-#ifdef HAVE_SYSTEMD
- uid_t uid;
-
- if (!LOGIND_RUNNING())
- 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 (GsmApplication *app, ProcInfo *info)
@@ -930,7 +896,7 @@ update_info (GsmApplication *app, ProcInfo *info)
/* get cgroup data */
get_process_cgroup_info(info);
- get_process_systemd_info(info);
+ procman::get_process_systemd_info(info);
}
ProcInfo::ProcInfo(pid_t pid)
diff --git a/src/systemd.cpp b/src/systemd.cpp
new file mode 100644
index 0000000..2c3c1a2
--- /dev/null
+++ b/src/systemd.cpp
@@ -0,0 +1,62 @@
+#include <config.h>
+#include <stdlib.h>
+
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-login.h>
+#endif
+
+#include "application.h"
+#include "systemd.h"
+
+
+bool
+procman::systemd_logind_running()
+{
+#ifdef HAVE_SYSTEMD
+ static bool init;
+ static bool is_running;
+
+ if (!init) {
+ /* check if logind is running */
+ if (access("/run/systemd/seats/", F_OK) >= 0) {
+ is_running = true;
+ }
+ init = true;
+ }
+
+ return is_running;
+
+#else
+ return false;
+#endif
+}
+
+void
+procman::get_process_systemd_info(ProcInfo *info)
+{
+#ifdef HAVE_SYSTEMD
+ uid_t uid;
+
+ if (!systemd_logind_running())
+ 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
+}
diff --git a/src/systemd.h b/src/systemd.h
new file mode 100644
index 0000000..6604877
--- /dev/null
+++ b/src/systemd.h
@@ -0,0 +1,12 @@
+#ifndef PROCMAN_SYSTEMD_H_144CA8D6_BF03_11E4_B291_000C298F6617
+#define PROCMAN_SYSTEMD_H_144CA8D6_BF03_11E4_B291_000C298F6617
+
+#include "application.h"
+
+namespace procman
+{
+ bool systemd_logind_running();
+ void get_process_systemd_info(ProcInfo *info);
+}
+
+#endif
diff --git a/src/util.h b/src/util.h
index 0118df4..5a5ac84 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,9 +8,6 @@
using std::string;
-/* check if logind is running */
-#define LOGIND_RUNNING() (access("/run/systemd/seats/", F_OK) >= 0)
-
GtkWidget*
procman_make_label_for_mmaps_or_ofiles(const char *format,
const char *process_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]