summaryrefslogtreecommitdiff
path: root/src/utmps/utmps_getent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utmps/utmps_getent.c')
-rw-r--r--src/utmps/utmps_getent.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utmps/utmps_getent.c b/src/utmps/utmps_getent.c
new file mode 100644
index 0000000..2b21b04
--- /dev/null
+++ b/src/utmps/utmps_getent.c
@@ -0,0 +1,21 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <skalibs/unix-timed.h>
+#include <utmps/utmpx.h>
+#include <utmps/utmps.h>
+#include "utmps-internal.h"
+
+int utmps_getent (utmps *a, struct utmpx *b, tain_t const *deadline, tain_t *stamp)
+{
+ ssize_t r ;
+ char buf[1 + sizeof(struct utmpx)] ;
+ if (!ipc_timed_send(a->fd, "e", 1, deadline, stamp)) return 0 ;
+ r = ipc_timed_recv(a->fd, buf, sizeof(buf), 0, deadline, stamp) ;
+ if (r < 0) return 0 ;
+ if (!r) return (errno = EPIPE, 0) ;
+ if (buf[0]) return (errno = buf[0], 0) ;
+ utmps_utmpx_unpack(buf + 1, b) ;
+ return 1 ;
+}