diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml
index b69fa13782..b62c35ae74 100644
--- a/man/sd_session_is_active.xml
+++ b/man/sd_session_is_active.xml
@@ -21,6 +21,7 @@
sd_session_is_remote
sd_session_get_state
sd_session_get_uid
+ sd_session_get_username
sd_session_get_seat
sd_session_get_service
sd_session_get_type
@@ -60,6 +61,12 @@
uid_t *uid
+
+ int sd_session_get_username
+ const char *session
+ char **username
+
+
int sd_session_get_seat
const char *session
@@ -155,6 +162,13 @@
determine the user identifier of the Unix user the session
identified by the specified session identifier belongs to.
+ sd_session_get_username() may be used to
+ determine the name of the Unix user the session identified by
+ the specified session identifier belongs to. The returned string
+ needs to be freed with the libc
+ free3
+ call after use.
+
sd_session_get_seat() may be used to
determine the seat identifier of the seat the session identified
by the specified session identifier belongs to. Note that not all
@@ -252,6 +266,7 @@
positive integer; if it fails, 0. On success,
sd_session_get_state(),
sd_session_get_uid(),
+ sd_session_get_username(),
sd_session_get_seat(),
sd_session_get_service(),
sd_session_get_type(),
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 802009b710..013167f097 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -812,3 +812,8 @@ global:
sd_pidfd_get_user_unit;
sd_journal_get_seqnum;
} LIBSYSTEMD_252;
+
+LIBSYSTEMD_254 {
+global:
+ sd_session_get_username;
+} LIBSYSTEMD_253;
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index d483889fd1..a01855d583 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -742,6 +742,10 @@ static int session_get_string(const char *session, const char *field, char **val
return 0;
}
+_public_ int sd_session_get_username(const char *session, char **username) {
+ return session_get_string(session, "USER", username);
+}
+
_public_ int sd_session_get_seat(const char *session, char **seat) {
return session_get_string(session, "SEAT", seat);
}
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 85dd086e2b..fefc05667b 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -157,6 +157,9 @@ int sd_session_get_state(const char *session, char **state);
/* Determine user ID of session */
int sd_session_get_uid(const char *session, uid_t *uid);
+/* Determine username of session */
+int sd_session_get_username(const char *session, char **username);
+
/* Determine seat of session */
int sd_session_get_seat(const char *session, char **seat);