1SD_SESSION_IS_ACTIVE(3) sd_session_is_active SD_SESSION_IS_ACTIVE(3)
2
3
4
6 sd_session_is_active, sd_session_is_remote, sd_session_get_state,
7 sd_session_get_uid, sd_session_get_seat, sd_session_get_service,
8 sd_session_get_type, sd_session_get_class, sd_session_get_desktop,
9 sd_session_get_display, sd_session_get_tty, sd_session_get_vt,
10 sd_session_get_remote_host, sd_session_get_remote_user - Determine
11 state of a specific session
12
14 #include <systemd/sd-login.h>
15
16 int sd_session_is_active(const char *session);
17
18 int sd_session_is_remote(const char *session);
19
20 int sd_session_get_state(const char *session, char **state);
21
22 int sd_session_get_uid(const char *session, uid_t *uid);
23
24 int sd_session_get_seat(const char *session, char **seat);
25
26 int sd_session_get_service(const char *session, char **service);
27
28 int sd_session_get_type(const char *session, char **type);
29
30 int sd_session_get_class(const char *session, char **class);
31
32 int sd_session_get_desktop(const char *session, char **desktop);
33
34 int sd_session_get_display(const char *session, char **display);
35
36 int sd_session_get_remote_host(const char *session,
37 char **remote_host);
38
39 int sd_session_get_remote_user(const char *session,
40 char **remote_user);
41
42 int sd_session_get_tty(const char *session, char **tty);
43
44 int sd_session_get_vt(const char *session, unsigned int *vt);
45
47 sd_session_is_active() may be used to determine whether the session
48 identified by the specified session identifier is currently active
49 (i.e. currently in the foreground and available for user input) or not.
50
51 sd_session_is_remote() may be used to determine whether the session
52 identified by the specified session identifier is a remote session
53 (i.e. its remote host is known) or not.
54
55 sd_session_get_state() may be used to determine the state of the
56 session identified by the specified session identifier. The following
57 states are currently known: "online" (session logged in, but session
58 not active, i.e. not in the foreground), "active" (session logged in
59 and active, i.e. in the foreground), "closing" (session nominally
60 logged out, but some processes belonging to it are still around). In
61 the future additional states might be defined, client code should be
62 written to be robust in regards to additional state strings being
63 returned. This function is a more generic version of
64 sd_session_is_active(). The returned string needs to be freed with the
65 libc free(3) call after use.
66
67 sd_session_get_uid() may be used to determine the user identifier of
68 the Unix user the session identified by the specified session
69 identifier belongs to.
70
71 sd_session_get_seat() may be used to determine the seat identifier of
72 the seat the session identified by the specified session identifier
73 belongs to. Note that not all sessions are attached to a seat, this
74 call will fail (returning -ENODATA) for them. The returned string needs
75 to be freed with the libc free(3) call after use.
76
77 sd_session_get_service() may be used to determine the name of the
78 service (as passed during PAM session setup) that registered the
79 session identified by the specified session identifier. The returned
80 string needs to be freed with the libc free(3) call after use.
81
82 sd_session_get_type() may be used to determine the type of the session
83 identified by the specified session identifier. The returned string is
84 one of "x11", "wayland", "tty", "mir" or "unspecified" and needs to be
85 freed with the libc free(3) call after use.
86
87 sd_session_get_class() may be used to determine the class of the
88 session identified by the specified session identifier. The returned
89 string is one of "user", "greeter", "lock-screen", or "background" and
90 needs to be freed with the libc free(3) call after use.
91
92 sd_session_get_desktop() may be used to determine the brand of the
93 desktop running on the session identified by the specified session
94 identifier. This field can be set freely by desktop environments and
95 does not follow any special formatting. However, desktops are strongly
96 recommended to use the same identifiers and capitalization as for
97 $XDG_CURRENT_DESKTOP, as defined by the Desktop Entry Specification[1].
98 The returned string needs to be freed with the libc free(3) call after
99 use.
100
101 sd_session_get_display() may be used to determine the X11 display of
102 the session identified by the specified session identifier. The
103 returned string needs to be freed with the libc free(3) call after use.
104
105 sd_session_get_remote_host() may be used to determine the remote
106 hostname of the session identified by the specified session identifier.
107 The returned string needs to be freed with the libc free(3) call after
108 use.
109
110 sd_session_get_remote_user() may be used to determine the remote
111 username of the session identified by the specified session identifier.
112 The returned string needs to be freed with the libc free(3) call after
113 use. Note that this value is rarely known to the system, and even then
114 should not be relied on.
115
116 sd_session_get_tty() may be used to determine the TTY device of the
117 session identified by the specified session identifier. The returned
118 string needs to be freed with the libc free(3) call after use.
119
120 sd_session_get_vt() may be used to determine the VT number of the
121 session identified by the specified session identifier. This function
122 will return an error if the seat does not support VTs.
123
124 If the session parameter of any of these functions is passed as NULL,
125 the operation is executed for the session the calling process is a
126 member of, if there is any.
127
129 If the test succeeds, sd_session_is_active() and sd_session_is_remote()
130 return a positive integer; if it fails, 0. On success,
131 sd_session_get_state(), sd_session_get_uid(), sd_session_get_seat(),
132 sd_session_get_service(), sd_session_get_type(),
133 sd_session_get_class(), sd_session_get_display(),
134 sd_session_get_remote_user(), sd_session_get_remote_host() and
135 sd_session_get_tty() return 0 or a positive integer. On failure, these
136 calls return a negative errno-style error code.
137
138 Errors
139 Returned errors may indicate the following problems:
140
141 -ENXIO
142 The specified session does not exist.
143
144 -ENODATA
145 The given field is not specified for the described session.
146
147 -EINVAL
148 An input parameter was invalid (out of range, or NULL, where that
149 is not accepted).
150
151 -ENOMEM
152 Memory allocation failed.
153
155 These APIs are implemented as a shared library, which can be compiled
156 and linked to with the libsystemd pkg-config(1) file.
157
159 systemd(1), sd-login(3), sd_pid_get_session(3)
160
162 1. Desktop Entry Specification
163 https://standards.freedesktop.org/desktop-entry-spec/latest/
164
165
166
167systemd 253 SD_SESSION_IS_ACTIVE(3)