From 20747498c68575646fae88f4dd270fab219a25a6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Jun 2012 16:52:54 +0200 Subject: [PATCH] login: wrap CanTTY and CanGraphical seat attributes in libsystemd-login --- man/sd_seat_get_active.xml | 31 +++++++++++++++++++++++++++---- man/sd_session_is_active.xml | 16 ++++++++++++---- src/login/libsystemd-login.sym | 2 ++ src/login/sd-login.c | 16 ++++++++++++++-- src/login/test-login.c | 8 ++++++++ src/systemd/sd-login.h | 6 ++++++ 6 files changed, 69 insertions(+), 10 deletions(-) diff --git a/man/sd_seat_get_active.xml b/man/sd_seat_get_active.xml index 997c38890..82a1ea048 100644 --- a/man/sd_seat_get_active.xml +++ b/man/sd_seat_get_active.xml @@ -72,6 +72,16 @@ int sd_seat_can_multi_session const char* seat + + + int sd_seat_can_tty + const char* seat + + + + int sd_seat_can_graphical + const char* seat + @@ -111,6 +121,15 @@ sessions in parallel (whith only one being active at a time). + sd_seat_can_tty() may be + used to determine whether a specific seat provides TTY + functionality, i.e. is useful as a text console. + + sd_seat_can_graphical() may + be used to determine whether a specific seat provides + graphics functionality, i.e. is useful as a graphics + display. + If the seat parameter of any of these functions is passed as NULL the operation is executed for the seat of the session of the calling @@ -126,8 +145,10 @@ sd_seat_get_sessions() returns the number of entries in the session identifier array. If the test succeeds - sd_seat_can_multi_session returns - a positive integer, if it fails 0. On failure, these + sd_seat_can_multi_session, + sd_seat_can_tty and + sd_seat_can_graphical return a + positive integer, if it fails 0. On failure, these calls return a negative errno-style error code. @@ -135,8 +156,10 @@ Notes The sd_seat_get_active(), - sd_seat_get_sessions(), and - sd_seat_can_multi_session() interfaces + sd_seat_get_sessions(), + sd_seat_can_multi_session(), + sd_seat_can_tty() and + sd_seat_can_grapical() interfaces are available as shared library, which can be compiled and linked to with the libsystemd-login diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml index f9b287454..a14286aea 100644 --- a/man/sd_session_is_active.xml +++ b/man/sd_session_is_active.xml @@ -198,9 +198,13 @@ If the test succeeds sd_session_is_active() returns a positive integer, if it fails 0. On success + sd_session_get_state(), sd_session_get_uid(), - sd_session_get_service() and - sd_session_get_seat() return 0 or + sd_session_get_seat(), + sd_session_get_service(), + sd_session_get_type(), + sd_session_get_class() and + sd_session_get_display() return 0 or a positive integer. On failure, these calls return a negative errno-style error code. @@ -209,9 +213,13 @@ Notes The sd_session_is_active(), + sd_session_get_state(), sd_session_get_uid(), - sd_session_get_service() and - sd_session_get_seat() interfaces + sd_session_get_seat(), + sd_session_get_service(), + sd_session_get_type(), + sd_session_get_class() and + sd_session_get_display() interfaces are available as shared library, which can be compiled and linked to with the libsystemd-login diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 347e0730a..ff51be729 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -50,4 +50,6 @@ global: LIBSYSTEMD_LOGIN_186 { global: sd_session_get_state; + sd_seat_can_tty; + sd_seat_can_graphical; } LIBSYSTEMD_LOGIN_43; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 223e121be..1978a05dc 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -583,7 +583,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui return r; } -_public_ int sd_seat_can_multi_session(const char *seat) { +static int seat_get_can(const char *seat, const char *variable) { char *p, *s = NULL; int r; @@ -592,7 +592,7 @@ _public_ int sd_seat_can_multi_session(const char *seat) { return r; r = parse_env_file(p, NEWLINE, - "CAN_MULTI_SESSION", &s, + variable, &s, NULL); free(p); @@ -610,6 +610,18 @@ _public_ int sd_seat_can_multi_session(const char *seat) { return r; } +_public_ int sd_seat_can_multi_session(const char *seat) { + return seat_get_can(seat, "CAN_MULTI_SESSION"); +} + +_public_ int sd_seat_can_tty(const char *seat) { + return seat_get_can(seat, "CAN_TTY"); +} + +_public_ int sd_seat_can_graphical(const char *seat) { + return seat_get_can(seat, "CAN_GRAPHICAL"); +} + _public_ int sd_get_seats(char ***seats) { return get_files_in_directory("/run/systemd/seats/", seats); } diff --git a/src/login/test-login.c b/src/login/test-login.c index d0916ced6..159ff3efc 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -99,6 +99,14 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); printf("can do multi session = %s\n", yes_no(r)); + r = sd_seat_can_tty(seat); + assert_se(r >= 0); + printf("can do tty = %s\n", yes_no(r)); + + r = sd_seat_can_graphical(seat); + assert_se(r >= 0); + printf("can do graphical = %s\n", yes_no(r)); + assert_se(sd_uid_get_state(u, &state) >= 0); printf("state = %s\n", state); diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index bddc74e72..1a36a56b1 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -117,6 +117,12 @@ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **uid, unsign /* Return whether the seat is multi-session capable */ int sd_seat_can_multi_session(const char *seat); +/* Return whether the seat is TTY capable, i.e. suitable for showing console UIs */ +int sd_seat_can_tty(const char *seat); + +/* Return whether the seat is graphics capable, i.e. suitable for showing graphical UIs */ +int sd_seat_can_graphical(const char *seat); + /* Get all seats, store in *seats. Returns the number of seats. If * seats is NULL only returns number of seats. */ int sd_get_seats(char ***seats); -- 2.30.2