wtent.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /* wtmp support rubbish (i.e. complete crap) */
  7. #include <string.h>
  8. #include <sys/time.h>
  9. #include <time.h>
  10. #include <unistd.h>
  11. #include <utmp.h>
  12. #include <fcntl.h>
  13. #include <sys/file.h>
  14. #include <not-cancel.h>
  15. #if 0
  16. /* This is enabled in uClibc/libutil/logwtmp.c */
  17. void logwtmp (const char *line, const char *name, const char *host)
  18. {
  19. struct utmp lutmp;
  20. memset(&lutmp, 0, sizeof(lutmp));
  21. lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
  22. lutmp.ut_pid = getpid();
  23. strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
  24. strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
  25. strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
  26. gettimeofday(&(lutmp.ut_tv), NULL);
  27. updwtmp(_PATH_WTMP, &lutmp);
  28. }
  29. #endif
  30. void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
  31. {
  32. int fd;
  33. fd = open_not_cancel(wtmp_file, O_APPEND | O_WRONLY, 0);
  34. if (fd >= 0) {
  35. if (lockf(fd, F_LOCK, 0) == 0) {
  36. write_not_cancel(fd, lutmp, sizeof(struct utmp));
  37. lockf(fd, F_ULOCK, 0);
  38. close_not_cancel_no_status(fd);
  39. }
  40. }
  41. }
  42. libc_hidden_def(updwtmp)