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