1*59a92d18SAlex Hornung /* $NetBSD: logoutx.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/time.h>
36*59a92d18SAlex Hornung #include <sys/wait.h>
37*59a92d18SAlex Hornung
38*59a92d18SAlex Hornung #include <assert.h>
39*59a92d18SAlex Hornung #include <fcntl.h>
40*59a92d18SAlex Hornung #include <stdlib.h>
41*59a92d18SAlex Hornung #include <string.h>
42*59a92d18SAlex Hornung #include <time.h>
43*59a92d18SAlex Hornung #include <unistd.h>
44*59a92d18SAlex Hornung #include <libutil.h>
45*59a92d18SAlex Hornung #include <utmpx.h>
46*59a92d18SAlex Hornung
47*59a92d18SAlex Hornung int
logoutx(const char * line,int status,int type)48*59a92d18SAlex Hornung logoutx(const char *line, int status, int type)
49*59a92d18SAlex Hornung {
50*59a92d18SAlex Hornung struct utmpx *utp, ut;
51*59a92d18SAlex Hornung (void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
52*59a92d18SAlex Hornung if ((utp = getutxline(&ut)) == NULL) {
53*59a92d18SAlex Hornung endutxent();
54*59a92d18SAlex Hornung return 0;
55*59a92d18SAlex Hornung }
56*59a92d18SAlex Hornung utp->ut_type = type;
57*59a92d18SAlex Hornung if (WIFEXITED(status))
58*59a92d18SAlex Hornung utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
59*59a92d18SAlex Hornung if (WIFSIGNALED(status))
60*59a92d18SAlex Hornung utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status);
61*59a92d18SAlex Hornung (void)gettimeofday(&utp->ut_tv, NULL);
62*59a92d18SAlex Hornung (void)pututxline(utp);
63*59a92d18SAlex Hornung endutxent();
64*59a92d18SAlex Hornung return 1;
65*59a92d18SAlex Hornung }
66