logout.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <string.h>
  18. #include <utmp.h>
  19. #include <sys/time.h>
  20. int
  21. logout (const char *line)
  22. {
  23. struct utmp tmp;
  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. #if _HAVE_UT_TYPE - 0
  33. tmp.ut_type = USER_PROCESS;
  34. #endif
  35. strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
  36. /* Read the record. */
  37. if( (ut = getutline(&tmp)) )
  38. {
  39. /* Clear information about who & from where. */
  40. memset (ut->ut_name, 0, sizeof ut->ut_name);
  41. #if _HAVE_UT_HOST - 0
  42. memset (ut->ut_host, 0, sizeof ut->ut_host);
  43. #endif
  44. #if _HAVE_UT_TV - 0
  45. # if __WORDSIZE_COMPAT32 == 0
  46. gettimeofday (&ut->ut_tv, NULL);
  47. # else
  48. {
  49. struct timeval tv;
  50. gettimeofday (&tv, NULL);
  51. ut->ut_tv.tv_sec = tv.tv_sec;
  52. ut->ut_tv.tv_usec = tv.tv_usec;
  53. }
  54. # endif
  55. #else
  56. time (&ut->ut_time);
  57. #endif
  58. #if _HAVE_UT_TYPE - 0
  59. ut->ut_type = DEAD_PROCESS;
  60. #endif
  61. if (pututline (ut) != NULL)
  62. result = 1;
  63. }
  64. /* Close UTMP file. */
  65. endutent ();
  66. return result;
  67. }