* exceptions.cc (ctrl_c_handler): Send SIGHUP when events occur only if there

is a tty associated with the process.  Send SIGHUP on CTRL_LOGOFF_EVENT.
* fhandler_tty.cc (fhandler_tty_slave::open): Adjust console open handle
counter regardless of whether this is a pty or tty.
(fhandler_tty_slave::open): Ditto.
(fhandler_tty_slave::dup): Ditto.
(fhandler_tty_common::set_close_on_exec): Ditto.
(fhandler_tty_master::init_console): Decrement console open handle counter
after init since it will now be handled by all tty open.
* syscalls.cc (setsid): Rework debugging output slightly.
This commit is contained in:
Christopher Faylor 2003-07-26 04:53:59 +00:00
parent ddb6762155
commit df04ae29b2
14 changed files with 231 additions and 223 deletions

View File

@ -1,3 +1,18 @@
2003-07-26 Christopher Faylor <cgf@redhat.com>
* exceptions.cc (ctrl_c_handler): Send SIGHUP when events occur only if
there is a tty associated with the process. Send SIGHUP on
CTRL_LOGOFF_EVENT.
* fhandler_tty.cc (fhandler_tty_slave::open): Adjust console open
handle counter regardless of whether this is a pty or tty.
(fhandler_tty_slave::open): Ditto.
(fhandler_tty_slave::dup): Ditto.
(fhandler_tty_common::set_close_on_exec): Ditto.
(fhandler_tty_master::init_console): Decrement console open handle
counter after init since it will now be handled by all tty open.
* syscalls.cc (setsid): Rework debugging output slightly.
2003-07-25 Christopher Faylor <cgf@redhat.com> 2003-07-25 Christopher Faylor <cgf@redhat.com>
* configure.in: Use 'install-sh -c'. * configure.in: Use 'install-sh -c'.

View File

@ -923,25 +923,29 @@ setup_handler (int sig, void *handler, struct sigaction& siga)
static BOOL WINAPI static BOOL WINAPI
ctrl_c_handler (DWORD type) ctrl_c_handler (DWORD type)
{ {
if (type == CTRL_LOGOFF_EVENT) static bool saw_close;
return TRUE;
/* Return FALSE to prevent an "End task" dialog box from appearing /* Return FALSE to prevent an "End task" dialog box from appearing
for each Cygwin process window that's open when the computer for each Cygwin process window that's open when the computer
is shut down or console window is closed. */ is shut down or console window is closed. */
if (type == CTRL_SHUTDOWN_EVENT) if (type == CTRL_SHUTDOWN_EVENT)
{ {
#if 0 #if 0
/* Don't send a signal. Only NT service applications and their child /* Don't send a signal. Only NT service applications and their child
processes will receive this event and the services typically already processes will receive this event and the services typically already
handle the shutdown action when getting the SERVICE_CONTROL_SHUTDOWN handle the shutdown action when getting the SERVICE_CONTROL_SHUTDOWN
control message. */ control message. */
sig_send (NULL, SIGTERM); sig_send (NULL, SIGTERM);
#endif #endif
return FALSE; return FALSE;
} }
if (type == CTRL_CLOSE_EVENT)
if (myself->ctty != -1
&& (type == CTRL_CLOSE_EVENT || (!saw_close && type == CTRL_LOGOFF_EVENT)))
{ {
if (type == CTRL_CLOSE_EVENT)
saw_close = true;
sig_send (NULL, SIGHUP); sig_send (NULL, SIGHUP);
return FALSE; return FALSE;
} }

View File

@ -226,7 +226,7 @@ fhandler_disk_file::fstat_helper (struct __stat64 *buf, path_conv *pc,
/* Although the documentation indicates otherwise, it seems like /* Although the documentation indicates otherwise, it seems like
"inodes" on these devices are persistent, at least across reboots. */ "inodes" on these devices are persistent, at least across reboots. */
buf->st_ino = (((__ino64_t) nFileIndexHigh) << 32) buf->st_ino = (((__ino64_t) nFileIndexHigh) << 32)
| (__ino64_t) nFileIndexLow; | (__ino64_t) nFileIndexLow;
break; break;
default: default:
/* Either the nFileIndex* fields are unreliable or unavailable. Use the /* Either the nFileIndex* fields are unreliable or unavailable. Use the

View File

@ -639,30 +639,30 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer); bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer);
read_value ("Identifier", REG_SZ); read_value ("Identifier", REG_SZ);
bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer); bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer);
if (wincap.is_winnt ()) if (wincap.is_winnt ())
{ {
read_value ("~Mhz", REG_DWORD); read_value ("~Mhz", REG_DWORD);
bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer); bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer);
print ("flags :"); print ("flags :");
if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE))
print (" 3dnow"); print (" 3dnow");
if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE)) if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE))
print (" cx8"); print (" cx8");
if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED)) if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED))
print (" fpu"); print (" fpu");
if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE))
print (" mmx"); print (" mmx");
if (IsProcessorFeaturePresent (PF_PAE_ENABLED)) if (IsProcessorFeaturePresent (PF_PAE_ENABLED))
print (" pae"); print (" pae");
if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE)) if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE))
print (" tsc"); print (" tsc");
if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE))
print (" sse"); print (" sse");
if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE))
print (" sse2"); print (" sse2");
} }
} }
else else
{ {
bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number); bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number);
@ -671,12 +671,12 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
maxf &= 0xffff; maxf &= 0xffff;
vendor_id[3] = 0; vendor_id[3] = 0;
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", (char *)vendor_id); bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", (char *)vendor_id);
unsigned cpu_mhz = 0; unsigned cpu_mhz = 0;
if (wincap.is_winnt ()) if (wincap.is_winnt ())
{ {
read_value ("~Mhz", REG_DWORD); read_value ("~Mhz", REG_DWORD);
cpu_mhz = *(DWORD *)szBuffer; cpu_mhz = *(DWORD *)szBuffer;
} }
if (maxf >= 1) if (maxf >= 1)
{ {
unsigned features2, features1, extra_info, cpuid_sig; unsigned features2, features1, extra_info, cpuid_sig;
@ -722,10 +722,10 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
// could implement a lookup table here if someone needs it // could implement a lookup table here if someone needs it
strcpy (szBuffer, "unknown"); strcpy (szBuffer, "unknown");
} }
if (wincap.is_winnt ()) if (wincap.is_winnt ())
{ {
bufptr += __small_sprintf (bufptr, "type : %s\n" bufptr += __small_sprintf (bufptr, "type : %s\n"
"cpu family : %d\n" "cpu family : %d\n"
"model : %d\n" "model : %d\n"
"model name : %s\n" "model name : %s\n"
"stepping : %d\n" "stepping : %d\n"
@ -744,28 +744,28 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize)
apic_id, apic_id,
cpu_mhz, cpu_mhz,
(features1 & (1 << 0)) ? "yes" : "no"); (features1 & (1 << 0)) ? "yes" : "no");
} }
else else
{ {
bufptr += __small_sprintf (bufptr, "type : %s\n" bufptr += __small_sprintf (bufptr, "type : %s\n"
"cpu family : %d\n" "cpu family : %d\n"
"model : %d\n" "model : %d\n"
"model name : %s\n" "model name : %s\n"
"stepping : %d\n" "stepping : %d\n"
"brand id : %d\n" "brand id : %d\n"
"cpu count : %d\n" "cpu count : %d\n"
"apic id : %d\n" "apic id : %d\n"
"fpu : %s\n", "fpu : %s\n",
type_str, type_str,
family, family,
model, model,
szBuffer, szBuffer,
stepping, stepping,
brand_id, brand_id,
cpu_count, cpu_count,
apic_id, apic_id,
(features1 & (1 << 0)) ? "yes" : "no"); (features1 & (1 << 0)) ? "yes" : "no");
} }
print ("flags :"); print ("flags :");
if (features1 & (1 << 0)) if (features1 & (1 << 0))
print (" fpu"); print (" fpu");

View File

@ -49,7 +49,7 @@ secret_event_name (char *buf, short port, int *secret_ptr)
{ {
__small_sprintf (buf, "%scygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x", __small_sprintf (buf, "%scygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x",
wincap.has_terminal_services () ? "Global\\" : "", wincap.has_terminal_services () ? "Global\\" : "",
port, port,
secret_ptr [0], secret_ptr [1], secret_ptr [0], secret_ptr [1],
secret_ptr [2], secret_ptr [3]); secret_ptr [2], secret_ptr [3]);
} }

View File

@ -555,25 +555,22 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
set_output_handle (to_master_local); set_output_handle (to_master_local);
set_open_status (); set_open_status ();
if (!output_done_event) if (fhandler_console::open_fhs++ == 0 && !output_done_event
&& wincap.pty_needs_alloc_console ())
{ {
if (fhandler_console::open_fhs++ == 0 BOOL b;
&& wincap.pty_needs_alloc_console ()) HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih);
termios_printf ("CreateWindowStation %p, %E", h);
if (h)
{ {
BOOL b; b = SetProcessWindowStation (h);
HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih); termios_printf ("SetProcessWindowStation %d, %E", b);
termios_printf ("CreateWindowStation %p, %E", h);
if (h)
{
b = SetProcessWindowStation (h);
termios_printf ("SetProcessWindowStation %d, %E", b);
}
b = AllocConsole (); // will cause flashing if workstation
// stuff fails
termios_printf ("%d = AllocConsole ()", b);
} }
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs); b = AllocConsole (); // will cause flashing if workstation
// stuff fails
termios_printf ("%d = AllocConsole ()", b);
} }
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
termios_printf ("tty%d opened", ttynum); termios_printf ("tty%d opened", ttynum);
return 1; return 1;
@ -582,12 +579,9 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
int int
fhandler_tty_slave::close () fhandler_tty_slave::close ()
{ {
if (!output_done_event) if (!--fhandler_console::open_fhs && myself->ctty == -1)
{ FreeConsole ();
if (!--fhandler_console::open_fhs && myself->ctty == -1) termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs);
FreeConsole ();
termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs);
}
return fhandler_tty_common::close (); return fhandler_tty_common::close ();
} }
@ -855,11 +849,8 @@ fhandler_tty_slave::read (void *ptr, size_t& len)
int int
fhandler_tty_slave::dup (fhandler_base *child) fhandler_tty_slave::dup (fhandler_base *child)
{ {
if (!output_done_event) fhandler_console::open_fhs++;
{ termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
fhandler_console::open_fhs++;
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
}
return fhandler_tty_common::dup (child); return fhandler_tty_common::dup (child);
} }
@ -1253,11 +1244,8 @@ fhandler_tty_common::set_close_on_exec (int val)
void void
fhandler_tty_slave::fixup_after_fork (HANDLE parent) fhandler_tty_slave::fixup_after_fork (HANDLE parent)
{ {
if (!output_done_event) fhandler_console::open_fhs++;
{ termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
fhandler_console::open_fhs++;
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
}
fhandler_tty_common::fixup_after_fork (parent); fhandler_tty_common::fixup_after_fork (parent);
} }
@ -1317,6 +1305,7 @@ fhandler_tty_master::init_console ()
return -1; return -1;
console->init (INVALID_HANDLE_VALUE, GENERIC_READ | GENERIC_WRITE, O_BINARY); console->init (INVALID_HANDLE_VALUE, GENERIC_READ | GENERIC_WRITE, O_BINARY);
fhandler_console::open_fhs--; /* handled when individual fds are opened */
console->set_r_no_interrupt (1); console->set_r_no_interrupt (1);
return 0; return 0;
} }

View File

@ -45,7 +45,7 @@ ftok (const char *path, int id)
to increase and reveal more bit usage. to increase and reveal more bit usage.
Implementation details: dev_t is 32bits, but is formed by Implementation details: dev_t is 32bits, but is formed by
device(32bits) << 16 | unit(32bits) device(32bits) << 16 | unit(32bits)
But device is ACTUALLY == status & FH_DEVMASK, where FH_DEVMASK But device is ACTUALLY == status & FH_DEVMASK, where FH_DEVMASK
is 0x00000fff --> 12 bits is 0x00000fff --> 12 bits

View File

@ -843,7 +843,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
if (!base && !(flags & MAP_FIXED)) if (!base && !(flags & MAP_FIXED))
base = MapViewOfFileEx (h, access, high, low, len, NULL); base = MapViewOfFileEx (h, access, high, low, len, NULL);
debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%D, " debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%D, "
"len:%u, addr:%x)", base, h, access, off, len, *addr); "len:%u, addr:%x)", base, h, access, off, len, *addr);
if (!base || ((flags & MAP_FIXED) && base != *addr)) if (!base || ((flags & MAP_FIXED) && base != *addr))
{ {
if (!base) if (!base)

View File

@ -522,7 +522,7 @@ fdsock (int &fd, const char *name, SOCKET soc)
debug_printf ("not setting socket inheritance since winsock2_active %d", debug_printf ("not setting socket inheritance since winsock2_active %d",
winsock2_active); winsock2_active);
fhandler_socket *fh = (fhandler_socket *) fhandler_socket *fh = (fhandler_socket *)
cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name, NULL, cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name, NULL,
tolower (name[5]) - 'a'); tolower (name[5]) - 'a');
if (!fh) if (!fh)
return NULL; return NULL;
@ -775,14 +775,14 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen)
{ {
bool was_blocking = false; bool was_blocking = false;
if (!fh->is_nonblocking ()) if (!fh->is_nonblocking ())
{ {
int nonblocking = 1; int nonblocking = 1;
fh->ioctl (FIONBIO, &nonblocking); fh->ioctl (FIONBIO, &nonblocking);
was_blocking = true; was_blocking = true;
} }
res = fh->connect (name, namelen); res = fh->connect (name, namelen);
if (was_blocking) if (was_blocking)
{ {
if (res == -1 && get_errno () == EINPROGRESS) if (res == -1 && get_errno () == EINPROGRESS)
{ {
size_t fds_size = howmany (fd + 1, NFDBITS) * sizeof (fd_mask); size_t fds_size = howmany (fd + 1, NFDBITS) * sizeof (fd_mask);
@ -794,7 +794,7 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen)
FD_SET (fd, except_fds); FD_SET (fd, except_fds);
res = cygwin_select (fd + 1, NULL, write_fds, except_fds, NULL); res = cygwin_select (fd + 1, NULL, write_fds, except_fds, NULL);
if (res > 0 && FD_ISSET (fd, except_fds)) if (res > 0 && FD_ISSET (fd, except_fds))
{ {
res = -1; res = -1;
for (;;) for (;;)
{ {
@ -803,7 +803,7 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen)
cygwin_getsockopt (fd, SOL_SOCKET, SO_ERROR, cygwin_getsockopt (fd, SOL_SOCKET, SO_ERROR,
(void *) &err, &len); (void *) &err, &len);
if (err) if (err)
{ {
set_errno (err); set_errno (err);
break; break;
} }
@ -811,9 +811,9 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen)
} }
} }
else if (res > 0) else if (res > 0)
res = 0; res = 0;
else else
{ {
WSASetLastError (WSAEINPROGRESS); WSASetLastError (WSAEINPROGRESS);
set_winsock_errno (); set_winsock_errno ();
} }

View File

@ -757,7 +757,7 @@ verify_token (HANDLE token, cygsid &usersid, user_groups &groups, BOOL *pintern)
debug_printf ("GetTokenInformation(my_token, TokenGroups): %E"); debug_printf ("GetTokenInformation(my_token, TokenGroups): %E");
else if (!groups.issetgroups ()) /* setgroups was never called */ else if (!groups.issetgroups ()) /* setgroups was never called */
ret = sid_in_token_groups (my_grps, groups.pgsid) ret = sid_in_token_groups (my_grps, groups.pgsid)
|| groups.pgsid == usersid; || groups.pgsid == usersid;
else /* setgroups was called */ else /* setgroups was called */
{ {
struct __group32 *gr; struct __group32 *gr;
@ -1430,15 +1430,15 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type,
psd = (PSECURITY_DESCRIPTOR) & sd_buf[0]; psd = (PSECURITY_DESCRIPTOR) & sd_buf[0];
DWORD len = sizeof (sd_buf); DWORD len = sizeof (sd_buf);
if (ERROR_SUCCESS != RegGetKeySecurity ((HKEY) handle, if (ERROR_SUCCESS != RegGetKeySecurity ((HKEY) handle,
DACL_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION |
GROUP_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
OWNER_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION,
psd, &len)) psd, &len))
{ {
__seterrno (); __seterrno ();
debug_printf ("RegGetKeySecurity %E"); debug_printf ("RegGetKeySecurity %E");
psd = NULL; psd = NULL;
} }
} }
else else
{ {
@ -1447,7 +1447,7 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type,
GROUP_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
OWNER_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION,
NULL, NULL, NULL, NULL, &psd)) NULL, NULL, NULL, NULL, &psd))
{ {
__seterrno (); __seterrno ();
debug_printf ("GetSecurityInfo %E"); debug_printf ("GetSecurityInfo %E");
psd = NULL; psd = NULL;

View File

@ -284,14 +284,14 @@ setsid (void)
{ {
if (myself->ctty >= 0 && fhandler_console::open_fhs <= 0) if (myself->ctty >= 0 && fhandler_console::open_fhs <= 0)
{ {
syscall_printf ("open_fhs %d, freeing console", syscall_printf ("freeing console");
fhandler_console::open_fhs);
FreeConsole (); FreeConsole ();
} }
myself->ctty = -1; myself->ctty = -1;
myself->sid = getpid (); myself->sid = getpid ();
myself->pgid = getpid (); myself->pgid = getpid ();
syscall_printf ("sid %d, pgid %d, ctty %d", myself->sid, myself->pgid, myself->ctty); syscall_printf ("sid %d, pgid %d, ctty %d, open_fhs %d", myself->sid,
myself->pgid, myself->ctty, fhandler_console::open_fhs);
return myself->sid; return myself->sid;
} }
@ -2105,7 +2105,7 @@ seteuid32 (__uid32_t uid)
if (usersid != (origpsid = cygheap->user.orig_sid ())) if (usersid != (origpsid = cygheap->user.orig_sid ()))
psid2 = usersid; psid2 = usersid;
if (sec_acl ((PACL) dacl_buf, FALSE, origpsid, psid2)) if (sec_acl ((PACL) dacl_buf, FALSE, origpsid, psid2))
{ {
TOKEN_DEFAULT_DACL tdacl; TOKEN_DEFAULT_DACL tdacl;
tdacl.DefaultDacl = (PACL) dacl_buf; tdacl.DefaultDacl = (PACL) dacl_buf;
if (!SetTokenInformation (ptok, TokenDefaultDacl, if (!SetTokenInformation (ptok, TokenDefaultDacl,
@ -2562,7 +2562,7 @@ logout (char *line)
/* 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,
shared_name (mutex_name, "wtmp_mutex", 0)); shared_name (mutex_name, "wtmp_mutex", 0));
if (mutex) if (mutex)
while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED) while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED)
; ;
@ -2603,11 +2603,11 @@ internal_setutent (bool force_readwrite)
case we try again for reading only unless the process calls case we try again for reading only unless the process calls
pututline() (==force_readwrite) in which case opening just fails. */ pututline() (==force_readwrite) in which case opening just fails. */
if (utmp_fd < 0 && !force_readwrite) if (utmp_fd < 0 && !force_readwrite)
{ {
utmp_fd = open (utmp_file, O_RDONLY | O_BINARY); utmp_fd = open (utmp_file, O_RDONLY | O_BINARY);
if (utmp_fd >= 0) if (utmp_fd >= 0)
utmp_readonly = true; utmp_readonly = true;
} }
} }
else else
lseek (utmp_fd, 0, SEEK_SET); lseek (utmp_fd, 0, SEEK_SET);
@ -2653,7 +2653,7 @@ getutent ()
{ {
internal_setutent (false); internal_setutent (false);
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
if (read (utmp_fd, &utmp_data, sizeof utmp_data) != sizeof utmp_data) if (read (utmp_fd, &utmp_data, sizeof utmp_data) != sizeof utmp_data)
return NULL; return NULL;
@ -2670,7 +2670,7 @@ getutid (struct utmp *id)
{ {
internal_setutent (false); internal_setutent (false);
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data) while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data)
{ {
@ -2707,7 +2707,7 @@ getutline (struct utmp *line)
{ {
internal_setutent (false); internal_setutent (false);
if (utmp_fd < 0) if (utmp_fd < 0)
return NULL; return NULL;
} }
while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data) while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data)
{ {
@ -2754,18 +2754,18 @@ extern "C"
long gethostid(void) long gethostid(void)
{ {
unsigned data[13] = {0x92895012, unsigned data[13] = {0x92895012,
0x10293412, 0x10293412,
0x29602018, 0x29602018,
0x81928167, 0x81928167,
0x34601329, 0x34601329,
0x75630198, 0x75630198,
0x89860395, 0x89860395,
0x62897564, 0x62897564,
0x00194362, 0x00194362,
0x20548593, 0x20548593,
0x96839102, 0x96839102,
0x12219854, 0x12219854,
0x00290012}; 0x00290012};
bool has_cpuid = false; bool has_cpuid = false;
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
@ -2780,12 +2780,12 @@ long gethostid(void)
{ {
debug_printf ("486 processor"); debug_printf ("486 processor");
if (can_set_flag (0x00200000)) if (can_set_flag (0x00200000))
{ {
debug_printf ("processor supports CPUID instruction"); debug_printf ("processor supports CPUID instruction");
has_cpuid = true; has_cpuid = true;
} }
else else
debug_printf ("processor does not support CPUID instruction"); debug_printf ("processor does not support CPUID instruction");
} }
if (has_cpuid) if (has_cpuid)
{ {
@ -2793,22 +2793,22 @@ long gethostid(void)
cpuid (&maxf, &unused[0], &unused[1], &unused[2], 0); cpuid (&maxf, &unused[0], &unused[1], &unused[2], 0);
maxf &= 0xffff; maxf &= 0xffff;
if (maxf >= 1) if (maxf >= 1)
{ {
unsigned features; unsigned features;
cpuid (&data[0], &unused[0], &unused[1], &features, 1); cpuid (&data[0], &unused[0], &unused[1], &features, 1);
if (features & (1 << 18)) if (features & (1 << 18))
{ {
debug_printf ("processor has psn"); debug_printf ("processor has psn");
if (maxf >= 3) if (maxf >= 3)
{ {
cpuid (&unused[0], &unused[1], &data[1], &data[2], 3); cpuid (&unused[0], &unused[1], &data[1], &data[2], 3);
debug_printf ("Processor PSN: %04x-%04x-%04x-%04x-%04x-%04x", debug_printf ("Processor PSN: %04x-%04x-%04x-%04x-%04x-%04x",
data[0] >> 16, data[0] & 0xffff, data[2] >> 16, data[2] & 0xffff, data[1] >> 16, data[1] & 0xffff); data[0] >> 16, data[0] & 0xffff, data[2] >> 16, data[2] & 0xffff, data[1] >> 16, data[1] & 0xffff);
} }
} }
else else
debug_printf ("processor does not have psn"); debug_printf ("processor does not have psn");
} }
} }
UUID Uuid; UUID Uuid;
@ -2822,8 +2822,8 @@ long gethostid(void)
// Unfortunately Windows will sometimes pick a virtual Ethernet card // Unfortunately Windows will sometimes pick a virtual Ethernet card
// e.g. VMWare Virtual Ethernet Adaptor // e.g. VMWare Virtual Ethernet Adaptor
debug_printf ("MAC address of first Ethernet card: %02x:%02x:%02x:%02x:%02x:%02x", debug_printf ("MAC address of first Ethernet card: %02x:%02x:%02x:%02x:%02x:%02x",
Uuid.Data4[2], Uuid.Data4[3], Uuid.Data4[4], Uuid.Data4[2], Uuid.Data4[3], Uuid.Data4[4],
Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]); Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]);
} }
else else
{ {
@ -2839,16 +2839,16 @@ long gethostid(void)
GetDiskFreeSpace ("C:\\", NULL, NULL, NULL, (DWORD *)&data[11]); GetDiskFreeSpace ("C:\\", NULL, NULL, NULL, (DWORD *)&data[11]);
debug_printf ("hostid entropy: %08x %08x %08x %08x " debug_printf ("hostid entropy: %08x %08x %08x %08x "
"%08x %08x %08x %08x " "%08x %08x %08x %08x "
"%08x %08x %08x %08x " "%08x %08x %08x %08x "
"%08x", "%08x",
data[0], data[1], data[0], data[1],
data[2], data[3], data[2], data[3],
data[4], data[5], data[4], data[5],
data[6], data[7], data[6], data[7],
data[8], data[9], data[8], data[9],
data[10], data[11], data[10], data[11],
data[12]); data[12]);
long hostid = 0x40291372; long hostid = 0x40291372;
// a random hashing algorithm // a random hashing algorithm

View File

@ -856,8 +856,8 @@ pthread_cond::pthread_cond (pthread_condattr *attr) :
if (attr) if (attr)
if (attr->shared != PTHREAD_PROCESS_PRIVATE) if (attr->shared != PTHREAD_PROCESS_PRIVATE)
{ {
magic = 0; magic = 0;
return; return;
} }
verifyable_mutex_obj = &mtx_in; verifyable_mutex_obj = &mtx_in;
@ -918,19 +918,19 @@ pthread_cond::unblock (const bool all)
unsigned long released; unsigned long released;
if (!pending) if (!pending)
{ {
/* /*
* Block incoming threads until all waiting threads are released. * Block incoming threads until all waiting threads are released.
*/ */
mtx_in.lock (); mtx_in.lock ();
/* /*
* Calculate releaseable again because threads can enter until * Calculate releaseable again because threads can enter until
* the semaphore has been taken, but they can not leave, therefore pending * the semaphore has been taken, but they can not leave, therefore pending
* is unchanged and releaseable can only get higher * is unchanged and releaseable can only get higher
*/ */
releaseable = waiting - pending; releaseable = waiting - pending;
} }
released = all ? releaseable : 1; released = all ? releaseable : 1;
pending += released; pending += released;
@ -980,11 +980,11 @@ pthread_cond::wait (pthread_mutex_t mutex, DWORD dwMilliseconds)
* If the thread gets one than a signal|broadcast is in progress. * If the thread gets one than a signal|broadcast is in progress.
*/ */
if (WaitForSingleObject (sem_wait, 0) == WAIT_OBJECT_0) if (WaitForSingleObject (sem_wait, 0) == WAIT_OBJECT_0)
/* /*
* thread got cancelled ot timed out while a signalling is in progress. * thread got cancelled ot timed out while a signalling is in progress.
* Set wait result back to signaled * Set wait result back to signaled
*/ */
rv = WAIT_OBJECT_0; rv = WAIT_OBJECT_0;
} }
InterlockedDecrement ((long *)&waiting); InterlockedDecrement ((long *)&waiting);
@ -1068,8 +1068,8 @@ pthread_rwlock::pthread_rwlock (pthread_rwlockattr *attr) :
if (attr) if (attr)
if (attr->shared != PTHREAD_PROCESS_PRIVATE) if (attr->shared != PTHREAD_PROCESS_PRIVATE)
{ {
magic = 0; magic = 0;
return; return;
} }
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj)) if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
@ -1162,12 +1162,12 @@ pthread_rwlock::tryrdlock ()
{ {
struct RWLOCK_READER *reader = new struct RWLOCK_READER; struct RWLOCK_READER *reader = new struct RWLOCK_READER;
if (reader) if (reader)
{ {
reader->thread = self; reader->thread = self;
add_reader (reader); add_reader (reader);
} }
else else
result = EAGAIN; result = EAGAIN;
} }
mtx.unlock (); mtx.unlock ();
@ -1237,10 +1237,10 @@ pthread_rwlock::unlock ()
if (writer) if (writer)
{ {
if (writer != self) if (writer != self)
{ {
result = EPERM; result = EPERM;
goto DONE; goto DONE;
} }
writer = NULL; writer = NULL;
} }
@ -1249,10 +1249,10 @@ pthread_rwlock::unlock ()
struct RWLOCK_READER *reader = lookup_reader (self); struct RWLOCK_READER *reader = lookup_reader (self);
if (!reader) if (!reader)
{ {
result = EPERM; result = EPERM;
goto DONE; goto DONE;
} }
remove_reader (reader); remove_reader (reader);
delete reader; delete reader;
@ -1336,13 +1336,13 @@ pthread_rwlock::_fixup_after_fork ()
while (*temp) while (*temp)
{ {
if ((*temp)->thread == self) if ((*temp)->thread == self)
temp = &((*temp)->next); temp = &((*temp)->next);
else else
{ {
struct RWLOCK_READER *cur = *temp; struct RWLOCK_READER *cur = *temp;
*temp = (*temp)->next; *temp = (*temp)->next;
delete cur; delete cur;
} }
} }
} }