chiark / gitweb /
login: add new public API call sd_login_monitor_get_events() to get poll() flags...
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Apr 2013 15:38:08 +0000 (17:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 4 Apr 2013 15:38:08 +0000 (17:38 +0200)
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.

man/sd_journal_get_fd.xml
man/sd_login_monitor_new.xml
src/login/libsystemd-login.sym
src/login/sd-login.c
src/login/test-login.c
src/systemd/sd-login.h

index e57431ea9e3c964d7cdccacaf75c2641e7962e55..f29aeaab23e9b32b8398562920e2f7887cab00a0 100644 (file)
                 below.</para>
 
                 <para><function>sd_journal_get_events()</function>
                 below.</para>
 
                 <para><function>sd_journal_get_events()</function>
-                will return the
-                <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
-                mask to wait for. This function will return a
-                combination of POLLIN and POLLOUT and similar to fill
-                into the <literal>.events</literal> field of
+                will return the <function>poll()</function> mask to
+                wait for. This function will return a combination of
+                <literal>POLLIN</literal> and
+                <literal>POLLOUT</literal> and similar to fill into
+                the <literal>.events</literal> field of
                 <literal>struct pollfd</literal>.</para>
 
                 <para><function>sd_journal_reliable_fd()</function>
                 <literal>struct pollfd</literal>.</para>
 
                 <para><function>sd_journal_reliable_fd()</function>
                 <function>sd_journal_get_fd()</function> are
                 sufficient as only source for wake-ups.</para>
 
                 <function>sd_journal_get_fd()</function> are
                 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
                 called to process events. This call will also indicate
                 what kind of change has been detected (see below; note
                 <function>sd_journal_process()</function> needs to be
                 called to process events. This call will also indicate
                 what kind of change has been detected (see below; note
                 errno-style error code.</para>
 
                 <para><function>sd_journal_get_events()</function>
                 errno-style error code.</para>
 
                 <para><function>sd_journal_get_events()</function>
-                returns a combination of POLLIN, POLLOUT and suchlike
-                on success or a negative errno-style error
-                code.</para>
+                returns a combination of <literal>POLLIN</literal>,
+                <literal>POLLOUT</literal> and suchlike on success or
+                a negative errno-style error code.</para>
 
                 <para><function>sd_journal_reliable_fd()</function>
                 returns a positive integer if the file descriptor
 
                 <para><function>sd_journal_reliable_fd()</function>
                 returns a positive integer if the file descriptor
index 2c4d05dcb944bf3617dd145def2fa71b9ad1d038..94428771a86687db8094861eb077be467fccea34 100644 (file)
@@ -47,6 +47,7 @@
                 <refname>sd_login_monitor_unref</refname>
                 <refname>sd_login_monitor_flush</refname>
                 <refname>sd_login_monitor_get_fd</refname>
                 <refname>sd_login_monitor_unref</refname>
                 <refname>sd_login_monitor_flush</refname>
                 <refname>sd_login_monitor_get_fd</refname>
+                <refname>sd_login_monitor_get_events</refname>
                 <refname>sd_login_monitor</refname>
                 <refpurpose>Monitor login sessions, seats and users</refpurpose>
         </refnamediv>
                 <refname>sd_login_monitor</refname>
                 <refpurpose>Monitor login sessions, seats and users</refpurpose>
         </refnamediv>
                                 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
                         </funcprototype>
 
                                 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
                         </funcprototype>
 
+                        <funcprototype>
+                                <funcdef>int <function>sd_login_monitor_get_events</function></funcdef>
+                                <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
+                        </funcprototype>
+
                 </funcsynopsis>
         </refsynopsisdiv>
 
                 </funcsynopsis>
         </refsynopsisdiv>
 
                 application defined event loop, based around
                 <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
                 or a similar interface. The application should include
                 application defined event loop, based around
                 <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
                 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
+                <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
                 application needs to reread the login state with a
                 function like
                 <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 or similar to determine what changed.</para>
                 <function>sd_login_monitor_flush()</function>. An
                 application needs to reread the login state with a
                 function like
                 <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 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>
                 <function>sd_login_monitor_flush()</function> return 0
                 or a positive integer. On success
                 <function>sd_login_monitor_get_fd()</function> returns
                 <function>sd_login_monitor_flush()</function> return 0
                 or a positive integer. On success
                 <function>sd_login_monitor_get_fd()</function> returns
-                a Unix file descriptor. On failure, these calls return
-                a negative errno-style error code.</para>
+                a Unix file descriptor. On success
+                <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>
                 always returns NULL.</para>
 
                 <para><function>sd_login_monitor_unref()</function>
                 always returns NULL.</para>
                 <title>Notes</title>
 
                 <para>The <function>sd_login_monitor_new()</function>,
                 <title>Notes</title>
 
                 <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_get_fd()</function> interfaces
-                are available as shared library, which can be compiled
-                and linked to with the
+                <function>sd_login_monitor_unref()</function>,
+                <function>sd_login_monitor_flush()</function>,
+                <function>sd_login_monitor_get_fd()</function> and
+                <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>
                 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
                 file.</para>
                 <literal>libsystemd-login</literal>
                 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
                 file.</para>
                 <para>
                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                 <para>
                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</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>
         </refsect1>
 
                 </para>
         </refsect1>
 
index 272b0e2b5201be0bfafa72bf14b0c7d37b12796e..55a828773bca26472d3b3aa8dfe255c45a3244f2 100644 (file)
@@ -58,3 +58,8 @@ LIBSYSTEMD_LOGIN_198 {
 global:
         sd_session_get_tty;
 } LIBSYSTEMD_LOGIN_186;
 global:
         sd_session_get_tty;
 } LIBSYSTEMD_LOGIN_186;
+
+LIBSYSTEMD_LOGIN_201 {
+global:
+        sd_login_monitor_get_events;
+} LIBSYSTEMD_LOGIN_198;
index 8867e8c8eb7f309fd60f8f4f163425b2e5f8422a..861a57166dc7633de27dd54ce1d0568e6779adcc 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/inotify.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/inotify.h>
+#include <sys/poll.h>
 
 #include "util.h"
 #include "cgroup-util.h"
 
 #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);
 }
 
         return MONITOR_TO_FD(m);
 }
+
+_public_ int sd_login_monitor_get_events(sd_login_monitor *m) {
+
+        if (!m)
+                return -EINVAL;
+
+        return POLLIN;
+}
index 159ff3efc5b3f07fa1bacfaad7a2a5055d51ffdd..f639129636e68fddc47aeb310ab845b2f69a35e2 100644 (file)
@@ -185,7 +185,7 @@ int main(int argc, char* argv[]) {
 
         zero(pollfd);
         pollfd.fd = sd_login_monitor_get_fd(m);
 
         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);
 
         for (n = 0; n < 5; n++) {
                 r = poll(&pollfd, 1, -1);
index 3746b45cf36500abdcfd9a6f187bd477c8498289..57255bd4a9698b200d8608eb1e4439ff4f5f3b8b 100644 (file)
@@ -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 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
 #ifdef __cplusplus
 }
 #endif