wtent.c 1.1 KB

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