summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/login/libsystemd-login.sym1
-rw-r--r--src/login/sd-login.c28
-rw-r--r--src/systemd/sd-login.h3
3 files changed, 32 insertions, 0 deletions
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
index 15e505e83b..3100c17662 100644
--- a/src/login/libsystemd-login.sym
+++ b/src/login/libsystemd-login.sym
@@ -37,4 +37,5 @@ local:
LIBSYSTEMD_LOGIN_38 {
global:
sd_pid_get_unit;
+ sd_session_get_service;
} LIBSYSTEMD_LOGIN_31;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 8893b1de80..ed98412266 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -415,6 +415,34 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
return 0;
}
+_public_ int sd_session_get_service(const char *session, char **service) {
+ char *p, *s = NULL;
+ int r;
+
+ if (!session)
+ return -EINVAL;
+ if (!service)
+ return -EINVAL;
+
+ p = strappend("/run/systemd/sessions/", session);
+ if (!p)
+ return -ENOMEM;
+
+ r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
+ free(p);
+
+ if (r < 0) {
+ free(s);
+ return r;
+ }
+
+ if (isempty(s))
+ return -ENOENT;
+
+ *service = s;
+ return 0;
+}
+
_public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) {
char *p, *s = NULL, *t = NULL;
int r;
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 00de6716b0..7d76f9a44e 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -83,6 +83,9 @@ int sd_session_get_uid(const char *session, uid_t *uid);
/* Determine seat of session */
int sd_session_get_seat(const char *session, char **seat);
+/* Determine the (PAM) service name this session was registered by. */
+int sd_session_get_service(const char *session, char **service);
+
/* Return active session and user of seat */
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);