Debian Codegraph @

upstream/fedora-44/man3/sd_session_is_active.3

raw
1 '\" t
2 .TH "SD_SESSION_IS_ACTIVE" "3" "" "systemd 259.5" "sd_session_is_active"
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_session_is_active, sd_session_is_remote, sd_session_get_state, 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, sd_session_get_desktop, sd_session_get_display, sd_session_get_tty, sd_session_get_vt, sd_session_get_remote_host, sd_session_get_remote_user, sd_session_get_leader \- Determine state of a specific session
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_session_is_active('u
32 .BI "int sd_session_is_active(const\ char\ *" "session" ");"
33 .HP \w'int\ sd_session_is_remote('u
34 .BI "int sd_session_is_remote(const\ char\ *" "session" ");"
35 .HP \w'int\ sd_session_get_state('u
36 .BI "int sd_session_get_state(const\ char\ *" "session" ", char\ **" "state" ");"
37 .HP \w'int\ sd_session_get_uid('u
38 .BI "int sd_session_get_uid(const\ char\ *" "session" ", uid_t\ *" "uid" ");"
39 .HP \w'int\ sd_session_get_username('u
40 .BI "int sd_session_get_username(const\ char\ *" "session" ", char\ **" "username" ");"
41 .HP \w'int\ sd_session_get_seat('u
42 .BI "int sd_session_get_seat(const\ char\ *" "session" ", char\ **" "seat" ");"
43 .HP \w'int\ sd_session_get_start_time('u
44 .BI "int sd_session_get_start_time(const\ char\ *" "session" ", uint64_t\ *" "usec" ");"
45 .HP \w'int\ sd_session_get_service('u
46 .BI "int sd_session_get_service(const\ char\ *" "session" ", char\ **" "service" ");"
47 .HP \w'int\ sd_session_get_type('u
48 .BI "int sd_session_get_type(const\ char\ *" "session" ", char\ **" "type" ");"
49 .HP \w'int\ sd_session_get_class('u
50 .BI "int sd_session_get_class(const\ char\ *" "session" ", char\ **" "class" ");"
51 .HP \w'int\ sd_session_get_desktop('u
52 .BI "int sd_session_get_desktop(const\ char\ *" "session" ", char\ **" "desktop" ");"
53 .HP \w'int\ sd_session_get_display('u
54 .BI "int sd_session_get_display(const\ char\ *" "session" ", char\ **" "display" ");"
55 .HP \w'int\ sd_session_get_leader('u
56 .BI "int sd_session_get_leader(const\ char\ *" "session" ", pid_t\ *" "leader" ");"
57 .HP \w'int\ sd_session_get_remote_host('u
58 .BI "int sd_session_get_remote_host(const\ char\ *" "session" ", char\ **" "remote_host" ");"
59 .HP \w'int\ sd_session_get_remote_user('u
60 .BI "int sd_session_get_remote_user(const\ char\ *" "session" ", char\ **" "remote_user" ");"
61 .HP \w'int\ sd_session_get_tty('u
62 .BI "int sd_session_get_tty(const\ char\ *" "session" ", char\ **" "tty" ");"
63 .HP \w'int\ sd_session_get_vt('u
64 .BI "int sd_session_get_vt(const\ char\ *" "session" ", unsigned\ int\ *" "vt" ");"
65 .SH "DESCRIPTION"
66 .PP
67 \fBsd_session_is_active()\fR
68 may be used to determine whether the session identified by the specified session identifier is currently active (i\&.e\&. currently in the foreground and available for user input) or not\&.
69 .PP
70 \fBsd_session_is_remote()\fR
71 may be used to determine whether the session identified by the specified session identifier is a remote session (i\&.e\&. its remote host is known) or not\&.
72 .PP
73 \fBsd_session_get_state()\fR
74 may be used to determine the state of the session identified by the specified session identifier\&. The following states are currently known:
75 "online"
76 (session logged in, but session not active, i\&.e\&. not in the foreground),
77 "active"
78 (session logged in and active, i\&.e\&. in the foreground),
79 "closing"
80 (session nominally logged out, but some processes belonging to it 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\&. This function is a more generic version of
81 \fBsd_session_is_active()\fR\&. The returned string needs to be freed with the libc
82 \fBfree\fR(3)
83 call after use\&.
84 .PP
85 \fBsd_session_get_uid()\fR
86 may be used to determine the user identifier of the Unix user the session identified by the specified session identifier belongs to\&.
87 .PP
88 \fBsd_session_get_username()\fR
89 may be used to determine the name of the Unix user the session identified by the specified session identifier belongs to\&. The returned string needs to be freed with the libc
90 \fBfree\fR(3)
91 call after use\&.
92 .PP
93 \fBsd_session_get_seat()\fR
94 may be used to determine the seat identifier of the seat the session identified by the specified session identifier belongs to\&. Note that not all sessions are attached to a seat, this call will fail (returning
95 \fB\-ENODATA\fR) for them\&. The returned string needs to be freed with the libc
96 \fBfree\fR(3)
97 call after use\&.
98 .PP
99 \fBsd_session_get_start_time()\fR
100 may be used to determine the start time of the session identified by the specified session identifier belongs to\&. The
101 \fIusec\fR
102 is in microseconds since the epoch (\fBCLOCK_REALTIME\fR)\&.
103 .PP
104 \fBsd_session_get_service()\fR
105 may be used to determine the name of the service (as passed during PAM session setup) that registered the session identified by the specified session identifier\&. The returned string needs to be freed with the libc
106 \fBfree\fR(3)
107 call after use\&.
108 .PP
109 \fBsd_session_get_type()\fR
110 may be used to determine the type of the session identified by the specified session identifier\&. The returned string is one of
111 "x11",
112 "wayland",
113 "tty",
114 "mir"
115 or
116 "unspecified"
117 and needs to be freed with the libc
118 \fBfree\fR(3)
119 call after use\&.
120 .PP
121 \fBsd_session_get_class()\fR
122 may be used to determine the class of the session identified by the specified session identifier\&. The returned string is one of
123 "user",
124 "user\-early",
125 "user\-light",
126 "user\-early\-light",
127 "user\-incomplete",
128 "greeter",
129 "lock\-screen",
130 "background",
131 "background\-light",
132 "manager"
133 or
134 "manager\-early"
135 and needs to be freed with the libc
136 \fBfree\fR(3)
137 call after use\&.
138 .PP
139 \fBsd_session_get_desktop()\fR
140 may be used to determine the brand of the desktop running on the session identified by the specified session identifier\&. This field can be set freely by desktop environments and does not follow any special formatting\&. However, desktops are strongly recommended to use the same identifiers and capitalization as for
141 \fI$XDG_CURRENT_DESKTOP\fR, as defined by the
142 \m[blue]\fBDesktop Entry Specification\fR\m[]\&\s-2\u[1]\d\s+2\&. The returned string needs to be freed with the libc
143 \fBfree\fR(3)
144 call after use\&.
145 .PP
146 \fBsd_session_get_display()\fR
147 may be used to determine the X11 display of the session identified by the specified session identifier\&. The returned string needs to be freed with the libc
148 \fBfree\fR(3)
149 call after use\&.
150 .PP
151 \fBsd_session_get_leader()\fR
152 may be used to determine the PID of the leader of the session identified by the specified session identifier\&.
153 .PP
154 \fBsd_session_get_remote_host()\fR
155 may be used to determine the remote hostname of the session identified by the specified session identifier\&. The returned string needs to be freed with the libc
156 \fBfree\fR(3)
157 call after use\&.
158 .PP
159 \fBsd_session_get_remote_user()\fR
160 may be used to determine the remote username of the session identified by the specified session identifier\&. The returned string needs to be freed with the libc
161 \fBfree\fR(3)
162 call after use\&. Note that this value is rarely known to the system, and even then should not be relied on\&.
163 .PP
164 \fBsd_session_get_tty()\fR
165 may be used to determine the TTY device of the session identified by the specified session identifier\&. The returned string needs to be freed with the libc
166 \fBfree\fR(3)
167 call after use\&.
168 .PP
169 \fBsd_session_get_vt()\fR
170 may be used to determine the VT number of the session identified by the specified session identifier\&. This function will return an error if the seat does not support VTs\&.
171 .PP
172 If the
173 \fIsession\fR
174 parameter of any of these functions is passed as
175 \fBNULL\fR, the operation is executed for the session the calling process is a member of, if there is any\&.
176 .SH "RETURN VALUE"
177 .PP
178 If the test succeeds,
179 \fBsd_session_is_active()\fR
180 and
181 \fBsd_session_is_remote()\fR
182 return a positive integer; if it fails, 0\&. On success,
183 \fBsd_session_get_state()\fR,
184 \fBsd_session_get_uid()\fR,
185 \fBsd_session_get_username()\fR,
186 \fBsd_session_get_seat()\fR,
187 \fBsd_session_get_service()\fR,
188 \fBsd_session_get_type()\fR,
189 \fBsd_session_get_class()\fR,
190 \fBsd_session_get_display()\fR,
191 \fBsd_session_get_leader()\fR,
192 \fBsd_session_get_remote_user()\fR,
193 \fBsd_session_get_remote_host()\fR
194 and
195 \fBsd_session_get_tty()\fR
196 return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
197 .SS "Errors"
198 .PP
199 Returned errors may indicate the following problems:
200 .PP
201 \fB\-ENXIO\fR
202 .RS 4
203 The specified session does not exist\&.
204 .RE
205 .PP
206 \fB\-ENODATA\fR
207 .RS 4
208 The given field is not specified for the described session\&.
209 .RE
210 .PP
211 \fB\-EINVAL\fR
212 .RS 4
213 An input parameter was invalid (out of range, or
214 \fBNULL\fR, where that is not accepted)\&.
215 .RE
216 .PP
217 \fB\-ENOMEM\fR
218 .RS 4
219 Memory allocation failed\&.
220 .RE
221 .SH "NOTES"
222 .PP
223 Functions described here are available as a shared library, which can be compiled against and linked to with the
224 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
225 file\&.
226 .PP
227 The code described here uses
228 \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
229 \fBsetenv\fR(3)
230 from a parallel thread\&. It is recommended to only do calls to
231 \fBsetenv()\fR
232 from an early phase of the program when no other threads have been started\&.
233 .SH "HISTORY"
234 .PP
235 \fBsd_session_get_state()\fR
236 was added in version 186\&.
237 .PP
238 \fBsd_session_get_tty()\fR
239 was added in version 198\&.
240 .PP
241 \fBsd_session_get_vt()\fR
242 was added in version 207\&.
243 .PP
244 \fBsd_session_is_remote()\fR,
245 \fBsd_session_get_remote_host()\fR, and
246 \fBsd_session_get_remote_user()\fR
247 were added in version 209\&.
248 .PP
249 \fBsd_session_get_desktop()\fR
250 was added in version 217\&.
251 .PP
252 \fBsd_session_get_username()\fR,
253 \fBsd_session_get_start_time()\fR, and
254 \fBsd_session_get_leader()\fR
255 were added in version 254\&.
256 .SH "SEE ALSO"
257 .PP
258 \fBsystemd\fR(1), \fBsd-login\fR(3), \fBsd_pid_get_session\fR(3)
259 .SH "NOTES"
260 .IP " 1." 4
261 Desktop Entry Specification
262 .RS 4
263 \%https://standards.freedesktop.org/desktop-entry-spec/latest/
264 .RE