Debian Codegraph @

upstream/debian-trixie/man3/sd_session_is_active.3

raw
1 '\" t
2 .TH "SD_SESSION_IS_ACTIVE" "3" "" "systemd 257.13" "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\-incomplete",
126 "greeter",
127 "lock\-screen",
128 "background",
129 "background\-light",
130 "manager"
131 or
132 "manager\-early"
133 and needs to be freed with the libc
134 \fBfree\fR(3)
135 call after use\&.
136 .PP
137 \fBsd_session_get_desktop()\fR
138 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
139 \fI$XDG_CURRENT_DESKTOP\fR, as defined by the
140 \m[blue]\fBDesktop Entry Specification\fR\m[]\&\s-2\u[1]\d\s+2\&. The returned string needs to be freed with the libc
141 \fBfree\fR(3)
142 call after use\&.
143 .PP
144 \fBsd_session_get_display()\fR
145 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
146 \fBfree\fR(3)
147 call after use\&.
148 .PP
149 \fBsd_session_get_leader()\fR
150 may be used to determine the PID of the leader of the session identified by the specified session identifier\&.
151 .PP
152 \fBsd_session_get_remote_host()\fR
153 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
154 \fBfree\fR(3)
155 call after use\&.
156 .PP
157 \fBsd_session_get_remote_user()\fR
158 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
159 \fBfree\fR(3)
160 call after use\&. Note that this value is rarely known to the system, and even then should not be relied on\&.
161 .PP
162 \fBsd_session_get_tty()\fR
163 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
164 \fBfree\fR(3)
165 call after use\&.
166 .PP
167 \fBsd_session_get_vt()\fR
168 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\&.
169 .PP
170 If the
171 \fIsession\fR
172 parameter of any of these functions is passed as
173 \fBNULL\fR, the operation is executed for the session the calling process is a member of, if there is any\&.
174 .SH "RETURN VALUE"
175 .PP
176 If the test succeeds,
177 \fBsd_session_is_active()\fR
178 and
179 \fBsd_session_is_remote()\fR
180 return a positive integer; if it fails, 0\&. On success,
181 \fBsd_session_get_state()\fR,
182 \fBsd_session_get_uid()\fR,
183 \fBsd_session_get_username()\fR,
184 \fBsd_session_get_seat()\fR,
185 \fBsd_session_get_service()\fR,
186 \fBsd_session_get_type()\fR,
187 \fBsd_session_get_class()\fR,
188 \fBsd_session_get_display()\fR,
189 \fBsd_session_get_leader()\fR,
190 \fBsd_session_get_remote_user()\fR,
191 \fBsd_session_get_remote_host()\fR
192 and
193 \fBsd_session_get_tty()\fR
194 return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
195 .SS "Errors"
196 .PP
197 Returned errors may indicate the following problems:
198 .PP
199 \fB\-ENXIO\fR
200 .RS 4
201 The specified session does not exist\&.
202 .RE
203 .PP
204 \fB\-ENODATA\fR
205 .RS 4
206 The given field is not specified for the described session\&.
207 .RE
208 .PP
209 \fB\-EINVAL\fR
210 .RS 4
211 An input parameter was invalid (out of range, or
212 \fBNULL\fR, where that is not accepted)\&.
213 .RE
214 .PP
215 \fB\-ENOMEM\fR
216 .RS 4
217 Memory allocation failed\&.
218 .RE
219 .SH "NOTES"
220 .PP
221 Functions described here are available as a shared library, which can be compiled against and linked to with the
222 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
223 file\&.
224 .PP
225 The code described here uses
226 \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
227 \fBsetenv\fR(3)
228 from a parallel thread\&. It is recommended to only do calls to
229 \fBsetenv()\fR
230 from an early phase of the program when no other threads have been started\&.
231 .SH "HISTORY"
232 .PP
233 \fBsd_session_get_state()\fR
234 was added in version 186\&.
235 .PP
236 \fBsd_session_get_tty()\fR
237 was added in version 198\&.
238 .PP
239 \fBsd_session_get_vt()\fR
240 was added in version 207\&.
241 .PP
242 \fBsd_session_is_remote()\fR,
243 \fBsd_session_get_remote_host()\fR, and
244 \fBsd_session_get_remote_user()\fR
245 were added in version 209\&.
246 .PP
247 \fBsd_session_get_desktop()\fR
248 was added in version 217\&.
249 .PP
250 \fBsd_session_get_username()\fR,
251 \fBsd_session_get_start_time()\fR, and
252 \fBsd_session_get_leader()\fR
253 were added in version 254\&.
254 .SH "SEE ALSO"
255 .PP
256 \fBsystemd\fR(1), \fBsd-login\fR(3), \fBsd_pid_get_session\fR(3)
257 .SH "NOTES"
258 .IP " 1." 4
259 Desktop Entry Specification
260 .RS 4
261 \%https://standards.freedesktop.org/desktop-entry-spec/latest/
262 .RE