11.2Schristos/* $NetBSD: compat_logoutx.c,v 1.2 2009/01/11 02:57:18 christos Exp $ */ 21.2Schristos 31.2Schristos/* 41.2Schristos * Copyright (c) 1988, 1993 51.2Schristos * The Regents of the University of California. All rights reserved. 61.2Schristos * 71.2Schristos * Redistribution and use in source and binary forms, with or without 81.2Schristos * modification, are permitted provided that the following conditions 91.2Schristos * are met: 101.2Schristos * 1. Redistributions of source code must retain the above copyright 111.2Schristos * notice, this list of conditions and the following disclaimer. 121.2Schristos * 2. Redistributions in binary form must reproduce the above copyright 131.2Schristos * notice, this list of conditions and the following disclaimer in the 141.2Schristos * documentation and/or other materials provided with the distribution. 151.2Schristos * 3. Neither the name of the University nor the names of its contributors 161.2Schristos * may be used to endorse or promote products derived from this software 171.2Schristos * without specific prior written permission. 181.2Schristos * 191.2Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201.2Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211.2Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221.2Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231.2Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241.2Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251.2Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261.2Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271.2Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281.2Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291.2Schristos * SUCH DAMAGE. 301.2Schristos */ 311.2Schristos 321.2Schristos#include <sys/cdefs.h> 331.2Schristos#if defined(LIBC_SCCS) && !defined(lint) 341.2Schristos#if 0 351.2Schristosstatic char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93"; 361.2Schristos#else 371.2Schristos__RCSID("$NetBSD: compat_logoutx.c,v 1.2 2009/01/11 02:57:18 christos Exp $"); 381.2Schristos#endif 391.2Schristos#endif /* LIBC_SCCS and not lint */ 401.2Schristos 411.2Schristos#include <sys/types.h> 421.2Schristos#include <sys/time.h> 431.2Schristos#include <sys/wait.h> 441.2Schristos 451.2Schristos#include <assert.h> 461.2Schristos#include <fcntl.h> 471.2Schristos#include <stdlib.h> 481.2Schristos#include <string.h> 491.2Schristos#include <time.h> 501.2Schristos#include <unistd.h> 511.2Schristos#include <util.h> 521.2Schristos#include <utmp.h> 531.2Schristos#include <utmpx.h> 541.2Schristos 551.2Schristosint 561.2Schristoslogoutx(const char *line, int status, int type) 571.2Schristos{ 581.2Schristos struct utmpx *utp, ut; 591.2Schristos (void)strlcpy(ut.ut_line, line, sizeof(ut.ut_line)); 601.2Schristos if ((utp = getutxline(&ut)) == NULL) { 611.2Schristos endutxent(); 621.2Schristos return 0; 631.2Schristos } 641.2Schristos utp->ut_type = type; 651.2Schristos if (WIFEXITED(status)) 661.2Schristos utp->ut_exit.e_exit = (uint16_t)WEXITSTATUS(status); 671.2Schristos if (WIFSIGNALED(status)) 681.2Schristos utp->ut_exit.e_termination = (uint16_t)WTERMSIG(status); 691.2Schristos (void)gettimeofday(&utp->ut_tv, NULL); 701.2Schristos (void)pututxline(utp); 711.2Schristos endutxent(); 721.2Schristos return 1; 731.2Schristos} 74