1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <string.h>
21: #include <sys/time.h>
22: #include <time.h>
23: #include <unistd.h>
24: #include <utmp.h>
25:
26:
27: void
28: logwtmp (const char *line, const char *name, const char *host)
29: {
30: struct utmp ut;
31:
32:
33: memset (&ut, 0, sizeof (ut));
34: #if _HAVE_UT_PID - 0
35: ut.ut_pid = getpid ();
36: #endif
37: #if _HAVE_UT_TYPE - 0
38: ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
39: #endif
40: strncpy (ut.ut_line, line, sizeof ut.ut_line);
41: strncpy (ut.ut_name, name, sizeof ut.ut_name);
42: #if _HAVE_UT_HOST - 0
43: strncpy (ut.ut_host, host, sizeof ut.ut_host);
44: #endif
45:
46: #if _HAVE_UT_TV - 0
47: struct timeval tv;
48: __gettimeofday (&tv, NULL);
49: ut.ut_tv.tv_sec = tv.tv_sec;
50: ut.ut_tv.tv_usec = tv.tv_usec;
51: #else
52: ut.ut_time = time (NULL);
53: #endif
54:
55: updwtmp (_PATH_WTMP, &ut);
56: }