summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--src/login/libsystemd-login.sym6
-rw-r--r--src/login/sd-login.c40
-rw-r--r--src/login/test-login.c14
-rw-r--r--src/systemd/sd-login.h6
5 files changed, 38 insertions, 30 deletions
diff --git a/TODO b/TODO
index 7693067d47..b6f7f006e8 100644
--- a/TODO
+++ b/TODO
@@ -28,8 +28,6 @@ Features:
* Possibly, detect whether SysV init scripts can do reloading by looking for "echo Usage:" lines
-* Add XDG_SESSION_CLASS
-
* figure out whether we should leave dbus around during shutdown
* support closing all fds via RLIMIT_NOFILE instead of /proc, in order to make chroot stuff work.
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
index 3100c17662..2ae376da44 100644
--- a/src/login/libsystemd-login.sym
+++ b/src/login/libsystemd-login.sym
@@ -39,3 +39,9 @@ global:
sd_pid_get_unit;
sd_session_get_service;
} LIBSYSTEMD_LOGIN_31;
+
+LIBSYSTEMD_LOGIN_43 {
+global:
+ sd_session_get_type;
+ sd_session_get_class;
+} LIBSYSTEMD_LOGIN_38;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 5a03d614bb..c100a7b4f2 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -433,18 +433,18 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
return r;
}
-_public_ int sd_session_get_seat(const char *session, char **seat) {
+static int session_get_string(const char *session, const char *field, char **value) {
char *p, *s = NULL;
int r;
- if (!seat)
+ if (!value)
return -EINVAL;
r = file_of_session(session, &p);
if (r < 0)
return r;
- r = parse_env_file(p, NEWLINE, "SEAT", &s, NULL);
+ r = parse_env_file(p, NEWLINE, field, &s, NULL);
free(p);
if (r < 0) {
@@ -455,34 +455,24 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
if (isempty(s))
return -ENOENT;
- *seat = s;
+ *value = s;
return 0;
}
-_public_ int sd_session_get_service(const char *session, char **service) {
- char *p, *s = NULL;
- int r;
-
- if (!service)
- return -EINVAL;
-
- r = file_of_session(session, &p);
- if (r < 0)
- return r;
-
- r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
- free(p);
+_public_ int sd_session_get_seat(const char *session, char **seat) {
+ return session_get_string(session, "SEAT", seat);
+}
- if (r < 0) {
- free(s);
- return r;
- }
+_public_ int sd_session_get_service(const char *session, char **service) {
+ return session_get_string(session, "SERVICE", service);
+}
- if (isempty(s))
- return -ENOENT;
+_public_ int sd_session_get_type(const char *session, char **type) {
+ return session_get_string(session, "TYPE", type);
+}
- *service = s;
- return 0;
+_public_ int sd_session_get_class(const char *session, char **class) {
+ return session_get_string(session, "CLASS", class);
}
static int file_of_seat(const char *seat, char **_p) {
diff --git a/src/login/test-login.c b/src/login/test-login.c
index 4596721060..2aaa31f22f 100644
--- a/src/login/test-login.c
+++ b/src/login/test-login.c
@@ -30,7 +30,7 @@
int main(int argc, char* argv[]) {
int r, k;
uid_t u, u2;
- char *seat;
+ char *seat, *type, *class;
char *session;
char *state;
char *session2;
@@ -75,6 +75,14 @@ int main(int argc, char* argv[]) {
printf("uid = %lu\n", (unsigned long) u);
assert_se(u == u2);
+ assert_se(sd_session_get_type(session, &type) >= 0);
+ printf("type = %s\n", type);
+ free(type);
+
+ assert_se(sd_session_get_class(session, &class) >= 0);
+ printf("class = %s\n", class);
+ free(class);
+
assert_se(sd_session_get_seat(session, &seat) >= 0);
printf("seat = %s\n", seat);
@@ -125,13 +133,13 @@ int main(int argc, char* argv[]) {
printf("seats = %s\n", t);
free(t);
+ assert_se(sd_get_seats(NULL) == r);
+
r = sd_seat_get_active(NULL, &t, NULL);
assert_se(r >= 0);
printf("active session on current seat = %s\n", t);
free(t);
- assert_se(sd_get_seats(NULL) == r);
-
r = sd_get_sessions(&sessions);
assert_se(r >= 0);
assert_se(r == (int) strv_length(sessions));
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 7746c742ff..879e0744a8 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -90,6 +90,12 @@ int sd_session_get_seat(const char *session, char **seat);
/* Determine the (PAM) service name this session was registered by. */
int sd_session_get_service(const char *session, char **service);
+/* Determine the type of this session, i.e. one of "tty", "x11" or "unspecified". */
+int sd_session_get_type(const char *session, char **type);
+
+/* Determine the class of this session, i.e. one of "user", "greeter" or "lock-screen". */
+int sd_session_get_class(const char *session, char **class);
+
/* Return active session and user of seat */
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);