1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-21 22:04:01 +03:00

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.
This commit is contained in:
Lennart Poettering 2013-04-04 17:38:08 +02:00
parent ee531d949c
commit dace83cbd0
6 changed files with 60 additions and 20 deletions

View File

@ -115,11 +115,11 @@
below.</para> below.</para>
<para><function>sd_journal_get_events()</function> <para><function>sd_journal_get_events()</function>
will return the will return the <function>poll()</function> mask to
<citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry> wait for. This function will return a combination of
mask to wait for. This function will return a <literal>POLLIN</literal> and
combination of POLLIN and POLLOUT and similar to fill <literal>POLLOUT</literal> and similar to fill into
into the <literal>.events</literal> field of the <literal>.events</literal> field of
<literal>struct pollfd</literal>.</para> <literal>struct pollfd</literal>.</para>
<para><function>sd_journal_reliable_fd()</function> <para><function>sd_journal_reliable_fd()</function>
@ -134,7 +134,7 @@
<function>sd_journal_get_fd()</function> are <function>sd_journal_get_fd()</function> are
sufficient as only source for wake-ups.</para> sufficient as only source for wake-ups.</para>
<para>After each <literal>poll()</literal> wake-up <para>After each <function>poll()</function> wake-up
<function>sd_journal_process()</function> needs to be <function>sd_journal_process()</function> needs to be
called to process events. This call will also indicate called to process events. This call will also indicate
what kind of change has been detected (see below; note what kind of change has been detected (see below; note
@ -169,9 +169,9 @@
errno-style error code.</para> errno-style error code.</para>
<para><function>sd_journal_get_events()</function> <para><function>sd_journal_get_events()</function>
returns a combination of POLLIN, POLLOUT and suchlike returns a combination of <literal>POLLIN</literal>,
on success or a negative errno-style error <literal>POLLOUT</literal> and suchlike on success or
code.</para> a negative errno-style error code.</para>
<para><function>sd_journal_reliable_fd()</function> <para><function>sd_journal_reliable_fd()</function>
returns a positive integer if the file descriptor returns a positive integer if the file descriptor

View File

@ -47,6 +47,7 @@
<refname>sd_login_monitor_unref</refname> <refname>sd_login_monitor_unref</refname>
<refname>sd_login_monitor_flush</refname> <refname>sd_login_monitor_flush</refname>
<refname>sd_login_monitor_get_fd</refname> <refname>sd_login_monitor_get_fd</refname>
<refname>sd_login_monitor_get_events</refname>
<refname>sd_login_monitor</refname> <refname>sd_login_monitor</refname>
<refpurpose>Monitor login sessions, seats and users</refpurpose> <refpurpose>Monitor login sessions, seats and users</refpurpose>
</refnamediv> </refnamediv>
@ -76,6 +77,11 @@
<paramdef>sd_login_monitor* <parameter>m</parameter></paramdef> <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
</funcprototype> </funcprototype>
<funcprototype>
<funcdef>int <function>sd_login_monitor_get_events</function></funcdef>
<paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
</funcprototype>
</funcsynopsis> </funcsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -122,14 +128,24 @@
application defined event loop, based around application defined event loop, based around
<citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry> <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
or a similar interface. The application should include or a similar interface. The application should include
the returned file descriptor as wake up source for the returned file descriptor as wake-up source for the
POLLIN events. Whenever a wake-up is triggered the events mask returned by
file descriptor needs to be reset via <function>sd_login_monitor_get_events()</function>. Whenever
a wake-up is triggered the file descriptor needs to be
reset via
<function>sd_login_monitor_flush()</function>. An <function>sd_login_monitor_flush()</function>. An
application needs to reread the login state with a application needs to reread the login state with a
function like function like
<citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry> <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
or similar to determine what changed.</para> or similar to determine what changed.</para>
<para><function>sd_login_monitor_get_events()</function>
will return the <function>poll()</function> mask to
wait for. This function will return a combination of
<literal>POLLIN</literal>, <literal>POLLOUT</literal>
and similar to fill into the
<literal>.events</literal> field of <literal>struct
pollfd</literal>.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
@ -140,8 +156,12 @@
<function>sd_login_monitor_flush()</function> return 0 <function>sd_login_monitor_flush()</function> return 0
or a positive integer. On success or a positive integer. On success
<function>sd_login_monitor_get_fd()</function> returns <function>sd_login_monitor_get_fd()</function> returns
a Unix file descriptor. On failure, these calls return a Unix file descriptor. On success
a negative errno-style error code.</para> <function>sd_login_monitor_get_events()</function>
returns a combination of <literal>POLLIN</literal>,
<literal>POLLOUT</literal> and suchlike. On failure,
these calls return a negative errno-style error
code.</para>
<para><function>sd_login_monitor_unref()</function> <para><function>sd_login_monitor_unref()</function>
always returns NULL.</para> always returns NULL.</para>
@ -151,10 +171,12 @@
<title>Notes</title> <title>Notes</title>
<para>The <function>sd_login_monitor_new()</function>, <para>The <function>sd_login_monitor_new()</function>,
<function>sd_login_monitor_unref()</function>, <function>sd_login_monitor_flush()</function> and <function>sd_login_monitor_unref()</function>,
<function>sd_login_monitor_get_fd()</function> interfaces <function>sd_login_monitor_flush()</function>,
are available as shared library, which can be compiled <function>sd_login_monitor_get_fd()</function> and
and linked to with the <function>sd_login_monitor_get_events()</function>
interfaces are available as shared library, which can
be compiled and linked to with the
<literal>libsystemd-login</literal> <literal>libsystemd-login</literal>
<citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
file.</para> file.</para>
@ -166,7 +188,8 @@
<para> <para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry> <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
</para> </para>
</refsect1> </refsect1>

View File

@ -58,3 +58,8 @@ LIBSYSTEMD_LOGIN_198 {
global: global:
sd_session_get_tty; sd_session_get_tty;
} LIBSYSTEMD_LOGIN_186; } LIBSYSTEMD_LOGIN_186;
LIBSYSTEMD_LOGIN_201 {
global:
sd_login_monitor_get_events;
} LIBSYSTEMD_LOGIN_198;

View File

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <sys/poll.h>
#include "util.h" #include "util.h"
#include "cgroup-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); return MONITOR_TO_FD(m);
} }
_public_ int sd_login_monitor_get_events(sd_login_monitor *m) {
if (!m)
return -EINVAL;
return POLLIN;
}

View File

@ -185,7 +185,7 @@ int main(int argc, char* argv[]) {
zero(pollfd); zero(pollfd);
pollfd.fd = sd_login_monitor_get_fd(m); 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++) { for (n = 0; n < 5; n++) {
r = poll(&pollfd, 1, -1); r = poll(&pollfd, 1, -1);

View File

@ -156,6 +156,9 @@ int sd_login_monitor_flush(sd_login_monitor *m);
/* Get FD from monitor */ /* Get FD from monitor */
int sd_login_monitor_get_fd(sd_login_monitor *m); 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 #ifdef __cplusplus
} }
#endif #endif