Back to index

glibc  2.9
logout.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 2002, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <string.h>
00022 #include <utmp.h>
00023 #include <sys/time.h>
00024 
00025 int
00026 logout (const char *line)
00027 {
00028   struct utmp tmp, utbuf;
00029   struct utmp *ut;
00030   int result = 0;
00031 
00032   /* Tell that we want to use the UTMP file.  */
00033   if (utmpname (_PATH_UTMP) == -1)
00034     return 0;
00035 
00036   /* Open UTMP file.  */
00037   setutent ();
00038 
00039   /* Fill in search information.  */
00040 #if _HAVE_UT_TYPE - 0
00041   tmp.ut_type = USER_PROCESS;
00042 #endif
00043   strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
00044 
00045   /* Read the record.  */
00046   if (getutline_r (&tmp, &utbuf, &ut) >= 0)
00047     {
00048       /* Clear information about who & from where.  */
00049       bzero (ut->ut_name, sizeof ut->ut_name);
00050 #if _HAVE_UT_HOST - 0
00051       bzero (ut->ut_host, sizeof ut->ut_host);
00052 #endif
00053 #if _HAVE_UT_TV - 0
00054       struct timeval tv;
00055       __gettimeofday (&tv, NULL);
00056       ut->ut_tv.tv_sec = tv.tv_sec;
00057       ut->ut_tv.tv_usec = tv.tv_usec;
00058 #else
00059       ut->ut_time = time (NULL);
00060 #endif
00061 #if _HAVE_UT_TYPE - 0
00062       ut->ut_type = DEAD_PROCESS;
00063 #endif
00064 
00065       if (pututline (ut) != NULL)
00066        result = 1;
00067     }
00068 
00069   /* Close UTMP file.  */
00070   endutent ();
00071 
00072   return result;
00073 }