sd-login: add sd_uid_get_login_time interface #26574
This commit is contained in:
@@ -817,4 +817,5 @@ LIBSYSTEMD_254 {
|
||||
global:
|
||||
sd_session_get_username;
|
||||
sd_session_get_start_time;
|
||||
sd_uid_get_login_time;
|
||||
} LIBSYSTEMD_253;
|
||||
|
||||
@@ -503,6 +503,36 @@ _public_ int sd_uid_get_display(uid_t uid, char **session) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_uid_get_login_time(uid_t uid, uint64_t *usec) {
|
||||
_cleanup_free_ char *p = NULL, *s = NULL, *rt = NULL;
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
assert_return(usec, -EINVAL);
|
||||
|
||||
r = file_of_uid(uid, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = parse_env_file(NULL, p, "STATE", &s, "REALTIME", &rt);
|
||||
if (r == -ENOENT)
|
||||
return -ENXIO;
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (isempty(s) || isempty(rt))
|
||||
return -EIO;
|
||||
|
||||
if (!STR_IN_SET(s, "active", "online"))
|
||||
return -ENXIO;
|
||||
|
||||
r = safe_atou64(rt, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*usec = t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int file_of_seat(const char *seat, char **_p) {
|
||||
char *p;
|
||||
int r;
|
||||
|
||||
@@ -130,6 +130,9 @@ int sd_uid_get_state(uid_t uid, char **state);
|
||||
/* Return primary session of user, if there is any */
|
||||
int sd_uid_get_display(uid_t uid, char **session);
|
||||
|
||||
/* Determine the login time of user */
|
||||
int sd_uid_get_login_time(uid_t uid, uint64_t *usec);
|
||||
|
||||
/* Return 1 if UID has session on seat. If require_active is true, this will
|
||||
* look for active sessions only. */
|
||||
int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat);
|
||||
|
||||
Reference in New Issue
Block a user