]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-login: add sd_session_get_start_time 26574/head
authorMike Yuan <me@yhndnzj.com>
Thu, 23 Feb 2023 17:45:50 +0000 (01:45 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 23 Feb 2023 18:12:36 +0000 (02:12 +0800)
man/sd_session_is_active.xml
src/libsystemd/libsystemd.sym
src/libsystemd/sd-login/sd-login.c
src/systemd/sd-login.h

index b62c35ae7401236e9b780d81d1f1a7e9148c19d3..716d8e162e24c4d31f18288f47165b1a3cf277b8 100644 (file)
@@ -23,6 +23,7 @@
     <refname>sd_session_get_uid</refname>
     <refname>sd_session_get_username</refname>
     <refname>sd_session_get_seat</refname>
+    <refname>sd_session_get_start_time</refname>
     <refname>sd_session_get_service</refname>
     <refname>sd_session_get_type</refname>
     <refname>sd_session_get_class</refname>
         <paramdef>char **<parameter>seat</parameter></paramdef>
       </funcprototype>
 
+      <funcprototype>
+        <funcdef>int <function>sd_session_get_start_time</function></funcdef>
+        <paramdef>const char *<parameter>session</parameter></paramdef>
+        <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
+      </funcprototype>
+
       <funcprototype>
         <funcdef>int <function>sd_session_get_service</function></funcdef>
         <paramdef>const char *<parameter>session</parameter></paramdef>
     <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
     call after use.</para>
 
+    <para><function>sd_session_get_start_time()</function> may be used to
+    determine the start time of the session identified by the specified
+    session identifier belongs to.</para>
+
     <para><function>sd_session_get_service()</function> may be used to
     determine the name of the service (as passed during PAM session
     setup) that registered the session identified by the specified
index 013167f0979e084426adaf8f95e5f3cc56b558c0..8b5edabb75eb4749000381a89318cdb5bab4b3a5 100644 (file)
@@ -816,4 +816,5 @@ global:
 LIBSYSTEMD_254 {
 global:
         sd_session_get_username;
+        sd_session_get_start_time;
 } LIBSYSTEMD_253;
index a01855d5830d11fe3dbf02804ec8e68b4669ced3..12cb4e67922370bc3d1e4eb133580ad67f33b06a 100644 (file)
@@ -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);
 }
index fefc05667b1b7cc9603937ec73ff57222f9e259e..526af34d376dc2b2db377edb5f7bc6ef0d407bf4 100644 (file)
@@ -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);