logout.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright (C) 1996-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <utmp.h>
  17. #include <time.h>
  18. #include <sys/time.h>
  19. #include <shlib-compat.h>
  20. int
  21. __logout (const char *line)
  22. {
  23. struct utmp tmp, utbuf;
  24. struct utmp *ut;
  25. int result = 0;
  26. /* Tell that we want to use the UTMP file. */
  27. if (__utmpname (_PATH_UTMP) == -1)
  28. return 0;
  29. /* Open UTMP file. */
  30. __setutent ();
  31. /* Fill in search information. */
  32. tmp.ut_type = USER_PROCESS;
  33. strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
  34. /* Read the record. */
  35. if (__getutline_r (&tmp, &utbuf, &ut) >= 0)
  36. {
  37. /* Clear information about who & from where. */
  38. memset (ut->ut_name, '\0', sizeof ut->ut_name);
  39. memset (ut->ut_host, '\0', sizeof ut->ut_host);
  40. struct __timespec64 ts;
  41. __clock_gettime64 (CLOCK_REALTIME, &ts);
  42. TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
  43. ut->ut_type = DEAD_PROCESS;
  44. if (__pututline (ut) != NULL)
  45. result = 1;
  46. }
  47. /* Close UTMP file. */
  48. __endutent ();
  49. return result;
  50. }
  51. versioned_symbol (libc, __logout, logout, GLIBC_2_34);
  52. libc_hidden_ver (__logout, logout)
  53. #if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34)
  54. compat_symbol (libutil, __logout, logout, GLIBC_2_0);
  55. #endif