From df04ae29b258b89bbd4991bd862a03ac56430e4e Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 26 Jul 2003 04:53:59 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 17 ++++- winsup/cygwin/exceptions.cc | 12 ++- winsup/cygwin/fhandler_disk_file.cc | 4 +- winsup/cygwin/fhandler_proc.cc | 82 ++++++++++----------- winsup/cygwin/fhandler_socket.cc | 6 +- winsup/cygwin/fhandler_tty.cc | 51 +++++-------- winsup/cygwin/ipc.cc | 22 +++--- winsup/cygwin/mmap.cc | 6 +- winsup/cygwin/net.cc | 18 ++--- winsup/cygwin/path.cc | 4 +- winsup/cygwin/security.cc | 22 +++--- winsup/cygwin/syscalls.cc | 110 ++++++++++++++-------------- winsup/cygwin/thread.cc | 98 ++++++++++++------------- winsup/cygwin/wincap.cc | 2 +- 14 files changed, 231 insertions(+), 223 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ac065769a..2c9ec5043 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,18 @@ +2003-07-26 Christopher Faylor + + * 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 * configure.in: Use 'install-sh -c'. @@ -42,7 +57,7 @@ * security.cc (verify_token): Fix white space and style. 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 diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 3c8bf39c9..e7c304185 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -923,25 +923,29 @@ setup_handler (int sig, void *handler, struct sigaction& siga) static BOOL WINAPI ctrl_c_handler (DWORD type) { - if (type == CTRL_LOGOFF_EVENT) - return TRUE; + static bool saw_close; /* Return FALSE to prevent an "End task" dialog box from appearing for each Cygwin process window that's open when the computer is shut down or console window is closed. */ + if (type == CTRL_SHUTDOWN_EVENT) { #if 0 /* 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 control message. */ sig_send (NULL, SIGTERM); #endif 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); return FALSE; } diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 29206bb0c..be634bda2 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -122,7 +122,7 @@ fhandler_disk_file::fstat_by_name (struct __stat64 *buf, path_conv *pc) FILETIME ft = {}; res = fstat_helper (buf, pc, ft, ft, ft, 0, 0); } - else + else { debug_printf ("FindFirstFile failed for '%s', %E", (char *) *pc); __seterrno (); @@ -226,7 +226,7 @@ fhandler_disk_file::fstat_helper (struct __stat64 *buf, path_conv *pc, /* Although the documentation indicates otherwise, it seems like "inodes" on these devices are persistent, at least across reboots. */ buf->st_ino = (((__ino64_t) nFileIndexHigh) << 32) - | (__ino64_t) nFileIndexLow; + | (__ino64_t) nFileIndexLow; break; default: /* Either the nFileIndex* fields are unreliable or unavailable. Use the diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 6ce815999..d7f5a1a3b 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -639,30 +639,30 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize) bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", szBuffer); read_value ("Identifier", REG_SZ); bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer); - if (wincap.is_winnt ()) - { + if (wincap.is_winnt ()) + { read_value ("~Mhz", REG_DWORD); bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer); print ("flags :"); if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)) - print (" 3dnow"); + print (" 3dnow"); if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE)) - print (" cx8"); + print (" cx8"); if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED)) - print (" fpu"); + print (" fpu"); if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) - print (" mmx"); + print (" mmx"); if (IsProcessorFeaturePresent (PF_PAE_ENABLED)) - print (" pae"); + print (" pae"); if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE)) - print (" tsc"); + print (" tsc"); if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE)) - print (" sse"); + print (" sse"); if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE)) - print (" sse2"); + print (" sse2"); } - } + } else { bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number); @@ -671,12 +671,12 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize) maxf &= 0xffff; vendor_id[3] = 0; bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", (char *)vendor_id); - unsigned cpu_mhz = 0; - if (wincap.is_winnt ()) - { + unsigned cpu_mhz = 0; + if (wincap.is_winnt ()) + { read_value ("~Mhz", REG_DWORD); cpu_mhz = *(DWORD *)szBuffer; - } + } if (maxf >= 1) { 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 strcpy (szBuffer, "unknown"); } - if (wincap.is_winnt ()) - { - bufptr += __small_sprintf (bufptr, "type : %s\n" - "cpu family : %d\n" + if (wincap.is_winnt ()) + { + bufptr += __small_sprintf (bufptr, "type : %s\n" + "cpu family : %d\n" "model : %d\n" "model name : %s\n" "stepping : %d\n" @@ -744,28 +744,28 @@ format_proc_cpuinfo (char *destbuf, size_t maxsize) apic_id, cpu_mhz, (features1 & (1 << 0)) ? "yes" : "no"); - } - else - { - bufptr += __small_sprintf (bufptr, "type : %s\n" - "cpu family : %d\n" - "model : %d\n" - "model name : %s\n" - "stepping : %d\n" - "brand id : %d\n" - "cpu count : %d\n" - "apic id : %d\n" - "fpu : %s\n", - type_str, - family, - model, - szBuffer, - stepping, - brand_id, - cpu_count, - apic_id, - (features1 & (1 << 0)) ? "yes" : "no"); - } + } + else + { + bufptr += __small_sprintf (bufptr, "type : %s\n" + "cpu family : %d\n" + "model : %d\n" + "model name : %s\n" + "stepping : %d\n" + "brand id : %d\n" + "cpu count : %d\n" + "apic id : %d\n" + "fpu : %s\n", + type_str, + family, + model, + szBuffer, + stepping, + brand_id, + cpu_count, + apic_id, + (features1 & (1 << 0)) ? "yes" : "no"); + } print ("flags :"); if (features1 & (1 << 0)) print (" fpu"); diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 5adeaefcb..cbfd56236 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -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", wincap.has_terminal_services () ? "Global\\" : "", - port, + port, secret_ptr [0], secret_ptr [1], 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]; - + secret_event_name (event_name, peer->sin_port, secret ?: connect_secret); HANDLE ev = CreateEvent (&sec_all_nih, FALSE, FALSE, event_name); if (!ev && GetLastError () == ERROR_ALREADY_EXISTS) @@ -956,7 +956,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags, res = ret; /* Special handling for EPIPE and SIGPIPE. - + 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 unless MSG_NOSIGNAL is set. */ diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 6e3a93364..44eb21e6b 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -555,25 +555,22 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t) set_output_handle (to_master_local); 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 - && wincap.pty_needs_alloc_console ()) + BOOL b; + HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih); + termios_printf ("CreateWindowStation %p, %E", h); + if (h) { - BOOL b; - HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih); - 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); + b = SetProcessWindowStation (h); + termios_printf ("SetProcessWindowStation %d, %E", 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); return 1; @@ -582,12 +579,9 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t) int fhandler_tty_slave::close () { - if (!output_done_event) - { - if (!--fhandler_console::open_fhs && myself->ctty == -1) - FreeConsole (); - termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs); - } + if (!--fhandler_console::open_fhs && myself->ctty == -1) + FreeConsole (); + termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs); return fhandler_tty_common::close (); } @@ -855,11 +849,8 @@ fhandler_tty_slave::read (void *ptr, size_t& len) int 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); } @@ -1253,11 +1244,8 @@ fhandler_tty_common::set_close_on_exec (int val) void 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); } @@ -1317,6 +1305,7 @@ fhandler_tty_master::init_console () return -1; 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); return 0; } diff --git a/winsup/cygwin/ipc.cc b/winsup/cygwin/ipc.cc index d37f45947..c89b23e21 100644 --- a/winsup/cygwin/ipc.cc +++ b/winsup/cygwin/ipc.cc @@ -35,45 +35,45 @@ ftok (const char *path, int id) We will have to alias; leaving open the possibility that the same key will be returned for multiple files. This possibility exists also on Linux; the question is, how to minimize this possibility. - + How to solve? Well, based on C. Vinschen's research, the nFileIndex* words vary as follows, on a partition with > 110,000 files nFileIndexHigh: 564 values between 0x00010000 -- 0xffff0000 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 to increase and reveal more bit usage. - + 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 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. However, FH_NDEV grows as new device types are added. So 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 lower 12 or 16) for the device (major?) number. - + Similarly, while 'units' is an int (32bits), it is unclear how many of these are significant. For most devices, it seems 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 as high as 16 significant bits. - + 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 are used, and none from major). ---> so, we only need 0x00ff00ff (16 bits) of dev_t - + ---> we MUST have all 8 bits of id. - + ---> So, we only have 64 - 8 - 16 = 40 bits for ino_t. But, we need 0xffff0000 for nFileIndexHigh and 0x0003ffff for nFileIndexLow minimum, or 16 + 18 = 34 bits. Lucky us - we have 6 more bits to distribute. - + For lack of a better idea, we'll allocate 2 of the extra bits to nFileIndexHigh and 4 to nFileIndexLow. */ diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 32287b1cb..7d8809e47 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -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) { 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 ()); high = (addr + len < high) ? addr + len : 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. */ if (base) base -= off - gran_off; - + HANDLE h = fh->mmap (&base, gran_len, access, flags, gran_off); 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)) base = MapViewOfFileEx (h, access, high, low, len, NULL); 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) diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 25d82e110..3db52f883 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -522,7 +522,7 @@ fdsock (int &fd, const char *name, SOCKET soc) debug_printf ("not setting socket inheritance since winsock2_active %d", winsock2_active); 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'); if (!fh) return NULL; @@ -775,14 +775,14 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen) { bool was_blocking = false; if (!fh->is_nonblocking ()) - { + { int nonblocking = 1; fh->ioctl (FIONBIO, &nonblocking); was_blocking = true; } res = fh->connect (name, namelen); if (was_blocking) - { + { if (res == -1 && get_errno () == EINPROGRESS) { 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); res = cygwin_select (fd + 1, NULL, write_fds, except_fds, NULL); if (res > 0 && FD_ISSET (fd, except_fds)) - { + { res = -1; for (;;) { @@ -803,7 +803,7 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen) cygwin_getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len); if (err) - { + { set_errno (err); break; } @@ -811,9 +811,9 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen) } } else if (res > 0) - res = 0; + res = 0; else - { + { WSASetLastError (WSAEINPROGRESS); set_winsock_errno (); } @@ -1304,7 +1304,7 @@ getdomainname (char *domain, size_t len) /* This is only used by Win95 and NT <= 4.0. 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 */ reg_key r (HKEY_LOCAL_MACHINE, KEY_READ, @@ -2014,7 +2014,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser, fh = NULL; if (newfd >= 0) fh = fdsock (newfd, "/dev/tcp", fd2s); - if (fh) + if (fh) { *fd2p = newfd; fh->set_connect_state (CONNECTED); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index ff474fdf5..3ea799b3f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -1391,7 +1391,7 @@ static char special_chars[] = "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"; -static char special_introducers[] = +static char special_introducers[] = "anpcl"; static char @@ -1434,7 +1434,7 @@ special_name (const char *s, int inc = 1) } bool -fnunmunge (char *dst, const char *src) +fnunmunge (char *dst, const char *src) { bool converted = false; char c; diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 0310f5c8b..d76964f91 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -757,7 +757,7 @@ verify_token (HANDLE token, cygsid &usersid, user_groups &groups, BOOL *pintern) debug_printf ("GetTokenInformation(my_token, TokenGroups): %E"); else if (!groups.issetgroups ()) /* setgroups was never called */ ret = sid_in_token_groups (my_grps, groups.pgsid) - || groups.pgsid == usersid; + || groups.pgsid == usersid; else /* setgroups was called */ { struct __group32 *gr; @@ -1430,15 +1430,15 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, psd = (PSECURITY_DESCRIPTOR) & sd_buf[0]; DWORD len = sizeof (sd_buf); if (ERROR_SUCCESS != RegGetKeySecurity ((HKEY) handle, - DACL_SECURITY_INFORMATION | - GROUP_SECURITY_INFORMATION | - OWNER_SECURITY_INFORMATION, - psd, &len)) - { - __seterrno (); - debug_printf ("RegGetKeySecurity %E"); - psd = NULL; - } + DACL_SECURITY_INFORMATION | + GROUP_SECURITY_INFORMATION | + OWNER_SECURITY_INFORMATION, + psd, &len)) + { + __seterrno (); + debug_printf ("RegGetKeySecurity %E"); + psd = NULL; + } } else { @@ -1447,7 +1447,7 @@ get_nt_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, NULL, NULL, NULL, NULL, &psd)) - { + { __seterrno (); debug_printf ("GetSecurityInfo %E"); psd = NULL; diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index b95c93999..3755be589 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -284,14 +284,14 @@ setsid (void) { if (myself->ctty >= 0 && fhandler_console::open_fhs <= 0) { - syscall_printf ("open_fhs %d, freeing console", - fhandler_console::open_fhs); + syscall_printf ("freeing console"); FreeConsole (); } myself->ctty = -1; myself->sid = 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; } @@ -2105,7 +2105,7 @@ seteuid32 (__uid32_t uid) if (usersid != (origpsid = cygheap->user.orig_sid ())) psid2 = usersid; if (sec_acl ((PACL) dacl_buf, FALSE, origpsid, psid2)) - { + { TOKEN_DEFAULT_DACL tdacl; tdacl.DefaultDacl = (PACL) dacl_buf; if (!SetTokenInformation (ptok, TokenDefaultDacl, @@ -2562,7 +2562,7 @@ logout (char *line) /* Writing to wtmp must be atomic to prevent mixed up data. */ char mutex_name[MAX_PATH]; HANDLE mutex = CreateMutex (NULL, FALSE, - shared_name (mutex_name, "wtmp_mutex", 0)); + shared_name (mutex_name, "wtmp_mutex", 0)); if (mutex) 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 pututline() (==force_readwrite) in which case opening just fails. */ if (utmp_fd < 0 && !force_readwrite) - { + { utmp_fd = open (utmp_file, O_RDONLY | O_BINARY); if (utmp_fd >= 0) utmp_readonly = true; - } + } } else lseek (utmp_fd, 0, SEEK_SET); @@ -2653,7 +2653,7 @@ getutent () { internal_setutent (false); if (utmp_fd < 0) - return NULL; + return NULL; } if (read (utmp_fd, &utmp_data, sizeof utmp_data) != sizeof utmp_data) return NULL; @@ -2670,7 +2670,7 @@ getutid (struct utmp *id) { internal_setutent (false); if (utmp_fd < 0) - return NULL; + return NULL; } while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data) { @@ -2707,7 +2707,7 @@ getutline (struct utmp *line) { internal_setutent (false); if (utmp_fd < 0) - return NULL; + return NULL; } while (read (utmp_fd, &utmp_data, sizeof utmp_data) == sizeof utmp_data) { @@ -2754,18 +2754,18 @@ extern "C" long gethostid(void) { unsigned data[13] = {0x92895012, - 0x10293412, - 0x29602018, - 0x81928167, - 0x34601329, - 0x75630198, - 0x89860395, - 0x62897564, - 0x00194362, - 0x20548593, - 0x96839102, - 0x12219854, - 0x00290012}; + 0x10293412, + 0x29602018, + 0x81928167, + 0x34601329, + 0x75630198, + 0x89860395, + 0x62897564, + 0x00194362, + 0x20548593, + 0x96839102, + 0x12219854, + 0x00290012}; bool has_cpuid = false; sigframe thisframe (mainthread); @@ -2780,12 +2780,12 @@ long gethostid(void) { debug_printf ("486 processor"); if (can_set_flag (0x00200000)) - { - debug_printf ("processor supports CPUID instruction"); - has_cpuid = true; - } + { + debug_printf ("processor supports CPUID instruction"); + has_cpuid = true; + } else - debug_printf ("processor does not support CPUID instruction"); + debug_printf ("processor does not support CPUID instruction"); } if (has_cpuid) { @@ -2793,22 +2793,22 @@ long gethostid(void) cpuid (&maxf, &unused[0], &unused[1], &unused[2], 0); maxf &= 0xffff; if (maxf >= 1) - { - unsigned features; - cpuid (&data[0], &unused[0], &unused[1], &features, 1); - if (features & (1 << 18)) - { - debug_printf ("processor has psn"); - if (maxf >= 3) - { - cpuid (&unused[0], &unused[1], &data[1], &data[2], 3); - 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); - } - } - else - debug_printf ("processor does not have psn"); - } + { + unsigned features; + cpuid (&data[0], &unused[0], &unused[1], &features, 1); + if (features & (1 << 18)) + { + debug_printf ("processor has psn"); + if (maxf >= 3) + { + cpuid (&unused[0], &unused[1], &data[1], &data[2], 3); + 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); + } + } + else + debug_printf ("processor does not have psn"); + } } UUID Uuid; @@ -2822,8 +2822,8 @@ long gethostid(void) // Unfortunately Windows will sometimes pick a virtual Ethernet card // e.g. VMWare Virtual Ethernet Adaptor 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[5], Uuid.Data4[6], Uuid.Data4[7]); + Uuid.Data4[2], Uuid.Data4[3], Uuid.Data4[4], + Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]); } else { @@ -2839,16 +2839,16 @@ long gethostid(void) GetDiskFreeSpace ("C:\\", NULL, NULL, NULL, (DWORD *)&data[11]); debug_printf ("hostid entropy: %08x %08x %08x %08x " - "%08x %08x %08x %08x " - "%08x %08x %08x %08x " - "%08x", - data[0], data[1], - data[2], data[3], - data[4], data[5], - data[6], data[7], - data[8], data[9], - data[10], data[11], - data[12]); + "%08x %08x %08x %08x " + "%08x %08x %08x %08x " + "%08x", + data[0], data[1], + data[2], data[3], + data[4], data[5], + data[6], data[7], + data[8], data[9], + data[10], data[11], + data[12]); long hostid = 0x40291372; // a random hashing algorithm diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index b42bb140b..516cb8d2b 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -288,7 +288,7 @@ List pthread::threads; /* member methods */ 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), joiner (NULL), next (NULL), cleanup_stack (NULL) { @@ -856,8 +856,8 @@ pthread_cond::pthread_cond (pthread_condattr *attr) : if (attr) if (attr->shared != PTHREAD_PROCESS_PRIVATE) { - magic = 0; - return; + magic = 0; + return; } verifyable_mutex_obj = &mtx_in; @@ -907,7 +907,7 @@ pthread_cond::unblock (const bool all) { unsigned long releaseable; - /* + /* * Block outgoing threads (and avoid simultanous unblocks) */ mtx_out.lock (); @@ -918,19 +918,19 @@ pthread_cond::unblock (const bool all) unsigned long released; if (!pending) - { - /* - * Block incoming threads until all waiting threads are released. - */ - mtx_in.lock (); + { + /* + * Block incoming threads until all waiting threads are released. + */ + mtx_in.lock (); - /* - * Calculate releaseable again because threads can enter until - * the semaphore has been taken, but they can not leave, therefore pending - * is unchanged and releaseable can only get higher - */ - releaseable = waiting - pending; - } + /* + * Calculate releaseable again because threads can enter until + * the semaphore has been taken, but they can not leave, therefore pending + * is unchanged and releaseable can only get higher + */ + releaseable = waiting - pending; + } released = all ? releaseable : 1; pending += released; @@ -971,20 +971,20 @@ pthread_cond::wait (pthread_mutex_t mutex, DWORD dwMilliseconds) rv = pthread::cancelable_wait (sem_wait, dwMilliseconds, false); mtx_out.lock (); - + if (rv != WAIT_OBJECT_0) { /* * It might happen that a signal is sent while the thread got canceled * or timed out. Try to take one. * If the thread gets one than a signal|broadcast is in progress. - */ + */ if (WaitForSingleObject (sem_wait, 0) == WAIT_OBJECT_0) - /* - * thread got cancelled ot timed out while a signalling is in progress. - * Set wait result back to signaled - */ - rv = WAIT_OBJECT_0; + /* + * thread got cancelled ot timed out while a signalling is in progress. + * Set wait result back to signaled + */ + rv = WAIT_OBJECT_0; } InterlockedDecrement ((long *)&waiting); @@ -997,7 +997,7 @@ pthread_cond::wait (pthread_mutex_t mutex, DWORD dwMilliseconds) mtx_in.unlock (); mtx_out.unlock (); - + mutex->lock (); --mutex->condwaits; @@ -1068,8 +1068,8 @@ pthread_rwlock::pthread_rwlock (pthread_rwlockattr *attr) : if (attr) if (attr->shared != PTHREAD_PROCESS_PRIVATE) { - magic = 0; - return; + magic = 0; + return; } if (!pthread_mutex::is_good_object (&verifyable_mutex_obj)) @@ -1129,7 +1129,7 @@ pthread_rwlock::rdlock () } while (writer || waiting_writers) - { + { pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this); ++waiting_readers; @@ -1162,14 +1162,14 @@ pthread_rwlock::tryrdlock () { struct RWLOCK_READER *reader = new struct RWLOCK_READER; if (reader) - { - reader->thread = self; - add_reader (reader); - } + { + reader->thread = self; + add_reader (reader); + } else - result = EAGAIN; + result = EAGAIN; } - + mtx.unlock (); return result; @@ -1190,7 +1190,7 @@ pthread_rwlock::wrlock () } while (writer || readers) - { + { pthread_cleanup_push (pthread_rwlock::wrlock_cleanup, this); ++waiting_writers; @@ -1220,7 +1220,7 @@ pthread_rwlock::trywrlock () result = EBUSY; else writer = self; - + mtx.unlock (); return result; @@ -1237,10 +1237,10 @@ pthread_rwlock::unlock () if (writer) { if (writer != self) - { - result = EPERM; - goto DONE; - } + { + result = EPERM; + goto DONE; + } writer = NULL; } @@ -1249,10 +1249,10 @@ pthread_rwlock::unlock () struct RWLOCK_READER *reader = lookup_reader (self); if (!reader) - { - result = EPERM; - goto DONE; - } + { + result = EPERM; + goto DONE; + } remove_reader (reader); delete reader; @@ -1336,13 +1336,13 @@ pthread_rwlock::_fixup_after_fork () while (*temp) { if ((*temp)->thread == self) - temp = &((*temp)->next); + temp = &((*temp)->next); else - { - struct RWLOCK_READER *cur = *temp; - *temp = (*temp)->next; - delete cur; - } + { + struct RWLOCK_READER *cur = *temp; + *temp = (*temp)->next; + delete cur; + } } } diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 37ec6ef57..dbc39132d 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -540,7 +540,7 @@ wincapc::init () case 0: caps = &wincap_2000; break; - + case 1: caps = &wincap_xp; break;