diff options
author | Karel Zak | 2015-07-16 11:26:14 +0200 |
---|---|---|
committer | Karel Zak | 2015-07-16 11:26:14 +0200 |
commit | a6bf40ee77a85f5108208dc764b5d023a07998f5 (patch) | |
tree | 69c0ad0d5480e231f88cd92077bc66f1528d189a /login-utils/lslogins.c | |
parent | lslogins: fix --user-accs and --system-accs docs (diff) | |
download | kernel-qcow2-util-linux-a6bf40ee77a85f5108208dc764b5d023a07998f5.tar.gz kernel-qcow2-util-linux-a6bf40ee77a85f5108208dc764b5d023a07998f5.tar.xz kernel-qcow2-util-linux-a6bf40ee77a85f5108208dc764b5d023a07998f5.zip |
lslogins: merge read_utmp() code
The code is used only in lslogins, so it does not make sense to
maintain it in libcommon.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/lslogins.c')
-rw-r--r-- | login-utils/lslogins.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 48ba6d8ad..b56efd476 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -26,6 +26,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/syslog.h> +#include <sys/types.h> #include <pwd.h> #include <grp.h> #include <shadow.h> @@ -35,7 +36,6 @@ #include <signal.h> #include <err.h> #include <limits.h> - #include <search.h> #include <libsmartcols.h> @@ -56,7 +56,6 @@ #include "optutils.h" #include "pathnames.h" #include "logindefs.h" -#include "readutmp.h" #include "procutils.h" /* @@ -476,6 +475,37 @@ static struct utmp *get_last_btmp(struct lslogins_control *ctl, const char *user } +static int read_utmp(char const *file, size_t *nents, struct utmp **res) +{ + size_t n_read = 0, n_alloc = 0; + struct utmp *utmp = NULL, *u; + + if (utmpname(file) < 0) + return -errno; + + setutent(); + errno = 0; + + while ((u = getutent()) != NULL) { + if (n_read == n_alloc) { + n_alloc += 32; + utmp = xrealloc(utmp, n_alloc * sizeof (struct utmp)); + } + utmp[n_read++] = *u; + } + if (!u && errno) { + free(utmp); + return -errno; + } + + endutent(); + + *nents = n_read; + *res = utmp; + + return 0; +} + static int parse_wtmp(struct lslogins_control *ctl, char *path) { int rc = 0; |