summaryrefslogtreecommitdiff
path: root/libc/misc/utmp/wtent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-06-17 18:58:58 +0000
committerEric Andersen <andersen@codepoet.org>2002-06-17 18:58:58 +0000
commitd83aa1f777ba3bacaa5ab65a508ff7d11756c95a (patch)
tree52d43dbefa1aeb5340208ea3b5d700fddeb9924d /libc/misc/utmp/wtent.c
parent6e0a5a3bb12d28a3eb8f3fb015dfe60e56b1ddd1 (diff)
Some cleanups so utmp/wtmp behaves. Fix potential use of
uninitialized memory. Prepare to reentrantify the utmp stuff. -Erik
Diffstat (limited to 'libc/misc/utmp/wtent.c')
-rw-r--r--libc/misc/utmp/wtent.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c
new file mode 100644
index 000000000..ef5663feb
--- /dev/null
+++ b/libc/misc/utmp/wtent.c
@@ -0,0 +1,60 @@
+/* wtmp support rubbish (i.e. complete crap)
+ *
+ * Written by Erik Andersen <andersee@debian.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 675 Mass Ave,
+ * Cambridge, MA 02139, USA. */
+
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+#include <fcntl.h>
+#include <sys/file.h>
+
+
+#if 0
+/* This is enabled in uClibc/libutil/logwtmp.c */
+void logwtmp (const char *line, const char *name, const char *host)
+{
+ struct utmp lutmp;
+ memset (&(lutmp), 0, sizeof (struct utmp));
+
+ lutmp.ut_type = (name && *name)? USER_PROCESS : DEAD_PROCESS;
+ lutmp.ut_pid = getpid();
+ strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
+ strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
+ strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
+ gettimeofday(&(lutmp.ut_tv), NULL);
+
+ updwtmp(_PATH_WTMP, &(lutmp));
+}
+#endif
+
+extern void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
+{
+ int fd;
+
+ fd = open(wtmp_file, O_APPEND | O_WRONLY, 0);
+ if (fd >= 0) {
+ if (lockf(fd, F_LOCK, 0)==0) {
+ write(fd, (const char *) lutmp, sizeof(struct utmp));
+ lockf(fd, F_ULOCK, 0);
+ close(fd);
+ }
+ }
+}
+