Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libutil add utmpx/wtmpx processing routines.
details: https://anonhg.NetBSD.org/src/rev/fe528acbb7f3
branches: trunk
changeset: 534477:fe528acbb7f3
user: christos <christos%NetBSD.org@localhost>
date: Sat Jul 27 23:49:23 2002 +0000
description:
add utmpx/wtmpx processing routines.
diffstat:
lib/libutil/login.c | 12 ++++++++++--
lib/libutil/logout.c | 36 ++++++++++++++++++++++++++++--------
lib/libutil/logwtmp.c | 29 +++++++++++++++++++++++++++--
lib/libutil/shlib_version | 4 ++--
4 files changed, 67 insertions(+), 14 deletions(-)
diffs (188 lines):
diff -r 2b61a39660c1 -r fe528acbb7f3 lib/libutil/login.c
--- a/lib/libutil/login.c Sat Jul 27 23:49:00 2002 +0000
+++ b/lib/libutil/login.c Sat Jul 27 23:49:23 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: login.c,v 1.13 2000/07/05 11:46:40 ad Exp $ */
+/* $NetBSD: login.c,v 1.14 2002/07/27 23:49:23 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: login.c,v 1.13 2000/07/05 11:46:40 ad Exp $");
+__RCSID("$NetBSD: login.c,v 1.14 2002/07/27 23:49:23 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -52,6 +52,7 @@
#include <unistd.h>
#include <util.h>
#include <utmp.h>
+#include <utmpx.h>
void
login(const struct utmp *ut)
@@ -72,3 +73,10 @@
(void)close(fd);
}
}
+
+void
+loginx(const struct utmpx *ut)
+{
+ (void)pututxline(ut);
+ (void)updwtmpx(_PATH_WTMPX, ut);
+}
diff -r 2b61a39660c1 -r fe528acbb7f3 lib/libutil/logout.c
--- a/lib/libutil/logout.c Sat Jul 27 23:49:00 2002 +0000
+++ b/lib/libutil/logout.c Sat Jul 27 23:49:23 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: logout.c,v 1.12 2000/07/05 11:46:41 ad Exp $ */
+/* $NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -38,12 +38,13 @@
#if 0
static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: logout.c,v 1.12 2000/07/05 11:46:41 ad Exp $");
+__RCSID("$NetBSD: logout.c,v 1.13 2002/07/27 23:49:23 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/time.h>
+#include <sys/wait.h>
#include <assert.h>
#include <fcntl.h>
@@ -53,30 +54,49 @@
#include <unistd.h>
#include <util.h>
#include <utmp.h>
-
-typedef struct utmp UTMP;
+#include <utmpx.h>
int
logout(const char *line)
{
int fd, rval;
- UTMP ut;
+ struct utmp ut;
_DIAGASSERT(line != NULL);
if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
return(0);
rval = 0;
- while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
+ while (read(fd, &ut, sizeof(ut)) == sizeof(ut)) {
if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
continue;
memset(ut.ut_name, 0, UT_NAMESIZE);
memset(ut.ut_host, 0, UT_HOSTSIZE);
(void)time(&ut.ut_time);
- (void)lseek(fd, -(off_t)sizeof(UTMP), SEEK_CUR);
- (void)write(fd, &ut, sizeof(UTMP));
+ (void)lseek(fd, -(off_t)sizeof(ut), SEEK_CUR);
+ (void)write(fd, &ut, sizeof(ut));
rval = 1;
}
(void)close(fd);
return(rval);
}
+
+int
+logoutx(const char *line, int status, int type)
+{
+ struct utmpx *utp, ut;
+ (void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
+ if ((utp = getutxline(&ut)) == NULL) {
+ endutxent();
+ return 0;
+ }
+ utp->ut_type = type;
+ if (WIFEXITED(status))
+ utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
+ if (WIFSIGNALED(status))
+ utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status);
+ (void)gettimeofday(&utp->ut_tv, NULL);
+ (void)pututxline(utp);
+ endutxent();
+ return 1;
+}
diff -r 2b61a39660c1 -r fe528acbb7f3 lib/libutil/logwtmp.c
--- a/lib/libutil/logwtmp.c Sat Jul 27 23:49:00 2002 +0000
+++ b/lib/libutil/logwtmp.c Sat Jul 27 23:49:23 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: logwtmp.c,v 1.11 2000/07/05 11:46:41 ad Exp $ */
+/* $NetBSD: logwtmp.c,v 1.12 2002/07/27 23:49:23 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: logwtmp.c,v 1.11 2000/07/05 11:46:41 ad Exp $");
+__RCSID("$NetBSD: logwtmp.c,v 1.12 2002/07/27 23:49:23 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -46,12 +46,14 @@
#include <sys/file.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
+#include <utmpx.h>
#include <util.h>
void
@@ -77,3 +79,26 @@
}
(void) close(fd);
}
+
+void
+logwtmpx(const char *line, const char *name, const char *host, int status,
+ int type)
+{
+ struct utmpx ut;
+
+ _DIAGASSERT(line != NULL);
+ _DIAGASSERT(name != NULL);
+ _DIAGASSERT(host != NULL);
+
+ (void)memset(&ut, 0, sizeof(ut));
+ (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
+ (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
+ (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
+ ut.ut_type = type;
+ if (WIFEXITED(status))
+ ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
+ if (WIFSIGNALED(status))
+ ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
+ (void)gettimeofday(&ut.ut_tv, NULL);
+ (void)updwtmpx(_PATH_WTMPX, &ut);
+}
diff -r 2b61a39660c1 -r fe528acbb7f3 lib/libutil/shlib_version
--- a/lib/libutil/shlib_version Sat Jul 27 23:49:00 2002 +0000
+++ b/lib/libutil/shlib_version Sat Jul 27 23:49:23 2002 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.24 2001/08/18 19:33:17 ad Exp $
+# $NetBSD: shlib_version,v 1.25 2002/07/27 23:49:24 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=6
-minor=0
+minor=1
Home |
Main Index |
Thread Index |
Old Index