1 /* vi: set sw=4 ts=4: */
3 * wtmp support rubbish (i.e. complete crap)
4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
16 void logwtmp(const char *line
, const char *name
, const char *host
)
19 memset(&lutmp
, 0, sizeof(lutmp
));
21 lutmp
.ut_type
= (name
&& *name
) ? USER_PROCESS
: DEAD_PROCESS
;
22 lutmp
.ut_pid
= getpid();
23 strncpy(lutmp
.ut_line
, line
, sizeof(lutmp
.ut_line
)-1);
24 strncpy(lutmp
.ut_name
, name
, sizeof(lutmp
.ut_name
)-1);
25 strncpy(lutmp
.ut_host
, host
, sizeof(lutmp
.ut_host
)-1);
26 #if !defined __WORDSIZE_COMPAT32 || __WORDSIZE_COMPAT32 == 0
27 gettimeofday(&lutmp
.ut_tv
, NULL
);
31 gettimeofday(&tv
, NULL
);
32 lutmp
.ut_tv
.tv_sec
= tv
.tv_sec
;
33 lutmp
.ut_tv
.tv_usec
= tv
.tv_usec
;
37 updwtmp(_PATH_WTMP
, &lutmp
);
41 /* This is enabled in uClibc/libc/misc/utmp/wtent.c */
42 void updwtmp(const char *wtmp_file
, const struct utmp
*lutmp
)
46 fd
= open(wtmp_file
, O_APPEND
| O_WRONLY
);
48 if (lockf(fd
, F_LOCK
, 0) == 0) {
49 write(fd
, lutmp
, sizeof(*lutmp
));
50 lockf(fd
, F_ULOCK
, 0);