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