logwtmp.c 1018 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * wtmp support rubbish (i.e. complete crap)
  3. * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <string.h>
  7. #include <sys/time.h>
  8. #include <time.h>
  9. #include <unistd.h>
  10. #include <fcntl.h>
  11. #include <sys/file.h>
  12. #include "internal/utmp.h"
  13. void logwtmp(const char *line, const char *name, const char *host)
  14. {
  15. struct UT lutmp;
  16. memset(&lutmp, 0, sizeof(lutmp));
  17. lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
  18. lutmp.ut_pid = getpid();
  19. strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
  20. strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
  21. strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
  22. #if !defined __WORDSIZE_TIME64_COMPAT32
  23. gettimeofday(&lutmp.ut_tv, NULL);
  24. #else
  25. {
  26. struct timeval tv;
  27. gettimeofday(&tv, NULL);
  28. lutmp.ut_tv.tv_sec = tv.tv_sec;
  29. lutmp.ut_tv.tv_usec = tv.tv_usec;
  30. }
  31. #endif
  32. updwtmp(_PATH_WTMP, &lutmp);
  33. }