Commit 2a7f1be1 authored by Ben's avatar Ben Committed by Robert Roth

Move all code related to systemd in systemd.{cpp,h} to have a clean interface...

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's avatarRobert Roth <robert.roth.off@gmail.com>
parent 3c1f1787
......@@ -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 \
......
......@@ -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);
......
......@@ -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)
......
#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
}
#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
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment