wtent.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifdef __UCLIBC_HAS_UTMPX__
  13. # include <utmpx.h>
  14. #endif
  15. #include <fcntl.h>
  16. #include <sys/file.h>
  17. #include <not-cancel.h>
  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. lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
  25. lutmp.ut_pid = getpid();
  26. strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
  27. strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
  28. strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
  29. gettimeofday(&(lutmp.ut_tv), NULL);
  30. updwtmp(_PATH_WTMP, &lutmp);
  31. }
  32. #endif
  33. static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp)
  34. {
  35. int fd;
  36. fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY);
  37. if (fd >= 0) {
  38. if (lockf(fd, F_LOCK, 0) == 0) {
  39. write_not_cancel(fd, lutmp, sizeof(struct utmp));
  40. lockf(fd, F_ULOCK, 0);
  41. close_not_cancel_no_status(fd);
  42. }
  43. }
  44. }
  45. strong_alias(__updwtmp,updwtmp)
  46. #ifdef __UCLIBC_HAS_UTMPX__
  47. void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
  48. {
  49. __updwtmp (wtmpx_file, (const struct utmp *) utmpx);
  50. }
  51. #endif