1*eb7c1594Sagc /* $NetBSD: logwtmpx.c,v 1.2 2003/08/07 16:44:59 agc Exp $ */
2961e3a84Sjdolecek
3961e3a84Sjdolecek /*
4961e3a84Sjdolecek * Copyright (c) 1988, 1993
5961e3a84Sjdolecek * The Regents of the University of California. All rights reserved.
6961e3a84Sjdolecek *
7961e3a84Sjdolecek * Redistribution and use in source and binary forms, with or without
8961e3a84Sjdolecek * modification, are permitted provided that the following conditions
9961e3a84Sjdolecek * are met:
10961e3a84Sjdolecek * 1. Redistributions of source code must retain the above copyright
11961e3a84Sjdolecek * notice, this list of conditions and the following disclaimer.
12961e3a84Sjdolecek * 2. Redistributions in binary form must reproduce the above copyright
13961e3a84Sjdolecek * notice, this list of conditions and the following disclaimer in the
14961e3a84Sjdolecek * documentation and/or other materials provided with the distribution.
15*eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
16961e3a84Sjdolecek * may be used to endorse or promote products derived from this software
17961e3a84Sjdolecek * without specific prior written permission.
18961e3a84Sjdolecek *
19961e3a84Sjdolecek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20961e3a84Sjdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21961e3a84Sjdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22961e3a84Sjdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23961e3a84Sjdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24961e3a84Sjdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25961e3a84Sjdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26961e3a84Sjdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27961e3a84Sjdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28961e3a84Sjdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29961e3a84Sjdolecek * SUCH DAMAGE.
30961e3a84Sjdolecek */
31961e3a84Sjdolecek
32961e3a84Sjdolecek #include <sys/cdefs.h>
33961e3a84Sjdolecek #if defined(LIBC_SCCS) && !defined(lint)
34961e3a84Sjdolecek #if 0
35961e3a84Sjdolecek static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
36961e3a84Sjdolecek #else
37*eb7c1594Sagc __RCSID("$NetBSD: logwtmpx.c,v 1.2 2003/08/07 16:44:59 agc Exp $");
38961e3a84Sjdolecek #endif
39961e3a84Sjdolecek #endif /* LIBC_SCCS and not lint */
40961e3a84Sjdolecek
41961e3a84Sjdolecek #include <sys/types.h>
42961e3a84Sjdolecek #include <sys/file.h>
43961e3a84Sjdolecek #include <sys/time.h>
44961e3a84Sjdolecek #include <sys/stat.h>
45961e3a84Sjdolecek #include <sys/wait.h>
46961e3a84Sjdolecek
47961e3a84Sjdolecek #include <assert.h>
48961e3a84Sjdolecek #include <string.h>
49961e3a84Sjdolecek #include <time.h>
50961e3a84Sjdolecek #include <unistd.h>
51961e3a84Sjdolecek #include <utmp.h>
52961e3a84Sjdolecek #include <utmpx.h>
53961e3a84Sjdolecek #include <util.h>
54961e3a84Sjdolecek
55961e3a84Sjdolecek void
logwtmpx(const char * line,const char * name,const char * host,int status,int type)56961e3a84Sjdolecek logwtmpx(const char *line, const char *name, const char *host, int status,
57961e3a84Sjdolecek int type)
58961e3a84Sjdolecek {
59961e3a84Sjdolecek struct utmpx ut;
60961e3a84Sjdolecek
61961e3a84Sjdolecek _DIAGASSERT(line != NULL);
62961e3a84Sjdolecek _DIAGASSERT(name != NULL);
63961e3a84Sjdolecek _DIAGASSERT(host != NULL);
64961e3a84Sjdolecek
65961e3a84Sjdolecek (void)memset(&ut, 0, sizeof(ut));
66961e3a84Sjdolecek (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
67961e3a84Sjdolecek (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
68961e3a84Sjdolecek (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
69961e3a84Sjdolecek ut.ut_type = type;
70961e3a84Sjdolecek if (WIFEXITED(status))
71961e3a84Sjdolecek ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
72961e3a84Sjdolecek if (WIFSIGNALED(status))
73961e3a84Sjdolecek ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
74961e3a84Sjdolecek (void)gettimeofday(&ut.ut_tv, NULL);
75961e3a84Sjdolecek (void)updwtmpx(_PATH_WTMPX, &ut);
76961e3a84Sjdolecek }
77