sd_login_monitor_new.xml revision 7ca4155737730ece73ae4b4ac80571005cb99b69
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
97a9a944b5887e91042b019776c41d5dd74557aferikabele "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive This file is part of systemd.
5a58787efeb02a1c3f06569d019ad81fd2efa06end Copyright 2010 Lennart Poettering
5a58787efeb02a1c3f06569d019ad81fd2efa06end systemd is free software; you can redistribute it and/or modify it
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen under the terms of the GNU Lesser General Public License as published by
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the Free Software Foundation; either version 2.1 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
5a58787efeb02a1c3f06569d019ad81fd2efa06end systemd is distributed in the hope that it will be useful, but
5a58787efeb02a1c3f06569d019ad81fd2efa06end WITHOUT ANY WARRANTY; without even the implied warranty of
5a58787efeb02a1c3f06569d019ad81fd2efa06end MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen Lesser General Public License for more details.
5a58787efeb02a1c3f06569d019ad81fd2efa06end You should have received a copy of the GNU Lesser General Public License
5a58787efeb02a1c3f06569d019ad81fd2efa06end along with systemd; If not, see <http://www.gnu.org/licenses/>.
5a58787efeb02a1c3f06569d019ad81fd2efa06end<refentry id="sd_login_monitor_new" conditional='HAVE_PAM'>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd <refentryinfo>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung <authorgroup>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </authorgroup>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </refentryinfo>
b21197dc8e6b8c764fdcc24d4bae8b0eebb6bc4end </refmeta>
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive <refnamediv>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <refpurpose>Monitor login sessions, seats, users and virtual machines/containers</refpurpose>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </refnamediv>
deeee6bb6fd94c0ba5f3730b58abd9d299c89ccdnd <refsynopsisdiv>
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl <funcsynopsis>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf <funcprototype>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <funcdef>int <function>sd_login_monitor_new</function></funcdef>
ffb01336be79c64046b636e59fa8ddca8ec029edsf <paramdef>const char *<parameter>category</parameter></paramdef>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <paramdef>sd_login_monitor **<parameter>ret</parameter></paramdef>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd </funcprototype>
2bc7f1cf720973a67f8ff7a8d523e40569ae5b6cnd <funcprototype>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <funcdef>sd_login_monitor *<function>sd_login_monitor_unref</function></funcdef>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd </funcprototype>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <funcprototype>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <funcdef>int <function>sd_login_monitor_flush</function></funcdef>
87ffb6e33f3cbef3b9bb406cc2d27039fa336eaatrawick <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl </funcprototype>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <funcprototype>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <funcdef>int <function>sd_login_monitor_get_fd</function></funcdef>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </funcprototype>
654d8eb036bedc99e90e11910ee02d3421417697rbowen <funcprototype>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh <funcdef>int <function>sd_login_monitor_get_events</function></funcdef>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </funcprototype>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <funcprototype>
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick <funcdef>int <function>sd_login_monitor_get_timeout</function></funcdef>
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick <paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick <paramdef>uint64_t *<parameter>timeout_usec</parameter></paramdef>
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick </funcprototype>
654d8eb036bedc99e90e11910ee02d3421417697rbowen </funcsynopsis>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </refsynopsisdiv>
654d8eb036bedc99e90e11910ee02d3421417697rbowen <para><function>sd_login_monitor_new()</function> may be used to
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive monitor login sessions, users, seats, and virtual
97a9a944b5887e91042b019776c41d5dd74557aferikabele machines/containers. Via a monitor object a file descriptor can be
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive integrated into an application defined event loop which is woken
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive up each time a user logs in, logs out or a seat is added or
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive removed, or a session, user, seat or virtual machine/container
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive changes state otherwise. The first parameter takes a string which
ffb01336be79c64046b636e59fa8ddca8ec029edsf can be <literal>seat</literal> (to get only notifications about
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick seats being added, removed or changed), <literal>session</literal>
ffb01336be79c64046b636e59fa8ddca8ec029edsf (to get only notifications about sessions being created or removed
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick or changed), <literal>uid</literal> (to get only notifications
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick when a user changes state in respect to logins) or
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick <literal>machine</literal> (to get only notifications when a
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick virtual machine or container is started or stopped). If
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick notifications shall be generated in all these conditions,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <constant>NULL</constant> may be passed. Note that in the future
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick additional categories may be defined. The second parameter returns
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf a monitor object and needs to be freed with the
ffb01336be79c64046b636e59fa8ddca8ec029edsf use.</para>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <para><function>sd_login_monitor_unref()</function> may be used to
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick destroy a monitor object. Note that this will invalidate any file
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick descriptor returned by
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <para><function>sd_login_monitor_flush()</function> may be used to
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd reset the wakeup state of the monitor object. Whenever an event
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick causes the monitor to wake up the event loop via the file
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf descriptor this function needs to be called to reset the wake-up
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf state. If this call is not invoked, the file descriptor will
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf immediately wake up the event loop again.</para>
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick <para><function>sd_login_monitor_get_fd()</function> may be used
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick to retrieve the file descriptor of the monitor object that may be
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick integrated in an application defined event loop, based around
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf or a similar interface. The application should include the
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick returned file descriptor as wake-up source for the events mask
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick returned by <function>sd_login_monitor_get_events()</function>. It
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick should pass a timeout value as returned by
ffb01336be79c64046b636e59fa8ddca8ec029edsf <function>sd_login_monitor_get_timeout()</function>. Whenever a
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick wake-up is triggered the file descriptor needs to be reset via
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive <function>sd_login_monitor_flush()</function>. An application
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive needs to reread the login state with a function like
97a9a944b5887e91042b019776c41d5dd74557aferikabele <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive or similar to determine what changed.</para>
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic <para><function>sd_login_monitor_get_events()</function> will
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic return the <function>poll()</function> mask to wait for. This
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic function will return a combination of <constant>POLLIN</constant>,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic <constant>POLLOUT</constant> and similar to fill into the
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic <para><function>sd_login_monitor_get_timeout()</function> will
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return a timeout value for usage in <function>poll()</function>.
e8d485701957d5c6de870111c112e168a894d49and This returns a value in microseconds since the epoch of
654d8eb036bedc99e90e11910ee02d3421417697rbowen <function>poll()</function> in <varname>timeout_usec</varname>.
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive for details about <constant>CLOCK_MONOTONIC</constant>. If there
9bcfc3697a91b5215893a7d0206865b13fc72148nd is no timeout to wait for this will fill in <constant>(uint64_t)
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive -1</constant> instead. Note that <function>poll()</function> takes
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive a relative timeout in milliseconds rather than an absolute timeout
06ba4a61654b3763ad65f52283832ebf058fdf1cslive in microseconds. To convert the absolute 'µs' timeout into
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf relative 'ms', use code like the following:</para>
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive <programlisting>uint64_t t;
709e3a21ba73b8433462959cd56c773454b34441trawicksd_login_monitor_get_timeout(m, &t);
709e3a21ba73b8433462959cd56c773454b34441trawickif (t == (uint64_t) -1)
709e3a21ba73b8433462959cd56c773454b34441trawick struct timespec ts;
709e3a21ba73b8433462959cd56c773454b34441trawick uint64_t n;
5a58787efeb02a1c3f06569d019ad81fd2efa06end clock_getttime(CLOCK_MONOTONIC, &ts);
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd}</programlisting>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun <para>The code above does not do any error checking for brevity's
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung sake. The calculated <varname>msec</varname> integer can be passed
0d0ba3a410038e179b695446bb149cce6264e0abnd parameter.</para>
0d0ba3a410038e179b695446bb149cce6264e0abnd <refsect1>
727872d18412fc021f03969b8641810d8896820bhumbedooh <para>On success,
727872d18412fc021f03969b8641810d8896820bhumbedooh return 0 or a positive integer. On success,
0d0ba3a410038e179b695446bb149cce6264e0abnd a Unix file descriptor. On success,
727872d18412fc021f03969b8641810d8896820bhumbedooh returns a combination of <constant>POLLIN</constant>,
0d0ba3a410038e179b695446bb149cce6264e0abnd these calls return a negative errno-style error
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh code.</para>
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd </refsect1>
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd <refsect1>