X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/734aad71947a79037af64f74c683f5eb36fe6065..065eae9f38780a3602538caa52399f41f061a88e:/util/logout.c diff --git a/util/logout.c b/util/logout.c index 520a45e..2452014 100644 --- a/util/logout.c +++ b/util/logout.c @@ -1,10 +1,8 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999, 2005, 2010 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -55,39 +53,51 @@ * SUCH DAMAGE. */ - #include #include -#include +#ifdef UTMP_COMPAT #include +#endif /* UTMP_COMPAT */ +#include +#include #include -#include #include -typedef struct utmp UTMP; - int -logout(line) - register char *line; +logout(char *line) { - register int fd; - UTMP ut; - int rval; + struct utmpx *ux, utx; +#ifdef UTMP_COMPAT +#ifdef __LP64__ + struct utmp32 u; +#else /* __LP64__ */ + struct utmp u; +#endif /* __LP64__ */ + int which; +#endif /* UTMP_COMPAT */ - if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0) - return(0); - rval = 0; - while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) { - if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE)) - continue; - bzero(ut.ut_name, UT_NAMESIZE); - bzero(ut.ut_host, UT_HOSTSIZE); - (void)time(&ut.ut_time); - (void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR); - (void)write(fd, &ut, sizeof(UTMP)); - rval = 1; + bzero(&utx, sizeof(utx)); + strncpy(utx.ut_line, line, sizeof(utx.ut_line)); + utx.ut_type = UTMPX_AUTOFILL_MASK | UTMPX_DEAD_IF_CORRESPONDING_MASK | DEAD_PROCESS; + (void)gettimeofday(&utx.ut_tv, NULL); + UTMPX_LOCK(&__utx__); + __setutxent(&__utx__); + ux = __pututxline(&__utx__, &utx); + __endutxent(&__utx__); + if (!ux) { + UTMPX_UNLOCK(&__utx__); + return 0; + } +#ifdef UTMP_COMPAT + if (__utx__.utfile_system) { /* only if we are using _PATH_UTMPX */ + which = _utmp_compat(ux, &u); + if (which & UTMP_COMPAT_UTMP0) + _write_utmp(&u, 0); + else if (which & UTMP_COMPAT_UTMP1) + _write_utmp(&u, 1); } - (void)close(fd); - return(rval); +#endif /* UTMP_COMPAT */ + UTMPX_UNLOCK(&__utx__); + return 1; }