logout.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <string.h>
  17. #include <sys/time.h>
  18. #include "internal/utmp.h"
  19. int
  20. logout (const char *line)
  21. {
  22. struct UT tmp;
  23. struct UT *ut;
  24. int result = 0;
  25. /* if (utmpname (_PATH_UTMP) == -1) return 0; - why?
  26. * this makes it impossible for caller to use other file!
  27. * Does any standard or historical precedent says this must be done? */
  28. /* Open UTMP file. */
  29. setutent ();
  30. /* Fill in search information. */
  31. #if _HAVE_UT_TYPE - 0
  32. tmp.ut_type = USER_PROCESS;
  33. #endif
  34. strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
  35. /* Read the record. */
  36. if ((ut = getutline(&tmp)) != NULL)
  37. {
  38. /* Clear information about who & from where. */
  39. memset (ut->ut_name, 0, sizeof ut->ut_name);
  40. #if _HAVE_UT_HOST - 0
  41. memset (ut->ut_host, 0, sizeof ut->ut_host);
  42. #endif
  43. #if _HAVE_UT_TV - 0
  44. # if !defined __WORDSIZE_TIME64_COMPAT32
  45. gettimeofday (&ut->ut_tv, NULL);
  46. # else
  47. {
  48. struct timeval tv;
  49. gettimeofday (&tv, NULL);
  50. ut->ut_tv.tv_sec = tv.tv_sec;
  51. ut->ut_tv.tv_usec = tv.tv_usec;
  52. }
  53. # endif
  54. #else
  55. time (&ut->ut_time);
  56. #endif
  57. #if _HAVE_UT_TYPE - 0
  58. ut->ut_type = DEAD_PROCESS;
  59. #endif
  60. if (pututline (ut) != NULL)
  61. result = 1;
  62. }
  63. /* Close UTMP file. */
  64. endutent ();
  65. return result;
  66. }