1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
26 /* XXX used for tty name array in login. */
32 login (const struct utmp *ut)
34 char tty[PATH_MAX + UT_LINESIZE];
37 struct utmp_data data;
40 found_tty = ttyname_r (STDIN_FILENO, tty, sizeof tty);
42 found_tty = ttyname_r (STDOUT_FILENO, tty, sizeof tty);
44 found_tty = ttyname_r (STDERR_FILENO, tty, sizeof tty);
48 /* Tell that we want to use the UTMP file. */
49 if (utmpname (_PATH_UTMP) != 0)
57 /* We only want to insert the name of the tty without path. */
58 ttyp = basename (tty);
60 /* Position to record for this tty. */
62 tmp.ut_type = USER_PROCESS;
64 strncpy (tmp.ut_line, ttyp, UT_LINESIZE);
66 /* Read the record. */
67 if (getutline_r (&tmp, &old, &data) >= 0 || errno == ESRCH)
70 /* We have to fake the old entry because this `login'
71 function does not fit well into the UTMP file
73 old->ut_type = ut->ut_type;
75 pututline_r (ut, &data);
78 /* Close UTMP file. */
83 /* Update the WTMP file. Here we have to add a new entry. */
84 if (utmpname (_PATH_WTMP) != 0)
86 /* Open the WTMP file. */
89 /* Position at end of file. */
90 data.loc_utmp = lseek (data.ut_fd, 0, SEEK_END);
91 if (data.loc_utmp != -1)
94 /* We have to fake the old entry because this `login'
95 function does not fit well into the UTMP file handling
97 data.ubuf.ut_type = ut->ut_type;
99 pututline_r (ut, &data);
102 /* Close WTMP file. */