1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

sd-login: add sd_session_get_start_time

This commit is contained in:
Mike Yuan 2023-02-24 01:45:50 +08:00
parent d71f5b1217
commit c4ef14dc2a
No known key found for this signature in database
GPG Key ID: 5A6360D78C6092C3
4 changed files with 42 additions and 0 deletions

View 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>
@ -73,6 +74,12 @@
<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>
@ -178,6 +185,10 @@
<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

View File

@ -816,4 +816,5 @@ global:
LIBSYSTEMD_254 {
global:
sd_session_get_username;
sd_session_get_start_time;
} LIBSYSTEMD_253;

View 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);
}

View 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);