1*eb7c1594Sagc /* $NetBSD: logoutx.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[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93";
36961e3a84Sjdolecek #else
37*eb7c1594Sagc __RCSID("$NetBSD: logoutx.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/time.h>
43961e3a84Sjdolecek #include <sys/wait.h>
44961e3a84Sjdolecek
45961e3a84Sjdolecek #include <assert.h>
46961e3a84Sjdolecek #include <fcntl.h>
47961e3a84Sjdolecek #include <stdlib.h>
48961e3a84Sjdolecek #include <string.h>
49961e3a84Sjdolecek #include <time.h>
50961e3a84Sjdolecek #include <unistd.h>
51961e3a84Sjdolecek #include <util.h>
52961e3a84Sjdolecek #include <utmp.h>
53961e3a84Sjdolecek #include <utmpx.h>
54961e3a84Sjdolecek
55961e3a84Sjdolecek int
logoutx(const char * line,int status,int type)56961e3a84Sjdolecek logoutx(const char *line, int status, int type)
57961e3a84Sjdolecek {
58961e3a84Sjdolecek struct utmpx *utp, ut;
59961e3a84Sjdolecek (void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
60961e3a84Sjdolecek if ((utp = getutxline(&ut)) == NULL) {
61961e3a84Sjdolecek endutxent();
62961e3a84Sjdolecek return 0;
63961e3a84Sjdolecek }
64961e3a84Sjdolecek utp->ut_type = type;
65961e3a84Sjdolecek if (WIFEXITED(status))
66961e3a84Sjdolecek utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status);
67961e3a84Sjdolecek if (WIFSIGNALED(status))
68961e3a84Sjdolecek utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status);
69961e3a84Sjdolecek (void)gettimeofday(&utp->ut_tv, NULL);
70961e3a84Sjdolecek (void)pututxline(utp);
71961e3a84Sjdolecek endutxent();
72961e3a84Sjdolecek return 1;
73961e3a84Sjdolecek }
74