* path.cc (cygdrive_getmntent): Do not skip over drives of type

DRIVE_REMOVABLE.
* fhandler.cc (fhandler_base::lseek): Be more paranoid when constructing
offsets from 64 bit value.
* syscalls.cc (logout): Avoid temp buffer memcpy since new scheme does not
require it.
(utmp_data): Rework as a macro which returns a pointer into a buffer.
(getutent): Use new buffer allocation mechanism to grab a utmp buffer.
(getutid): Ditto.
(pututline): Ditto.
This commit is contained in:
Christopher Faylor 2003-08-05 04:49:44 +00:00
parent 3fea2e4087
commit 4423d92489
4 changed files with 64 additions and 32 deletions

View File

@ -1,3 +1,19 @@
2003-08-05 Pavel Tsekov <ptsekov@gmx.net>
* path.cc (cygdrive_getmntent): Do not skip over drives of type
DRIVE_REMOVABLE.
2003-08-05 Christopher Faylor <cgf@redhat.com>
* fhandler.cc (fhandler_base::lseek): Be more paranoid when
constructing offsets from 64 bit value.
* syscalls.cc (logout): Avoid temp buffer memcpy since new scheme does
not require it.
(utmp_data): Rework as a macro which returns a pointer into a buffer.
(getutent): Use new buffer allocation mechanism to grab a utmp buffer.
(getutid): Ditto.
(pututline): Ditto.
2003-08-05 Pavel Tsekov <ptsekov@gmx.net> 2003-08-05 Pavel Tsekov <ptsekov@gmx.net>
* fhandler_disk_file.cc (fhandler_cygdrive::readdir): Do not change * fhandler_disk_file.cc (fhandler_cygdrive::readdir): Do not change

View File

@ -891,13 +891,13 @@ fhandler_base::lseek (_off64_t offset, int whence)
DWORD win32_whence = whence == SEEK_SET ? FILE_BEGIN DWORD win32_whence = whence == SEEK_SET ? FILE_BEGIN
: (whence == SEEK_CUR ? FILE_CURRENT : FILE_END); : (whence == SEEK_CUR ? FILE_CURRENT : FILE_END);
LONG off_low = offset & 0xffffffff; LONG off_low = ((__uint64_t) offset) & 0xffffffffLL;
LONG *poff_high, off_high; LONG *poff_high, off_high;
if (!wincap.has_64bit_file_access ()) if (!wincap.has_64bit_file_access ())
poff_high = NULL; poff_high = NULL;
else else
{ {
off_high = offset >> 32; off_high = ((__uint64_t) offset) >> 32LL;
poff_high = &off_high; poff_high = &off_high;
} }

View File

@ -2539,8 +2539,7 @@ cygdrive_getmntent ()
break; break;
__small_sprintf (native_path, "%c:\\", drive); __small_sprintf (native_path, "%c:\\", drive);
if (GetDriveType (native_path) == DRIVE_REMOVABLE || if (GetFileAttributes (native_path) == INVALID_FILE_ATTRIBUTES)
GetFileAttributes (native_path) == INVALID_FILE_ATTRIBUTES)
{ {
available_drives &= ~mask; available_drives &= ~mask;
continue; continue;

View File

@ -2548,17 +2548,14 @@ logout (char *line)
strncpy (ut_buf.ut_line, line, sizeof ut_buf.ut_line); strncpy (ut_buf.ut_line, line, sizeof ut_buf.ut_line);
setutent (); setutent ();
ut = getutline (&ut_buf); ut = getutline (&ut_buf);
if (ut) if (ut)
{ {
int fd; int fd;
/* We can't use ut further since it's a pointer to the static utmp_data ut->ut_type = DEAD_PROCESS;
area (see below) and would get overwritten in pututline(). So we memset (ut->ut_user, 0, sizeof ut->ut_user);
copy it back to the local ut_buf. */ time (&ut->ut_time);
memcpy (&ut_buf, ut, sizeof ut_buf);
ut_buf.ut_type = DEAD_PROCESS;
memset (ut_buf.ut_user, 0, sizeof ut_buf.ut_user);
time (&ut_buf.ut_time);
/* Writing to wtmp must be atomic to prevent mixed up data. */ /* Writing to wtmp must be atomic to prevent mixed up data. */
char mutex_name[MAX_PATH]; char mutex_name[MAX_PATH];
HANDLE mutex = CreateMutex (NULL, FALSE, HANDLE mutex = CreateMutex (NULL, FALSE,
@ -2569,6 +2566,7 @@ logout (char *line)
if ((fd = open (_PATH_WTMP, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0) if ((fd = open (_PATH_WTMP, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0)
{ {
write (fd, &ut_buf, sizeof ut_buf); write (fd, &ut_buf, sizeof ut_buf);
debug_printf ("set logout time for %s", line);
close (fd); close (fd);
} }
if (mutex) if (mutex)
@ -2576,9 +2574,9 @@ logout (char *line)
ReleaseMutex (mutex); ReleaseMutex (mutex);
CloseHandle (mutex); CloseHandle (mutex);
} }
memset (ut_buf.ut_line, 0, sizeof ut_buf.ut_line); memset (ut->ut_line, 0, sizeof ut_buf.ut_line);
ut_buf.ut_time = 0; ut->ut_time = 0;
pututline (&ut_buf); pututline (ut);
endutent (); endutent ();
} }
return 1; return 1;
@ -2588,8 +2586,6 @@ static int utmp_fd = -1;
static bool utmp_readonly = false; static bool utmp_readonly = false;
static char *utmp_file = (char *) _PATH_UTMP; static char *utmp_file = (char *) _PATH_UTMP;
static struct utmp utmp_data;
static void static void
internal_setutent (bool force_readwrite) internal_setutent (bool force_readwrite)
{ {
@ -2645,6 +2641,16 @@ utmpname (_CONST char *file)
debug_printf ("New UTMP file: %s", utmp_file); debug_printf ("New UTMP file: %s", utmp_file);
} }
/* Note: do not make NO_COPY */
static struct utmp utmp_data_buf[16];
static unsigned utix = 0;
#define nutdbuf (sizeof (utmp_data_buf) / sizeof (utmp_data_buf[0]))
#define utmp_data ({ \
if (utix > nutdbuf) \
utix = 0; \
utmp_data_buf + utix++; \
})
extern "C" struct utmp * extern "C" struct utmp *
getutent () getutent ()
{ {
@ -2655,9 +2661,11 @@ getutent ()
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
if (read (utmp_fd, &utmp_data, sizeof utmp_data) != sizeof utmp_data)
utmp *ut = utmp_data;
if (read (utmp_fd, ut, sizeof *ut) != sizeof *ut)
return NULL; return NULL;
return &utmp_data; return ut;
} }
extern "C" struct utmp * extern "C" struct utmp *
@ -2672,7 +2680,9 @@ getutid (struct utmp *id)
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data)
utmp *ut = utmp_data;
while (read (utmp_fd, ut, sizeof *ut) == sizeof *ut)
{ {
switch (id->ut_type) switch (id->ut_type)
{ {
@ -2680,15 +2690,15 @@ getutid (struct utmp *id)
case BOOT_TIME: case BOOT_TIME:
case OLD_TIME: case OLD_TIME:
case NEW_TIME: case NEW_TIME:
if (id->ut_type == utmp_data.ut_type) if (id->ut_type == ut->ut_type)
return &utmp_data; return ut;
break; break;
case INIT_PROCESS: case INIT_PROCESS:
case LOGIN_PROCESS: case LOGIN_PROCESS:
case USER_PROCESS: case USER_PROCESS:
case DEAD_PROCESS: case DEAD_PROCESS:
if (strncmp (id->ut_id, utmp_data.ut_id, UT_IDLEN) == 0) if (strncmp (id->ut_id, ut->ut_id, UT_IDLEN) == 0)
return &utmp_data; return ut;
break; break;
default: default:
return NULL; return NULL;
@ -2709,14 +2719,14 @@ getutline (struct utmp *line)
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data)
{ utmp *ut = utmp_data;
if ((utmp_data.ut_type == LOGIN_PROCESS || while (read (utmp_fd, ut, sizeof *ut) == sizeof *ut)
utmp_data.ut_type == USER_PROCESS) && if ((ut->ut_type == LOGIN_PROCESS ||
!strncmp (utmp_data.ut_line, line->ut_line, ut->ut_type == USER_PROCESS) &&
sizeof utmp_data.ut_line)) !strncmp (ut->ut_line, line->ut_line, sizeof (ut->ut_line)))
return &utmp_data; return ut;
}
return NULL; return NULL;
} }
@ -2728,7 +2738,14 @@ pututline (struct utmp *ut)
return; return;
internal_setutent (true); internal_setutent (true);
if (utmp_fd < 0) if (utmp_fd < 0)
return; {
debug_printf ("error: utmp_fd %d", utmp_fd);
return;
}
debug_printf ("ut->ut_type %d, ut->ut_pid %d, ut->ut_line '%s', ut->ut_id '%s'\n",
ut->ut_type, ut->ut_pid, ut->ut_line, ut->ut_id);
debug_printf ("ut->ut_user '%s', ut->ut_host '%s'\n",
ut->ut_user, ut->ut_host);
/* Read/write to utmp must be atomic to prevent overriding data /* Read/write to utmp must be atomic to prevent overriding data
by concurrent processes. */ by concurrent processes. */
char mutex_name[MAX_PATH]; char mutex_name[MAX_PATH];