X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=man%2Fsd_login_monitor_new.xml;h=c6c58390a2b863705bd9973fc9e1ce794b2dfb19;hb=d04b238170998e0cbcc86db0f8ae66c3ee4a14d6;hp=7319c061c975cbbc1f17fcc06b4054902d19faa7;hpb=7586a2e532d8dcb2428edd4e98c3534fc6f22061;p=elogind.git diff --git a/man/sd_login_monitor_new.xml b/man/sd_login_monitor_new.xml index 7319c061c..c6c58390a 100644 --- a/man/sd_login_monitor_new.xml +++ b/man/sd_login_monitor_new.xml @@ -45,6 +45,7 @@ sd_login_monitor_new sd_login_monitor_unref + sd_login_monitor_unrefp sd_login_monitor_flush sd_login_monitor_get_fd sd_login_monitor_get_events @@ -68,6 +69,11 @@ sd_login_monitor *m + + void sd_login_monitor_unrefp + sd_login_monitor **m + + int sd_login_monitor_flush sd_login_monitor *m @@ -121,6 +127,26 @@ descriptor returned by sd_login_monitor_get_fd(). + sd_login_monitor_unrefp() is similar to + sd_login_monitor_unref() but takes a pointer + to a pointer to an sd_login_monitor object. This call + is useful in conjunction with GCC's and LLVM's Clean-up + Variable Attribute. Note that this function is defined as + inline function. Use a declaration like the following, in order to + allocate a login monitor object that is freed automatically as the + code block is left: + + { + __attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL; + int r; + … + r = sd_login_monitor_default(&m); + if (r < 0) + fprintf(stderr, "Failed to allocate login monitor object: %s\n", strerror(-r)); + … +} + sd_login_monitor_flush() may be used to reset the wakeup state of the monitor object. Whenever an event causes the monitor to wake up the event loop via the file @@ -128,6 +154,11 @@ state. If this call is not invoked, the file descriptor will immediately wake up the event loop again. + sd_login_monitor_unref() and + sd_login_monitor_unrefp() execute no + operation if the passed in monitor object is + NULL. + sd_login_monitor_get_fd() may be used to retrieve the file descriptor of the monitor object that may be integrated in an application defined event loop, based around @@ -161,20 +192,20 @@ is no timeout to wait for this will fill in (uint64_t) -1 instead. Note that poll() takes a relative timeout in milliseconds rather than an absolute timeout - in microseconds. To convert the absolute 'us' timeout into + in microseconds. To convert the absolute 'µs' timeout into relative 'ms', use code like the following: uint64_t t; int msec; sd_login_monitor_get_timeout(m, &t); if (t == (uint64_t) -1) - msec = -1; + msec = -1; else { - struct timespec ts; - uint64_t n; - clock_getttime(CLOCK_MONOTONIC, &ts); - n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; - msec = t > n ? (int) ((t - n + 999) / 1000) : 0; + struct timespec ts; + uint64_t n; + clock_gettime(CLOCK_MONOTONIC, &ts); + n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; + msec = t > n ? (int) ((t - n + 999) / 1000) : 0; } The code above does not do any error checking for brevity's @@ -203,6 +234,29 @@ else { always returns NULL. + + Errors + + Returned errors may indicate the following problems: + + + + + -EINVAL + + An input parameter was invalid (out of range, + or NULL, where that is not accepted). The specified category to + watch is not known. + + + + -ENOMEM + + Memory allocation failed. + + + + Notes