From fb31765cbe33890f325a87015507364156741321 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:59:44 +0200 Subject: Adding upstream version 42.0. Signed-off-by: Daniel Baumann --- src/systemd.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/systemd.cpp (limited to 'src/systemd.cpp') diff --git a/src/systemd.cpp b/src/systemd.cpp new file mode 100644 index 0000000..880fc4c --- /dev/null +++ b/src/systemd.cpp @@ -0,0 +1,61 @@ +#include +#include + +#ifdef HAVE_SYSTEMD +#include +#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; + + char* unit = NULL; + sd_pid_get_unit(info->pid, &unit); + info->unit = make_string(unit); + + char* session = NULL; + sd_pid_get_session(info->pid, &session); + info->session = make_string(session); + + if (!info->session.empty()) { + char* seat = NULL; + sd_session_get_seat(info->session.c_str(), &seat); + info->seat = make_string(seat); + } + if (sd_pid_get_owner_uid(info->pid, &uid) >= 0) + info->owner = info->lookup_user(uid); + else + info->owner = ""; +#endif +} -- cgit v1.2.3