Debian Codegraph @

upstream/debian-unstable/man3/sd_uid_get_state.3

raw
1 '\" t
2 .TH "SD_UID_GET_STATE" "3" "" "systemd 261~rc3" "sd_uid_get_state"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_uid_get_state, sd_uid_is_on_seat, sd_uid_get_sessions, sd_uid_get_seats, sd_uid_get_display, sd_uid_get_login_time \- Determine login state of a specific Unix user ID
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-login\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_uid_get_state('u
32 .BI "int sd_uid_get_state(uid_t\ " "uid" ", char\ **" "state" ");"
33 .HP \w'int\ sd_uid_is_on_seat('u
34 .BI "int sd_uid_is_on_seat(uid_t\ " "uid" ", int\ " "require_active" ", const\ char\ *" "seat" ");"
35 .HP \w'int\ sd_uid_get_sessions('u
36 .BI "int sd_uid_get_sessions(uid_t\ " "uid" ", int\ " "require_active" ", char\ ***" "sessions" ");"
37 .HP \w'int\ sd_uid_get_seats('u
38 .BI "int sd_uid_get_seats(uid_t\ " "uid" ", int\ " "require_active" ", char\ ***" "seats" ");"
39 .HP \w'int\ sd_uid_get_display('u
40 .BI "int sd_uid_get_display(uid_t\ " "uid" ", char\ **" "session" ");"
41 .HP \w'int\ sd_uid_get_login_time('u
42 .BI "int sd_uid_get_login_time(uid_t\ " "uid" ", uint64_t\ *" "usec" ");"
43 .SH "DESCRIPTION"
44 .PP
45 \fBsd_uid_get_state()\fR
46 may be used to determine the login state of a specific Unix user identifier\&. The following states are currently known:
47 "offline"
48 (user not logged in at all),
49 "lingering"
50 (user not logged in, but some user services running),
51 "online"
52 (user logged in, but not active, i\&.e\&. has no session in the foreground),
53 "active"
54 (user logged in, and has at least one active session, i\&.e\&. one session in the foreground),
55 "closing"
56 (user not logged in, and not lingering, but some processes are still around)\&. In the future additional states might be defined, client code should be written to be robust in regards to additional state strings being returned\&. The returned string needs to be freed with the libc
57 \fBfree\fR(3)
58 call after use\&.
59 .PP
60 \fBsd_uid_is_on_seat()\fR
61 may be used to determine whether a specific user is logged in or active on a specific seat\&. Accepts a Unix user identifier and a seat identifier string as parameters\&. The
62 \fIrequire_active\fR
63 parameter is a boolean value\&. If non\-zero (true), this function will test if the user is active (i\&.e\&. has a session that is in the foreground and accepting user input) on the specified seat, otherwise (false) only if the user is logged in (and possibly inactive) on the specified seat\&.
64 .PP
65 \fBsd_uid_get_sessions()\fR
66 may be used to determine the current sessions of the specified user\&. Accepts a Unix user identifier as parameter\&. The
67 \fIrequire_active\fR
68 parameter controls whether the returned list shall consist of only those sessions where the user is currently active (> 0), where the user is currently online but possibly inactive (= 0), or logged in but possibly closing the session (< 0)\&. The call returns a
69 \fBNULL\fR
70 terminated string array of session identifiers in
71 \fIsessions\fR
72 which needs to be freed by the caller with the libc
73 \fBfree\fR(3)
74 call after use, including all the strings referenced\&. If the string array parameter is passed as
75 \fBNULL\fR, the array will not be filled in, but the return code still indicates the number of current sessions\&. Note that instead of an empty array
76 \fBNULL\fR
77 may be returned and should be considered equivalent to an empty array\&.
78 .PP
79 Similarly,
80 \fBsd_uid_get_seats()\fR
81 may be used to determine the list of seats on which the user currently has sessions\&. Similar semantics apply, however note that the user may have multiple sessions on the same seat as well as sessions with no attached seat and hence the number of entries in the returned array may differ from the one returned by
82 \fBsd_uid_get_sessions()\fR\&.
83 .PP
84 \fBsd_uid_get_display()\fR
85 returns the name of the "primary" session of a user\&. If the user has graphical sessions, it will be the oldest graphical session\&. Otherwise, it will be the oldest open session\&.
86 .PP
87 \fBsd_uid_get_login_time()\fR
88 may be used to determine the time the user\*(Aqs service manager has been invoked, which is the time when the user\*(Aqs first active session, since which they stayed logged in continuously, began\&. The
89 \fIusec\fR
90 is in microseconds since the epoch (\fBCLOCK_REALTIME\fR)\&. This call will fail with
91 \fB\-ENXIO\fR
92 if the user is not currently logged in\&.
93 .SH "RETURN VALUE"
94 .PP
95 On success,
96 \fBsd_uid_get_state()\fR
97 and
98 \fBsd_uid_get_login_time()\fR
99 returns 0 or a positive integer\&. If the test succeeds,
100 \fBsd_uid_is_on_seat()\fR
101 returns a positive integer; if it fails, 0\&.
102 \fBsd_uid_get_sessions()\fR
103 and
104 \fBsd_uid_get_seats()\fR
105 return the number of entries in the returned arrays\&.
106 \fBsd_uid_get_display()\fR
107 returns a non\-negative code on success\&. On failure, these calls return a negative errno\-style error code\&.
108 .SS "Errors"
109 .PP
110 Returned errors may indicate the following problems:
111 .PP
112 \fB\-ENODATA\fR
113 .RS 4
114 The given field is not specified for the described user\&.
115 .RE
116 .PP
117 \fB\-ENXIO\fR
118 .RS 4
119 The specified seat is unknown\&.
120 .RE
121 .PP
122 \fB\-EINVAL\fR
123 .RS 4
124 An input parameter was invalid (out of range, or
125 \fBNULL\fR, where that is not accepted)\&. This is also returned if the passed user ID is
126 \fB0xFFFF\fR
127 or
128 \fB0xFFFFFFFF\fR, which are undefined on Linux\&.
129 .RE
130 .PP
131 \fB\-ENOMEM\fR
132 .RS 4
133 Memory allocation failed\&.
134 .RE
135 .SH "NOTES"
136 .PP
137 Functions described here are available as a shared library, which can be compiled against and linked to with the
138 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
139 file\&.
140 .PP
141 The code described here uses
142 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
143 \fBsetenv\fR(3)
144 from a parallel thread\&. It is recommended to only do calls to
145 \fBsetenv()\fR
146 from an early phase of the program when no other threads have been started\&.
147 .SH "HISTORY"
148 .PP
149 \fBsd_uid_get_display()\fR
150 was added in version 213\&.
151 .PP
152 \fBsd_uid_get_login_time()\fR
153 was added in version 254\&.
154 .SH "SEE ALSO"
155 .PP
156 \fBsystemd\fR(1), \fBsd-login\fR(3), \fBsd_pid_get_owner_uid\fR(3)