summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-02-14 21:54:00 +0100
committerLennart Poettering <lennart@poettering.net>2012-02-14 21:54:00 +0100
commit51f58f083a9454599080dc01d7740cf097f48920 (patch)
tree69cc8b34ee3e74280e7e90bc773d2a48c2b056a2 /src
parent55efac6cbcea0d8edda9c6820620ceb390009e7a (diff)
login: add new sd_session_get_type() and sd_session_get_class API calls
Diffstat (limited to 'src')
-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
4 files changed, 38 insertions, 28 deletions
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);