1*59a92d18SAlex Hornung /* $NetBSD: logwtmpx.c,v 1.2 2003/08/07 16:44:59 agc Exp $ */
2*59a92d18SAlex Hornung
3*59a92d18SAlex Hornung /*
4*59a92d18SAlex Hornung * Copyright (c) 1988, 1993
5*59a92d18SAlex Hornung * The Regents of the University of California. All rights reserved.
6*59a92d18SAlex Hornung *
7*59a92d18SAlex Hornung * Redistribution and use in source and binary forms, with or without
8*59a92d18SAlex Hornung * modification, are permitted provided that the following conditions
9*59a92d18SAlex Hornung * are met:
10*59a92d18SAlex Hornung * 1. Redistributions of source code must retain the above copyright
11*59a92d18SAlex Hornung * notice, this list of conditions and the following disclaimer.
12*59a92d18SAlex Hornung * 2. Redistributions in binary form must reproduce the above copyright
13*59a92d18SAlex Hornung * notice, this list of conditions and the following disclaimer in the
14*59a92d18SAlex Hornung * documentation and/or other materials provided with the distribution.
15*59a92d18SAlex Hornung * 3. Neither the name of the University nor the names of its contributors
16*59a92d18SAlex Hornung * may be used to endorse or promote products derived from this software
17*59a92d18SAlex Hornung * without specific prior written permission.
18*59a92d18SAlex Hornung *
19*59a92d18SAlex Hornung * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*59a92d18SAlex Hornung * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*59a92d18SAlex Hornung * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*59a92d18SAlex Hornung * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*59a92d18SAlex Hornung * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*59a92d18SAlex Hornung * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*59a92d18SAlex Hornung * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*59a92d18SAlex Hornung * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*59a92d18SAlex Hornung * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*59a92d18SAlex Hornung * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*59a92d18SAlex Hornung * SUCH DAMAGE.
30*59a92d18SAlex Hornung */
31*59a92d18SAlex Hornung
32*59a92d18SAlex Hornung #include <sys/cdefs.h>
33*59a92d18SAlex Hornung
34*59a92d18SAlex Hornung #include <sys/types.h>
35*59a92d18SAlex Hornung #include <sys/file.h>
36*59a92d18SAlex Hornung #include <sys/time.h>
37*59a92d18SAlex Hornung #include <sys/stat.h>
38*59a92d18SAlex Hornung #include <sys/wait.h>
39*59a92d18SAlex Hornung
40*59a92d18SAlex Hornung #include <assert.h>
41*59a92d18SAlex Hornung #include <string.h>
42*59a92d18SAlex Hornung #include <time.h>
43*59a92d18SAlex Hornung #include <unistd.h>
44*59a92d18SAlex Hornung #include <utmpx.h>
45*59a92d18SAlex Hornung #include <libutil.h>
46*59a92d18SAlex Hornung
47*59a92d18SAlex Hornung void
logwtmpx(const char * line,const char * name,const char * host,int status,int type)48*59a92d18SAlex Hornung logwtmpx(const char *line, const char *name, const char *host, int status,
49*59a92d18SAlex Hornung int type)
50*59a92d18SAlex Hornung {
51*59a92d18SAlex Hornung struct utmpx ut;
52*59a92d18SAlex Hornung
53*59a92d18SAlex Hornung _DIAGASSERT(line != NULL);
54*59a92d18SAlex Hornung _DIAGASSERT(name != NULL);
55*59a92d18SAlex Hornung _DIAGASSERT(host != NULL);
56*59a92d18SAlex Hornung
57*59a92d18SAlex Hornung (void)memset(&ut, 0, sizeof(ut));
58*59a92d18SAlex Hornung (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
59*59a92d18SAlex Hornung (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
60*59a92d18SAlex Hornung (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
61*59a92d18SAlex Hornung ut.ut_type = type;
62*59a92d18SAlex Hornung if (WIFEXITED(status))
63*59a92d18SAlex Hornung ut.ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
64*59a92d18SAlex Hornung if (WIFSIGNALED(status))
65*59a92d18SAlex Hornung ut.ut_exit.e_termination = (uint16_t)WTERMSIG(status);
66*59a92d18SAlex Hornung (void)gettimeofday(&ut.ut_tv, NULL);
67*59a92d18SAlex Hornung (void)updwtmpx(_PATH_WTMPX, &ut);
68*59a92d18SAlex Hornung }
69*59a92d18SAlex Hornung
70