* 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'.
@ -42,7 +57,7 @@
* security.cc (verify_token): Fix white space and style. * security.cc (verify_token): Fix white space and style.
Use type bool instead of BOOL and char. Use alloca Use type bool instead of BOOL and char. Use alloca
instead of malloc and free for my_grps. instead of malloc and free for my_grps.
2003-07-17 Corinna Vinschen <corinna@vinschen.de> 2003-07-17 Corinna Vinschen <corinna@vinschen.de>

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

@ -122,7 +122,7 @@ fhandler_disk_file::fstat_by_name (struct __stat64 *buf, path_conv *pc)
FILETIME ft = {}; FILETIME ft = {};
res = fstat_helper (buf, pc, ft, ft, ft, 0, 0); res = fstat_helper (buf, pc, ft, ft, ft, 0, 0);
} }
else else
{ {
debug_printf ("FindFirstFile failed for '%s', %E", (char *) *pc); debug_printf ("FindFirstFile failed for '%s', %E", (char *) *pc);
__seterrno (); __seterrno ();
@ -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]);
} }
@ -224,7 +224,7 @@ fhandler_socket::check_peer_secret_event (struct sockaddr_in* peer, int* secret)
{ {
char event_name[MAX_PATH]; char event_name[MAX_PATH];
secret_event_name (event_name, peer->sin_port, secret ?: connect_secret); secret_event_name (event_name, peer->sin_port, secret ?: connect_secret);
HANDLE ev = CreateEvent (&sec_all_nih, FALSE, FALSE, event_name); HANDLE ev = CreateEvent (&sec_all_nih, FALSE, FALSE, event_name);
if (!ev && GetLastError () == ERROR_ALREADY_EXISTS) if (!ev && GetLastError () == ERROR_ALREADY_EXISTS)
@ -956,7 +956,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags,
res = ret; res = ret;
/* Special handling for EPIPE and SIGPIPE. /* Special handling for EPIPE and SIGPIPE.
EPIPE is generated if the local end has been shut down on a connection EPIPE is generated if the local end has been shut down on a connection
oriented socket. In this case the process will also receive a SIGPIPE oriented socket. In this case the process will also receive a SIGPIPE
unless MSG_NOSIGNAL is set. */ unless MSG_NOSIGNAL is set. */

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

@ -35,45 +35,45 @@ ftok (const char *path, int id)
We will have to alias; leaving open the possibility that the same We will have to alias; leaving open the possibility that the same
key will be returned for multiple files. This possibility exists key will be returned for multiple files. This possibility exists
also on Linux; the question is, how to minimize this possibility. also on Linux; the question is, how to minimize this possibility.
How to solve? Well, based on C. Vinschen's research, the nFileIndex* How to solve? Well, based on C. Vinschen's research, the nFileIndex*
words vary as follows, on a partition with > 110,000 files words vary as follows, on a partition with > 110,000 files
nFileIndexHigh: 564 values between 0x00010000 -- 0xffff0000 nFileIndexHigh: 564 values between 0x00010000 -- 0xffff0000
nFileIndexLow : 103812 values between 0x00000000 -- 0x0003ffff nFileIndexLow : 103812 values between 0x00000000 -- 0x0003ffff
R. Collins suggests that these may represent a tree path, R. Collins suggests that these may represent a tree path,
and that it would require ~2.9M files to force the tree depth and that it would require ~2.9M files to force the tree depth
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
As it happens, the maximum number of devices is actually As it happens, the maximum number of devices is actually
FH_NDEV, not FH_DEVMASK, where FH_NDEV is currently 0x0000001d. FH_NDEV, not FH_DEVMASK, where FH_NDEV is currently 0x0000001d.
However, FH_NDEV grows as new device types are added. So However, FH_NDEV grows as new device types are added. So
currently the device number needs 5 bits, but later? Let's currently the device number needs 5 bits, but later? Let's
take a cue from Linux, and use the lower 8 bits (instead of the take a cue from Linux, and use the lower 8 bits (instead of the
lower 12 or 16) for the device (major?) number. lower 12 or 16) for the device (major?) number.
Similarly, while 'units' is an int (32bits), it is unclear Similarly, while 'units' is an int (32bits), it is unclear
how many of these are significant. For most devices, it seems that how many of these are significant. For most devices, it seems that
'units' is equivalent to 'minor'. For FH_TAPE, it's obvious that 'units' is equivalent to 'minor'. For FH_TAPE, it's obvious that
only 8 bits are important. However, for FH_SOCKET...it might be only 8 bits are important. However, for FH_SOCKET...it might be
as high as 16 significant bits. as high as 16 significant bits.
Let's assume that we only need 8 bits from device (major) and Let's assume that we only need 8 bits from device (major) and
only 8 bits from unit (minor). (On linux, only 8 bits of minor only 8 bits from unit (minor). (On linux, only 8 bits of minor
are used, and none from major). are used, and none from major).
---> so, we only need 0x00ff00ff (16 bits) of dev_t ---> so, we only need 0x00ff00ff (16 bits) of dev_t
---> we MUST have all 8 bits of id. ---> we MUST have all 8 bits of id.
---> So, we only have 64 - 8 - 16 = 40 bits for ino_t. But, we ---> So, we only have 64 - 8 - 16 = 40 bits for ino_t. But, we
need 0xffff0000 for nFileIndexHigh and 0x0003ffff for nFileIndexLow need 0xffff0000 for nFileIndexHigh and 0x0003ffff for nFileIndexLow
minimum, or 16 + 18 = 34 bits. Lucky us - we have 6 more bits minimum, or 16 + 18 = 34 bits. Lucky us - we have 6 more bits
to distribute. to distribute.
For lack of a better idea, we'll allocate 2 of the extra bits to For lack of a better idea, we'll allocate 2 of the extra bits to
nFileIndexHigh and 4 to nFileIndexLow. */ nFileIndexHigh and 4 to nFileIndexLow. */

View File

@ -332,7 +332,7 @@ list::match (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
for (int i = start + 1; i < nrecs; ++i) for (int i = start + 1; i < nrecs; ++i)
{ {
low = (addr >= recs[i].get_address ()) ? addr : recs[i].get_address (); low = (addr >= recs[i].get_address ()) ? addr : recs[i].get_address ();
high = recs[i].get_address () high = recs[i].get_address ()
+ (PAGE_CNT (recs[i].get_size ()) * getpagesize ()); + (PAGE_CNT (recs[i].get_size ()) * getpagesize ());
high = (addr + len < high) ? addr + len : high; high = (addr + len < high) ? addr + len : high;
if (low < high) if (low < high)
@ -565,7 +565,7 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, _off64_t off)
The offset is re-added when evaluating the return value. */ The offset is re-added when evaluating the return value. */
if (base) if (base)
base -= off - gran_off; base -= off - gran_off;
HANDLE h = fh->mmap (&base, gran_len, access, flags, gran_off); HANDLE h = fh->mmap (&base, gran_len, access, flags, gran_off);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
@ -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 ();
} }
@ -1304,7 +1304,7 @@ getdomainname (char *domain, size_t len)
/* This is only used by Win95 and NT <= 4.0. /* This is only used by Win95 and NT <= 4.0.
The registry names are language independent. The registry names are language independent.
FIXME: Handle DHCP on Win95. The DhcpDomain(s) may be available FIXME: Handle DHCP on Win95. The DhcpDomain(s) may be available
in ..VxD\DHCP\DhcpInfoXX\OptionInfo, RFC 1533 format */ in ..VxD\DHCP\DhcpInfoXX\OptionInfo, RFC 1533 format */
reg_key r (HKEY_LOCAL_MACHINE, KEY_READ, reg_key r (HKEY_LOCAL_MACHINE, KEY_READ,
@ -2014,7 +2014,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
fh = NULL; fh = NULL;
if (newfd >= 0) if (newfd >= 0)
fh = fdsock (newfd, "/dev/tcp", fd2s); fh = fdsock (newfd, "/dev/tcp", fd2s);
if (fh) if (fh)
{ {
*fd2p = newfd; *fd2p = newfd;
fh->set_connect_state (CONNECTED); fh->set_connect_state (CONNECTED);

View File

@ -1391,7 +1391,7 @@ static char special_chars[] =
"I" "J" "K" "L" "M" "N" "O" "P" "I" "J" "K" "L" "M" "N" "O" "P"
"Q" "R" "S" "T" "U" "V" "W" "X" "Q" "R" "S" "T" "U" "V" "W" "X"
"Y" "Z"; "Y" "Z";
static char special_introducers[] = static char special_introducers[] =
"anpcl"; "anpcl";
static char static char
@ -1434,7 +1434,7 @@ special_name (const char *s, int inc = 1)
} }
bool bool
fnunmunge (char *dst, const char *src) fnunmunge (char *dst, const char *src)
{ {
bool converted = false; bool converted = false;
char c; char c;

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

@ -288,7 +288,7 @@ List<pthread> pthread::threads;
/* member methods */ /* member methods */
pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0), pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0),
running (false), suspended (false), running (false), suspended (false),
cancelstate (0), canceltype (0), cancel_event (0), cancelstate (0), canceltype (0), cancel_event (0),
joiner (NULL), next (NULL), cleanup_stack (NULL) joiner (NULL), next (NULL), cleanup_stack (NULL)
{ {
@ -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;
@ -907,7 +907,7 @@ pthread_cond::unblock (const bool all)
{ {
unsigned long releaseable; unsigned long releaseable;
/* /*
* Block outgoing threads (and avoid simultanous unblocks) * Block outgoing threads (and avoid simultanous unblocks)
*/ */
mtx_out.lock (); mtx_out.lock ();
@ -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;
@ -971,20 +971,20 @@ pthread_cond::wait (pthread_mutex_t mutex, DWORD dwMilliseconds)
rv = pthread::cancelable_wait (sem_wait, dwMilliseconds, false); rv = pthread::cancelable_wait (sem_wait, dwMilliseconds, false);
mtx_out.lock (); mtx_out.lock ();
if (rv != WAIT_OBJECT_0) if (rv != WAIT_OBJECT_0)
{ {
/* /*
* It might happen that a signal is sent while the thread got canceled * It might happen that a signal is sent while the thread got canceled
* or timed out. Try to take one. * or timed out. Try to take one.
* 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);
@ -997,7 +997,7 @@ pthread_cond::wait (pthread_mutex_t mutex, DWORD dwMilliseconds)
mtx_in.unlock (); mtx_in.unlock ();
mtx_out.unlock (); mtx_out.unlock ();
mutex->lock (); mutex->lock ();
--mutex->condwaits; --mutex->condwaits;
@ -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))
@ -1129,7 +1129,7 @@ pthread_rwlock::rdlock ()
} }
while (writer || waiting_writers) while (writer || waiting_writers)
{ {
pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this); pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this);
++waiting_readers; ++waiting_readers;
@ -1162,14 +1162,14 @@ 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 ();
return result; return result;
@ -1190,7 +1190,7 @@ pthread_rwlock::wrlock ()
} }
while (writer || readers) while (writer || readers)
{ {
pthread_cleanup_push (pthread_rwlock::wrlock_cleanup, this); pthread_cleanup_push (pthread_rwlock::wrlock_cleanup, this);
++waiting_writers; ++waiting_writers;
@ -1220,7 +1220,7 @@ pthread_rwlock::trywrlock ()
result = EBUSY; result = EBUSY;
else else
writer = self; writer = self;
mtx.unlock (); mtx.unlock ();
return result; return result;
@ -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;
} }
} }
} }

View File

@ -540,7 +540,7 @@ wincapc::init ()
case 0: case 0:
caps = &wincap_2000; caps = &wincap_2000;
break; break;
case 1: case 1:
caps = &wincap_xp; caps = &wincap_xp;
break; break;