logout.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright (C) 1996, 1997 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 Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 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. utmpname (_PATH_UTMP);
  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)) )
  37. {
  38. /* Clear information about who & from where. */
  39. bzero (ut->ut_name, sizeof ut->ut_name);
  40. #if _HAVE_UT_HOST - 0
  41. bzero (ut->ut_host, sizeof ut->ut_host);
  42. #endif
  43. #if _HAVE_UT_TV - 0
  44. gettimeofday (&ut->ut_tv, NULL);
  45. #else
  46. time (&ut->ut_time);
  47. #endif
  48. #if _HAVE_UT_TYPE - 0
  49. ut->ut_type = DEAD_PROCESS;
  50. #endif
  51. if (pututline (ut) != NULL)
  52. result = 1;
  53. }
  54. /* Close UTMP file. */
  55. endutent ();
  56. return result;
  57. }