From: Lennart Poettering Date: Thu, 4 Apr 2013 15:38:08 +0000 (+0200) Subject: login: add new public API call sd_login_monitor_get_events() to get poll() flags... X-Git-Tag: v201~68 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=dace83cbd0c2212fc0e25d36d50711b19f14b1b6 login: add new public API call sd_login_monitor_get_events() to get poll() flags to wait for We should keep our options open, so that we can watch for POLLOUT later on if we wish to. CUrrently this call will always return POLLIN however. --- diff --git a/man/sd_journal_get_fd.xml b/man/sd_journal_get_fd.xml index e57431ea9..f29aeaab2 100644 --- a/man/sd_journal_get_fd.xml +++ b/man/sd_journal_get_fd.xml @@ -115,11 +115,11 @@ below. sd_journal_get_events() - will return the - poll2 - mask to wait for. This function will return a - combination of POLLIN and POLLOUT and similar to fill - into the .events field of + will return the poll() mask to + wait for. This function will return a combination of + POLLIN and + POLLOUT and similar to fill into + the .events field of struct pollfd. sd_journal_reliable_fd() @@ -134,7 +134,7 @@ sd_journal_get_fd() are sufficient as only source for wake-ups. - After each poll() wake-up + After each poll() wake-up sd_journal_process() needs to be called to process events. This call will also indicate what kind of change has been detected (see below; note @@ -169,9 +169,9 @@ errno-style error code. sd_journal_get_events() - returns a combination of POLLIN, POLLOUT and suchlike - on success or a negative errno-style error - code. + returns a combination of POLLIN, + POLLOUT and suchlike on success or + a negative errno-style error code. sd_journal_reliable_fd() returns a positive integer if the file descriptor diff --git a/man/sd_login_monitor_new.xml b/man/sd_login_monitor_new.xml index 2c4d05dcb..94428771a 100644 --- a/man/sd_login_monitor_new.xml +++ b/man/sd_login_monitor_new.xml @@ -47,6 +47,7 @@ sd_login_monitor_unref sd_login_monitor_flush sd_login_monitor_get_fd + sd_login_monitor_get_events sd_login_monitor Monitor login sessions, seats and users @@ -76,6 +77,11 @@ sd_login_monitor* m + + int sd_login_monitor_get_events + sd_login_monitor* m + + @@ -122,14 +128,24 @@ application defined event loop, based around poll2 or a similar interface. The application should include - the returned file descriptor as wake up source for - POLLIN events. Whenever a wake-up is triggered the - file descriptor needs to be reset via + the returned file descriptor as wake-up source for the + events mask returned by + sd_login_monitor_get_events(). Whenever + a wake-up is triggered the file descriptor needs to be + reset via sd_login_monitor_flush(). An application needs to reread the login state with a function like sd_get_seats3 or similar to determine what changed. + + sd_login_monitor_get_events() + will return the poll() mask to + wait for. This function will return a combination of + POLLIN, POLLOUT + and similar to fill into the + .events field of struct + pollfd. @@ -140,8 +156,12 @@ sd_login_monitor_flush() return 0 or a positive integer. On success sd_login_monitor_get_fd() returns - a Unix file descriptor. On failure, these calls return - a negative errno-style error code. + a Unix file descriptor. On success + sd_login_monitor_get_events() + returns a combination of POLLIN, + POLLOUT and suchlike. On failure, + these calls return a negative errno-style error + code. sd_login_monitor_unref() always returns NULL. @@ -151,10 +171,12 @@ Notes The sd_login_monitor_new(), - sd_login_monitor_unref(), sd_login_monitor_flush() and - sd_login_monitor_get_fd() interfaces - are available as shared library, which can be compiled - and linked to with the + sd_login_monitor_unref(), + sd_login_monitor_flush(), + sd_login_monitor_get_fd() and + sd_login_monitor_get_events() + interfaces are available as shared library, which can + be compiled and linked to with the libsystemd-login pkg-config1 file. @@ -166,7 +188,8 @@ systemd1, sd-login3, - sd_get_seats3 + sd_get_seats3, + poll2 diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 272b0e2b5..55a828773 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -58,3 +58,8 @@ LIBSYSTEMD_LOGIN_198 { global: sd_session_get_tty; } LIBSYSTEMD_LOGIN_186; + +LIBSYSTEMD_LOGIN_201 { +global: + sd_login_monitor_get_events; +} LIBSYSTEMD_LOGIN_198; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 8867e8c8e..861a57166 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "util.h" #include "cgroup-util.h" @@ -797,3 +798,11 @@ _public_ int sd_login_monitor_get_fd(sd_login_monitor *m) { return MONITOR_TO_FD(m); } + +_public_ int sd_login_monitor_get_events(sd_login_monitor *m) { + + if (!m) + return -EINVAL; + + return POLLIN; +} diff --git a/src/login/test-login.c b/src/login/test-login.c index 159ff3efc..f63912963 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -185,7 +185,7 @@ int main(int argc, char* argv[]) { zero(pollfd); pollfd.fd = sd_login_monitor_get_fd(m); - pollfd.events = POLLIN; + pollfd.events = sd_login_monitor_get_events(m); for (n = 0; n < 5; n++) { r = poll(&pollfd, 1, -1); diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index 3746b45cf..57255bd4a 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -156,6 +156,9 @@ int sd_login_monitor_flush(sd_login_monitor *m); /* Get FD from monitor */ int sd_login_monitor_get_fd(sd_login_monitor *m); +/* Get poll() mask to monitor */ +int sd_login_monitor_get_events(sd_login_monitor *m); + #ifdef __cplusplus } #endif