lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> |
| 3 | * |
| 4 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 5 | */ |
| 6 | |
| 7 | /* wtmp support rubbish (i.e. complete crap) */ |
| 8 | |
| 9 | #include <string.h> |
| 10 | #include <sys/time.h> |
| 11 | #include <time.h> |
| 12 | #include <unistd.h> |
| 13 | #include <utmp.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <sys/file.h> |
| 16 | #include <not-cancel.h> |
| 17 | |
| 18 | #if 0 |
| 19 | /* This is enabled in uClibc/libutil/logwtmp.c */ |
| 20 | void logwtmp (const char *line, const char *name, const char *host) |
| 21 | { |
| 22 | struct utmp lutmp; |
| 23 | memset(&lutmp, 0, sizeof(lutmp)); |
| 24 | |
| 25 | lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS; |
| 26 | lutmp.ut_pid = getpid(); |
| 27 | strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1); |
| 28 | strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1); |
| 29 | strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1); |
| 30 | gettimeofday(&(lutmp.ut_tv), NULL); |
| 31 | |
| 32 | updwtmp(_PATH_WTMP, &lutmp); |
| 33 | } |
| 34 | #endif |
| 35 | |
| 36 | void updwtmp(const char *wtmp_file, const struct utmp *lutmp) |
| 37 | { |
| 38 | int fd; |
| 39 | |
| 40 | fd = open_not_cancel(wtmp_file, O_APPEND | O_WRONLY, 0); |
| 41 | if (fd >= 0) { |
| 42 | if (lockf(fd, F_LOCK, 0) == 0) { |
| 43 | write_not_cancel(fd, lutmp, sizeof(struct utmp)); |
| 44 | lockf(fd, F_ULOCK, 0); |
| 45 | close_not_cancel_no_status(fd); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | libc_hidden_def(updwtmp) |