Fix obscure bug where the working directory would not be restored to its
[unix-history] / usr / src / lib / libutil / logout.c
CommitLineData
2db26d41 1/*
f376fd72
KB
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
2db26d41 4 *
1343342a 5 * %sccs.include.redist.c%
2db26d41
KB
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
f376fd72 9static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) %G%";
2db26d41
KB
10#endif /* LIBC_SCCS and not lint */
11
12#include <sys/types.h>
2db26d41 13#include <sys/time.h>
6bcd9886
KB
14
15#include <fcntl.h>
2db26d41 16#include <utmp.h>
6bcd9886
KB
17#include <unistd.h>
18#include <stdlib.h>
19#include <string.h>
2db26d41 20
70ad55f8 21typedef struct utmp UTMP;
825856b4 22
6bcd9886 23int
2db26d41
KB
24logout(line)
25 register char *line;
26{
70ad55f8
KB
27 register int fd;
28 UTMP ut;
2db26d41 29 int rval;
2db26d41 30
6bcd9886 31 if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
2db26d41 32 return(0);
825856b4 33 rval = 0;
6bcd9886 34 while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
70ad55f8 35 if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
2db26d41 36 continue;
70ad55f8
KB
37 bzero(ut.ut_name, UT_NAMESIZE);
38 bzero(ut.ut_host, UT_HOSTSIZE);
2db26d41 39 (void)time(&ut.ut_time);
6bcd9886
KB
40 (void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR);
41 (void)write(fd, &ut, sizeof(UTMP));
825856b4 42 rval = 1;
2db26d41 43 }
70ad55f8 44 (void)close(fd);
2db26d41
KB
45 return(rval);
46}