wtent.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #if 0
  15. libc_hidden_proto(memset)
  16. libc_hidden_proto(strncpy)
  17. libc_hidden_proto(updwtmp)
  18. #endif
  19. libc_hidden_proto(open)
  20. libc_hidden_proto(write)
  21. libc_hidden_proto(close)
  22. libc_hidden_proto(lockf)
  23. libc_hidden_proto(gettimeofday)
  24. #if 0
  25. /* This is enabled in uClibc/libutil/logwtmp.c */
  26. void logwtmp (const char *line, const char *name, const char *host)
  27. {
  28. struct utmp lutmp;
  29. memset (&(lutmp), 0, sizeof (struct utmp));
  30. lutmp.ut_type = (name && *name)? USER_PROCESS : DEAD_PROCESS;
  31. lutmp.ut_pid = __getpid();
  32. strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
  33. strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
  34. strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
  35. gettimeofday(&(lutmp.ut_tv), NULL);
  36. updwtmp(_PATH_WTMP, &(lutmp));
  37. }
  38. #endif
  39. void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
  40. {
  41. int fd;
  42. fd = open(wtmp_file, O_APPEND | O_WRONLY, 0);
  43. if (fd >= 0) {
  44. if (lockf(fd, F_LOCK, 0)==0) {
  45. write(fd, (const char *) lutmp, sizeof(struct utmp));
  46. lockf(fd, F_ULOCK, 0);
  47. close(fd);
  48. }
  49. }
  50. }