Back to index

glibc  2.9
logwtmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 2002 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 <string.h>
00021 #include <sys/time.h>
00022 #include <time.h>
00023 #include <unistd.h>
00024 #include <utmp.h>
00025 
00026 
00027 void
00028 logwtmp (const char *line, const char *name, const char *host)
00029 {
00030   struct utmp ut;
00031 
00032   /* Set information in new entry.  */
00033   memset (&ut, 0, sizeof (ut));
00034 #if _HAVE_UT_PID - 0
00035   ut.ut_pid = getpid ();
00036 #endif
00037 #if _HAVE_UT_TYPE - 0
00038   ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
00039 #endif
00040   strncpy (ut.ut_line, line, sizeof ut.ut_line);
00041   strncpy (ut.ut_name, name, sizeof ut.ut_name);
00042 #if _HAVE_UT_HOST - 0
00043   strncpy (ut.ut_host, host, sizeof ut.ut_host);
00044 #endif
00045 
00046 #if _HAVE_UT_TV - 0
00047   struct timeval tv;
00048   __gettimeofday (&tv, NULL);
00049   ut.ut_tv.tv_sec = tv.tv_sec;
00050   ut.ut_tv.tv_usec = tv.tv_usec;
00051 #else
00052   ut.ut_time = time (NULL);
00053 #endif
00054 
00055   updwtmp (_PATH_WTMP, &ut);
00056 }