utmp
Pierre A. Humblet
Pierre.Humblet@ieee.org
Sat Mar 8 03:07:00 GMT 2003
Chris,
Here is GetComputerName replacing cygwin_gethostname.
When testing I found an old bug: ut_id wasn't set although
login() uses it in getutid(), called from pututline().
utmp is now closed with endutent() (that's what sshd does too)
and I optimized setutent.
Please review & apply.
Pierre
2003-03-07 Pierre Humblet <pierre.humblet@ieee.org>
* tty.cc (create_tty_master): Call GetComputerName instead of
cygwin_gethostname. Set ut_id.
* syscalls.cc (login): Call endutent.
(setutent): Do not seek after a fresh open.
-------------- next part --------------
Index: tty.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/tty.cc,v
retrieving revision 1.50
diff -u -p -r1.50 tty.cc
--- tty.cc 26 Nov 2002 20:32:39 -0000 1.50
+++ tty.cc 8 Mar 2003 02:45:09 -0000
@@ -81,12 +81,18 @@ create_tty_master (int ttynum)
{
/* Log utmp entry */
struct utmp our_utmp;
+ DWORD len = sizeof our_utmp.ut_host;
bzero ((char *) &our_utmp, sizeof (utmp));
(void) time (&our_utmp.ut_time);
strncpy (our_utmp.ut_name, getlogin (), sizeof (our_utmp.ut_name));
- cygwin_gethostname (our_utmp.ut_host, sizeof (our_utmp.ut_host));
+ GetComputerName (our_utmp.ut_host, &len);
__small_sprintf (our_utmp.ut_line, "tty%d", ttynum);
+ if ((len = strlen (our_utmp.ut_line)) >= UT_IDLEN)
+ len -= UT_IDLEN;
+ else
+ len = 0;
+ strncpy (our_utmp.ut_id, our_utmp.ut_line + len, UT_IDLEN);
our_utmp.ut_type = USER_PROCESS;
our_utmp.ut_pid = myself->pid;
myself->ctty = ttynum;
Index: syscalls.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v
retrieving revision 1.249
diff -u -p -r1.249 syscalls.cc
--- syscalls.cc 7 Mar 2003 16:35:56 -0000 1.249
+++ syscalls.cc 8 Mar 2003 02:45:23 -0000
@@ -2472,6 +2472,7 @@ login (struct utmp *ut)
register int fd;
pututline (ut);
+ endutent ();
if ((fd = open (_PATH_WTMP, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0)
{
(void) write (fd, (char *) ut, sizeof (struct utmp));
@@ -2551,10 +2552,9 @@ setutent ()
{
sigframe thisframe (mainthread);
if (utmp_fd == -2)
- {
- utmp_fd = open (utmp_file, O_RDWR);
- }
- lseek (utmp_fd, 0, SEEK_SET);
+ utmp_fd = open (utmp_file, O_RDWR);
+ else
+ lseek (utmp_fd, 0, SEEK_SET);
}
extern "C" void
More information about the Cygwin-patches
mailing list