]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: merge read_utmp() code
authorKarel Zak <kzak@redhat.com>
Thu, 16 Jul 2015 09:26:14 +0000 (11:26 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 16 Jul 2015 09:26:14 +0000 (11:26 +0200)
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>
include/Makemodule.am
include/readutmp.h [deleted file]
lib/Makemodule.am
lib/readutmp.c [deleted file]
login-utils/lslogins.c

index be94f8a87c2a442d0166d59b6df6a247f935c9a5..48a19541efc51aacc2c306d3c7516930492feb2d 100644 (file)
@@ -42,7 +42,6 @@ dist_noinst_HEADERS += \
        include/pt-sgi.h \
        include/pt-sun.h \
        include/randutils.h \
-       include/readutmp.h \
        include/rpmatch.h \
        include/setproctitle.h \
        include/statfs_magic.h \
diff --git a/include/readutmp.h b/include/readutmp.h
deleted file mode 100644 (file)
index 93251ea..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Declarations for GNU's read utmp module.
-
-   Copyright (C) 1992-2007, 2009-2014 Free Software Foundation, Inc.
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Written by jla; revised by djm */
-
-#ifndef READUTMP_H
-#define READUTMP_H
-
-#include <sys/types.h>
-#include <utmp.h>
-
-int read_utmp (char const *file, size_t *n_entries, struct utmp **utmp_buf);
-
-#endif /* READUTMP_H */
index 566c527a0862ed1d79c994f79025f4ab09f9214a..6ef69570fb675d9f10e7f9b685c32364f621dfae 100644 (file)
@@ -24,8 +24,7 @@ libcommon_la_SOURCES = \
        lib/timeutils.c \
        lib/ttyutils.c \
        lib/exec_shell.c \
-       lib/strv.c \
-       lib/readutmp.c
+       lib/strv.c
 
 if LINUX
 libcommon_la_SOURCES += \
diff --git a/lib/readutmp.c b/lib/readutmp.c
deleted file mode 100644 (file)
index b11e9a4..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* GNU's read utmp module.
-
-        Copyright (C) 1992-2001, 2003-2006, 2009-2014 Free Software Foundation, Inc.
-
-        This program is free software: you can redistribute it and/or modify
-        it under the terms of the GNU General Public License as published by
-        the Free Software Foundation; either version 3 of the License, or
-        (at your option) any later version.
-
-        This program is distributed in the hope that it will be useful,
-        but WITHOUT ANY WARRANTY; without even the implied warranty of
-        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
-        GNU General Public License for more details.
-
-        You should have received a copy of the GNU General Public License
-        along with this program.       If not, see <http://www.gnu.org/licenses/>.     */
-
-/* Written by jla; revised by djm */
-/* extracted for util-linux by ooprala */
-
-#include <errno.h>
-#include <stdio.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "xalloc.h"
-#include "readutmp.h"
-
-/* Read the utmp entries corresponding to file FILE into freshly-
-        malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to
-        the number of entries, and return zero.        If there is any error,
-        return -1, setting errno, and don't modify the parameters.
-        If OPTIONS & READ_UTMP_CHECK_PIDS is nonzero, omit entries whose
-        process-IDs do not currently exist.    */
-int
-read_utmp (char const *file, size_t *n_entries, struct utmp **utmp_buf)
-{
-       size_t n_read = 0;
-       size_t n_alloc = 0;
-       struct utmp *utmp = NULL;
-       struct utmp *u;
-
-       /* Ignore the return value for now.
-                Solaris' utmpname returns 1 upon success -- which is contrary
-                to what the GNU libc version does.     In addition, older GNU libc
-                versions are actually void.     */
-       utmpname(file);
-
-       setutent();
-
-       errno = 0;
-       while ((u = getutent()) != NULL) {
-               if (n_read == n_alloc) {
-                       n_alloc += 32;
-                       utmp = xrealloc(utmp, n_alloc * sizeof (struct utmp));
-                       if (!utmp)
-                               return -1;
-               }
-               utmp[n_read++] = *u;
-       }
-       if (!u && errno) {
-               free(utmp);
-               return -1;
-       }
-
-       endutent();
-
-       *n_entries = n_read;
-       *utmp_buf = utmp;
-
-       return 0;
-}
index 48ba6d8ad5911a168dd10af5cf2aa11d130a79ee..b56efd476e330e3dbc9ac7c3e95e1d05bd092cf8 100644 (file)
@@ -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;