wtent.c 1.2 KB

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