sd_login_monitor_new.xml revision 4afd3348c7506dd1d36305b7bcb9feb8952b9d6b
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<?xml version='1.0'?> <!--*-nxml-*-->
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<!--
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering This file is part of systemd.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering Copyright 2010 Lennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering systemd is free software; you can redistribute it and/or modify it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering (at your option) any later version.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering systemd is distributed in the hope that it will be useful, but
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering-->
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
56ba3c78ae35065064c4289a0c8e22a81256af20Zbigniew Jędrzejewski-Szmek<refentry id="sd_login_monitor_new" conditional='HAVE_PAM'>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refentryinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>sd_login_monitor_new</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <productname>systemd</productname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <authorgroup>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <author>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <contrib>Developer</contrib>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <firstname>Lennart</firstname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <surname>Poettering</surname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <email>lennart@poettering.net</email>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </author>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </authorgroup>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refentryinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refmeta>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refentrytitle>sd_login_monitor_new</refentrytitle>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <manvolnum>3</manvolnum>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refmeta>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refnamediv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_new</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_unref</refname>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <refname>sd_login_monitor_unrefp</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_flush</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_get_fd</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_get_events</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor_get_timeout</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_login_monitor</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refpurpose>Monitor login sessions, seats, users and virtual machines/containers</refpurpose>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refnamediv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsynopsisdiv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcsynopsis>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_login_monitor_new</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>const char *<parameter>category</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor **<parameter>ret</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>sd_login_monitor *<function>sd_login_monitor_unref</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <funcprototype>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <funcdef>void <function>sd_login_monitor_unrefp</function></funcdef>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <paramdef>sd_login_monitor **<parameter>m</parameter></paramdef>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering </funcprototype>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_login_monitor_flush</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_login_monitor_get_fd</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_login_monitor_get_events</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_login_monitor_get_timeout</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>uint64_t *<parameter>timeout_usec</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcsynopsis>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsynopsisdiv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Description</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_new()</function> may be used to
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek monitor login sessions, users, seats, and virtual
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek machines/containers. Via a monitor object a file descriptor can be
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek integrated into an application defined event loop which is woken
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek up each time a user logs in, logs out or a seat is added or
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek removed, or a session, user, seat or virtual machine/container
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek changes state otherwise. The first parameter takes a string which
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek can be <literal>seat</literal> (to get only notifications about
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek seats being added, removed or changed), <literal>session</literal>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek (to get only notifications about sessions being created or removed
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek or changed), <literal>uid</literal> (to get only notifications
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek when a user changes state in respect to logins) or
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <literal>machine</literal> (to get only notifications when a
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek virtual machine or container is started or stopped). If
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek notifications shall be generated in all these conditions,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <constant>NULL</constant> may be passed. Note that in the future
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek additional categories may be defined. The second parameter returns
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek a monitor object and needs to be freed with the
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_unref()</function> call after
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek use.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_unref()</function> may be used to
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek destroy a monitor object. Note that this will invalidate any file
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek descriptor returned by
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_fd()</function>.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <para><function>sd_login_monitor_unrefp()</function> is similar to
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <function>sd_login_monitor_unref()</function> but takes a pointer
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering to a pointer to an <type>sd_login_monitor</type> object. This call
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering is useful in conjunction with GCC's and LLVM's <ulink
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering Variable Attribute</ulink>. Note that this function is defined as
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering inline function. Use a declaration like the following, in order to
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering allocate a login monitor object that is freed automatically as the
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering code block is left:</para>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <programlisting>{
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering __attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering int r;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering r = sd_login_monitor_default(&amp;m);
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering if (r &lt; 0)
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering fprintf(stderr, "Failed to allocate login monitor object: %s\n", strerror(-r));
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering}</programlisting>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_flush()</function> may be used to
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek reset the wakeup state of the monitor object. Whenever an event
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek causes the monitor to wake up the event loop via the file
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek descriptor this function needs to be called to reset the wake-up
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state. If this call is not invoked, the file descriptor will
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek immediately wake up the event loop again.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <para><function>sd_login_monitor_unref()</function> and
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <function>sd_login_monitor_unrefp()</function> execute no
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering operation if the passed in monitor object is
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering <constant>NULL</constant>.</para>
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_get_fd()</function> may be used
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek to retrieve the file descriptor of the monitor object that may be
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek integrated in an application defined event loop, based around
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek or a similar interface. The application should include the
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek returned file descriptor as wake-up source for the events mask
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek returned by <function>sd_login_monitor_get_events()</function>. It
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek should pass a timeout value as returned by
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_timeout()</function>. Whenever a
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek wake-up is triggered the file descriptor needs to be reset via
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_flush()</function>. An application
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek needs to reread the login state with a function like
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek or similar to determine what changed.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_get_events()</function> will
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return the <function>poll()</function> mask to wait for. This
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek function will return a combination of <constant>POLLIN</constant>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <constant>POLLOUT</constant> and similar to fill into the
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <literal>.events</literal> field of <varname>struct
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek pollfd</varname>.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_get_timeout()</function> will
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return a timeout value for usage in <function>poll()</function>.
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek This returns a value in microseconds since the epoch of
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <constant>CLOCK_MONOTONIC</constant> for timing out
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>poll()</function> in <varname>timeout_usec</varname>.
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek See
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek for details about <constant>CLOCK_MONOTONIC</constant>. If there
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek is no timeout to wait for this will fill in <constant>(uint64_t)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek -1</constant> instead. Note that <function>poll()</function> takes
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek a relative timeout in milliseconds rather than an absolute timeout
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering in microseconds. To convert the absolute 'µs' timeout into
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek relative 'ms', use code like the following:</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <programlisting>uint64_t t;
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poetteringint msec;
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poetteringsd_login_monitor_get_timeout(m, &amp;t);
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poetteringif (t == (uint64_t) -1)
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering msec = -1;
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poetteringelse {
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering struct timespec ts;
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering uint64_t n;
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering clock_getttime(CLOCK_MONOTONIC, &amp;ts);
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poettering}</programlisting>
667c24a6a86a5a26a906b7477ae81dcf4c73e64eLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>The code above does not do any error checking for brevity's
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sake. The calculated <varname>msec</varname> integer can be passed
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek directly as <function>poll()</function>'s timeout
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek parameter.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Return Value</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>On success,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_new()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_flush()</function> and
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_timeout()</function>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return 0 or a positive integer. On success,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_fd()</function> returns
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek a Unix file descriptor. On success,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_events()</function>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek returns a combination of <constant>POLLIN</constant>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <constant>POLLOUT</constant> and suchlike. On failure,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek these calls return a negative errno-style error
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek code.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_login_monitor_unref()</function>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek always returns <constant>NULL</constant>.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <refsect1>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <title>Errors</title>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <para>Returned errors may indicate the following problems:</para>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <variablelist>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-EINVAL</constant></term>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <listitem><para>An input parameter was invalid (out of range,
7ca4155737730ece73ae4b4ac80571005cb99b69Jan Engelhardt or NULL, where that is not accepted). The specified category to
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering watch is not known.</para></listitem>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-ENOMEM</constant></term>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <listitem><para>Memory allocation failed.</para></listitem>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </variablelist>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </refsect1>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Notes</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>The <function>sd_login_monitor_new()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_unref()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_flush()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_fd()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_events()</function> and
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_login_monitor_get_timeout()</function>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek interfaces are available as a shared library, which can be
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek compiled and linked to with the
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek file.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>See Also</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering</refentry>