| 1 |
'\" t |
| 2 |
.TH "SD_SESSION_IS_ACTIVE" "3" "" "systemd 261~rc3" "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, sd_session_get_extra_device_access \- 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 |
.HP \w'int\ sd_session_get_extra_device_access('u |
| 66 |
.BI "int sd_session_get_extra_device_access(const\ char\ *" "session" ", char\ ***" "ret_ids" ");" |
| 67 |
.SH "DESCRIPTION" |
| 68 |
.PP |
| 69 |
\fBsd_session_is_active()\fR |
| 70 |
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\&. |
| 71 |
.PP |
| 72 |
\fBsd_session_is_remote()\fR |
| 73 |
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\&. |
| 74 |
.PP |
| 75 |
\fBsd_session_get_state()\fR |
| 76 |
may be used to determine the state of the session identified by the specified session identifier\&. The following states are currently known: |
| 77 |
"online" |
| 78 |
(session logged in, but session not active, i\&.e\&. not in the foreground), |
| 79 |
"active" |
| 80 |
(session logged in and active, i\&.e\&. in the foreground), |
| 81 |
"closing" |
| 82 |
(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 |
| 83 |
\fBsd_session_is_active()\fR\&. The returned string needs to be freed with the libc |
| 84 |
\fBfree\fR(3) |
| 85 |
call after use\&. |
| 86 |
.PP |
| 87 |
\fBsd_session_get_uid()\fR |
| 88 |
may be used to determine the user identifier of the Unix user the session identified by the specified session identifier belongs to\&. |
| 89 |
.PP |
| 90 |
\fBsd_session_get_username()\fR |
| 91 |
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 |
| 92 |
\fBfree\fR(3) |
| 93 |
call after use\&. |
| 94 |
.PP |
| 95 |
\fBsd_session_get_seat()\fR |
| 96 |
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 |
| 97 |
\fB\-ENODATA\fR) for them\&. The returned string needs to be freed with the libc |
| 98 |
\fBfree\fR(3) |
| 99 |
call after use\&. |
| 100 |
.PP |
| 101 |
\fBsd_session_get_start_time()\fR |
| 102 |
may be used to determine the start time of the session identified by the specified session identifier belongs to\&. The |
| 103 |
\fIusec\fR |
| 104 |
is in microseconds since the epoch (\fBCLOCK_REALTIME\fR)\&. |
| 105 |
.PP |
| 106 |
\fBsd_session_get_service()\fR |
| 107 |
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 |
| 108 |
\fBfree\fR(3) |
| 109 |
call after use\&. |
| 110 |
.PP |
| 111 |
\fBsd_session_get_type()\fR |
| 112 |
may be used to determine the type of the session identified by the specified session identifier\&. The returned string is one of |
| 113 |
"x11", |
| 114 |
"wayland", |
| 115 |
"tty", |
| 116 |
"mir" |
| 117 |
or |
| 118 |
"unspecified" |
| 119 |
and needs to be freed with the libc |
| 120 |
\fBfree\fR(3) |
| 121 |
call after use\&. |
| 122 |
.PP |
| 123 |
\fBsd_session_get_class()\fR |
| 124 |
may be used to determine the class of the session identified by the specified session identifier\&. The returned string is one of |
| 125 |
"user", |
| 126 |
"user\-early", |
| 127 |
"user\-light", |
| 128 |
"user\-early\-light", |
| 129 |
"user\-incomplete", |
| 130 |
"greeter", |
| 131 |
"lock\-screen", |
| 132 |
"background", |
| 133 |
"background\-light", |
| 134 |
"manager" |
| 135 |
or |
| 136 |
"manager\-early" |
| 137 |
and needs to be freed with the libc |
| 138 |
\fBfree\fR(3) |
| 139 |
call after use\&. |
| 140 |
.PP |
| 141 |
\fBsd_session_get_desktop()\fR |
| 142 |
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 |
| 143 |
\fI$XDG_CURRENT_DESKTOP\fR, as defined by the |
| 144 |
\m[blue]\fBDesktop Entry Specification\fR\m[]\&\s-2\u[1]\d\s+2\&. The returned string needs to be freed with the libc |
| 145 |
\fBfree\fR(3) |
| 146 |
call after use\&. |
| 147 |
.PP |
| 148 |
\fBsd_session_get_display()\fR |
| 149 |
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 |
| 150 |
\fBfree\fR(3) |
| 151 |
call after use\&. |
| 152 |
.PP |
| 153 |
\fBsd_session_get_leader()\fR |
| 154 |
may be used to determine the PID of the leader of the session identified by the specified session identifier\&. |
| 155 |
.PP |
| 156 |
\fBsd_session_get_remote_host()\fR |
| 157 |
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 |
| 158 |
\fBfree\fR(3) |
| 159 |
call after use\&. |
| 160 |
.PP |
| 161 |
\fBsd_session_get_remote_user()\fR |
| 162 |
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 |
| 163 |
\fBfree\fR(3) |
| 164 |
call after use\&. Note that this value is rarely known to the system, and even then should not be relied on\&. |
| 165 |
.PP |
| 166 |
\fBsd_session_get_tty()\fR |
| 167 |
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 |
| 168 |
\fBfree\fR(3) |
| 169 |
call after use\&. |
| 170 |
.PP |
| 171 |
\fBsd_session_get_vt()\fR |
| 172 |
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\&. |
| 173 |
.PP |
| 174 |
\fBsd_session_get_extra_device_access()\fR |
| 175 |
may be used to determine which additional hardware devices the session is granted access to\&. For every |
| 176 |
"\fIID\fR" |
| 177 |
in the list, the session is granted access to all devices tagged with |
| 178 |
"xaccess\-\fIID\fR" |
| 179 |
in udev\&. |
| 180 |
.PP |
| 181 |
If the |
| 182 |
\fIsession\fR |
| 183 |
parameter of any of these functions is passed as |
| 184 |
\fBNULL\fR, the operation is executed for the session the calling process is a member of, if there is any\&. |
| 185 |
.SH "RETURN VALUE" |
| 186 |
.PP |
| 187 |
If the test succeeds, |
| 188 |
\fBsd_session_is_active()\fR |
| 189 |
and |
| 190 |
\fBsd_session_is_remote()\fR |
| 191 |
return a positive integer; if it fails, 0\&. On success, |
| 192 |
\fBsd_session_get_state()\fR, |
| 193 |
\fBsd_session_get_uid()\fR, |
| 194 |
\fBsd_session_get_username()\fR, |
| 195 |
\fBsd_session_get_seat()\fR, |
| 196 |
\fBsd_session_get_service()\fR, |
| 197 |
\fBsd_session_get_type()\fR, |
| 198 |
\fBsd_session_get_class()\fR, |
| 199 |
\fBsd_session_get_display()\fR, |
| 200 |
\fBsd_session_get_leader()\fR, |
| 201 |
\fBsd_session_get_remote_user()\fR, |
| 202 |
\fBsd_session_get_remote_host()\fR, |
| 203 |
\fBsd_session_get_tty()\fR, and |
| 204 |
\fBsd_session_get_extra_device_access()\fR |
| 205 |
return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&. |
| 206 |
.SS "Errors" |
| 207 |
.PP |
| 208 |
Returned errors may indicate the following problems: |
| 209 |
.PP |
| 210 |
\fB\-ENXIO\fR |
| 211 |
.RS 4 |
| 212 |
The specified session does not exist\&. |
| 213 |
.RE |
| 214 |
.PP |
| 215 |
\fB\-ENODATA\fR |
| 216 |
.RS 4 |
| 217 |
The given field is not specified for the described session\&. |
| 218 |
.RE |
| 219 |
.PP |
| 220 |
\fB\-EINVAL\fR |
| 221 |
.RS 4 |
| 222 |
An input parameter was invalid (out of range, or |
| 223 |
\fBNULL\fR, where that is not accepted)\&. |
| 224 |
.RE |
| 225 |
.PP |
| 226 |
\fB\-ENOMEM\fR |
| 227 |
.RS 4 |
| 228 |
Memory allocation failed\&. |
| 229 |
.RE |
| 230 |
.SH "NOTES" |
| 231 |
.PP |
| 232 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 233 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 234 |
file\&. |
| 235 |
.PP |
| 236 |
The code described here uses |
| 237 |
\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 |
| 238 |
\fBsetenv\fR(3) |
| 239 |
from a parallel thread\&. It is recommended to only do calls to |
| 240 |
\fBsetenv()\fR |
| 241 |
from an early phase of the program when no other threads have been started\&. |
| 242 |
.SH "HISTORY" |
| 243 |
.PP |
| 244 |
\fBsd_session_get_state()\fR |
| 245 |
was added in version 186\&. |
| 246 |
.PP |
| 247 |
\fBsd_session_get_tty()\fR |
| 248 |
was added in version 198\&. |
| 249 |
.PP |
| 250 |
\fBsd_session_get_vt()\fR |
| 251 |
was added in version 207\&. |
| 252 |
.PP |
| 253 |
\fBsd_session_is_remote()\fR, |
| 254 |
\fBsd_session_get_remote_host()\fR, and |
| 255 |
\fBsd_session_get_remote_user()\fR |
| 256 |
were added in version 209\&. |
| 257 |
.PP |
| 258 |
\fBsd_session_get_desktop()\fR |
| 259 |
was added in version 217\&. |
| 260 |
.PP |
| 261 |
\fBsd_session_get_username()\fR, |
| 262 |
\fBsd_session_get_start_time()\fR, and |
| 263 |
\fBsd_session_get_leader()\fR |
| 264 |
were added in version 254\&. |
| 265 |
.PP |
| 266 |
\fBsd_session_get_extra_device_access()\fR |
| 267 |
was added in version 260\&. |
| 268 |
.SH "SEE ALSO" |
| 269 |
.PP |
| 270 |
\fBsystemd\fR(1), \fBsd-login\fR(3), \fBsd_pid_get_session\fR(3) |
| 271 |
.SH "NOTES" |
| 272 |
.IP " 1." 4 |
| 273 |
Desktop Entry Specification |
| 274 |
.RS 4 |
| 275 |
\%https://standards.freedesktop.org/desktop-entry-spec/latest/ |
| 276 |
.RE |