1 /*
2  * wtmp support rubbish (i.e. complete crap)
3  * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6 
7 #include <string.h>
8 #include <sys/time.h>
9 #include <time.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <sys/file.h>
13 #include "internal/utmp.h"
14 
logwtmp(const char * line,const char * name,const char * host)15 void logwtmp(const char *line, const char *name, const char *host)
16 {
17     struct UT lutmp;
18     memset(&lutmp, 0, sizeof(lutmp));
19 
20     lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
21     lutmp.ut_pid = getpid();
22     strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1);
23     strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1);
24     strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1);
25 #if !defined __WORDSIZE_TIME64_COMPAT32
26     gettimeofday(&lutmp.ut_tv, NULL);
27 #else
28     {
29       struct timeval tv;
30       gettimeofday(&tv, NULL);
31       lutmp.ut_tv.tv_sec = tv.tv_sec;
32       lutmp.ut_tv.tv_usec = tv.tv_usec;
33     }
34 #endif
35 
36     updwtmp(_PATH_WTMP, &lutmp);
37 }
38