diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml
index b62c35ae74..716d8e162e 100644
--- a/man/sd_session_is_active.xml
+++ b/man/sd_session_is_active.xml
@@ -23,6 +23,7 @@
sd_session_get_uid
sd_session_get_username
sd_session_get_seat
+ sd_session_get_start_time
sd_session_get_service
sd_session_get_type
sd_session_get_class
@@ -73,6 +74,12 @@
char **seat
+
+ int sd_session_get_start_time
+ const char *session
+ uint64_t *usec
+
+
int sd_session_get_service
const char *session
@@ -178,6 +185,10 @@
free3
call after use.
+ sd_session_get_start_time() may be used to
+ determine the start time of the session identified by the specified
+ session identifier belongs to.
+
sd_session_get_service() may be used to
determine the name of the service (as passed during PAM session
setup) that registered the session identified by the specified
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 013167f097..8b5edabb75 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -816,4 +816,5 @@ global:
LIBSYSTEMD_254 {
global:
sd_session_get_username;
+ sd_session_get_start_time;
} LIBSYSTEMD_253;
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index a01855d583..12cb4e6792 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -750,6 +750,33 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
return session_get_string(session, "SEAT", seat);
}
+_public_ int sd_session_get_start_time(const char *session, uint64_t *usec) {
+ _cleanup_free_ char *p = NULL, *s = NULL;
+ usec_t t;
+ int r;
+
+ assert_return(usec, -EINVAL);
+
+ r = file_of_session(session, &p);
+ if (r < 0)
+ return r;
+
+ r = parse_env_file(NULL, p, "REALTIME", &s);
+ if (r == -ENOENT)
+ return -ENXIO;
+ if (r < 0)
+ return r;
+ if (isempty(s))
+ return -EIO;
+
+ r = safe_atou64(s, &t);
+ if (r < 0)
+ return r;
+
+ *usec = t;
+ return 0;
+}
+
_public_ int sd_session_get_tty(const char *session, char **tty) {
return session_get_string(session, "TTY", tty);
}
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index fefc05667b..526af34d37 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -163,6 +163,9 @@ int sd_session_get_username(const char *session, char **username);
/* Determine seat of session */
int sd_session_get_seat(const char *session, char **seat);
+/* Determine the start time of session */
+int sd_session_get_start_time(const char *session, uint64_t *usec);
+
/* Determine the (PAM) service name this session was registered by. */
int sd_session_get_service(const char *session, char **service);