* fhandler.cc (fhandler_base::set_no_inheritance): Always use

SetHandleInformation.
	* fhandler_disk_file.cc (fhandler_disk_file::lock): Always use
	UnlockFileEx/LockFileEx functions.
	* net.cc (fdsock): Don't bother to duplicate socket for inheritance.
	* sysconf.cc (get_nproc_values): Take NT for granted.
	(get_avphys): Ditto.
	* syslog.cc (WIN95_EVENT_LOG_PATH): Remove define.
	(get_win95_event_log_path): Remove.
	(vsyslog): Fix formatting.  Take NT for granted.
	* wincap.cc: Remove has_lock_file_ex, has_signal_object_and_wait,
	has_eventlog, has_set_handle_information,
	has_set_handle_information_on_console_handles and supports_smp
	throughout.
	* wincap.h: Ditto.
This commit is contained in:
Corinna Vinschen 2007-02-22 17:09:46 +00:00
parent 64f211c87c
commit eef57fe1e3
9 changed files with 209 additions and 386 deletions

View File

@ -1,3 +1,21 @@
2007-02-22 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::set_no_inheritance): Always use
SetHandleInformation.
* fhandler_disk_file.cc (fhandler_disk_file::lock): Always use
UnlockFileEx/LockFileEx functions.
* net.cc (fdsock): Don't bother to duplicate socket for inheritance.
* sysconf.cc (get_nproc_values): Take NT for granted.
(get_avphys): Ditto.
* syslog.cc (WIN95_EVENT_LOG_PATH): Remove define.
(get_win95_event_log_path): Remove.
(vsyslog): Fix formatting. Take NT for granted.
* wincap.cc: Remove has_lock_file_ex, has_signal_object_and_wait,
has_eventlog, has_set_handle_information,
has_set_handle_information_on_console_handles and supports_smp
throughout.
* wincap.h: Ditto.
2007-02-22 Corinna Vinschen <corinna@vinschen.de>
* dir.cc (rmdir): Move existance check in front of

View File

@ -1481,21 +1481,9 @@ fhandler_dev_null::open (int flags, mode_t mode)
void
fhandler_base::set_no_inheritance (HANDLE &h, bool not_inheriting)
{
if (wincap.has_set_handle_information ())
{
if (!SetHandleInformation (h, HANDLE_FLAG_INHERIT, not_inheriting ? 0 : HANDLE_FLAG_INHERIT))
if (!SetHandleInformation (h, HANDLE_FLAG_INHERIT,
not_inheriting ? 0 : HANDLE_FLAG_INHERIT))
debug_printf ("SetHandleInformation failed, %E");
}
else
{
HANDLE oh = h;
if (!DuplicateHandle (hMainProc, oh, hMainProc, &h, 0, !not_inheriting,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
debug_printf ("DuplicateHandle failed, %E");
if (oh != h)
VerifyHandle (h);
}
#ifdef DEBUGGING_AND_FDS_PROTECTED
if (h)
setclexec (oh, h, not_inheriting);

View File

@ -1281,8 +1281,6 @@ fhandler_disk_file::lock (int cmd, struct __flock64 *fl)
BOOL res;
if (wincap.has_lock_file_ex ())
{
DWORD lock_flags = (cmd == F_SETLK) ? LOCKFILE_FAIL_IMMEDIATELY : 0;
lock_flags |= (fl->l_type == F_WRLCK) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
@ -1316,15 +1314,6 @@ fhandler_disk_file::lock (int cmd, struct __flock64 *fl)
return -1;
}
}
}
else
{
/* Windows 95 -- use primitive lock call */
if (fl->l_type == F_UNLCK)
res = UnlockFile (get_handle (), off_low, off_high, len_low, len_high);
else
res = LockFile (get_handle (), off_low, off_high, len_low, len_high);
}
if (res == 0)
{

View File

@ -501,16 +501,6 @@ cygwin_getprotobynumber (int number)
bool
fdsock (cygheap_fdmanip& fd, const device *dev, SOCKET soc)
{
/* NT systems apparently set sockets to inheritable by default */
if (!wincap.has_set_handle_information ()
&& !DuplicateHandle (hMainProc, (HANDLE) soc,
hMainProc, (HANDLE *) &soc,
0, TRUE,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
{
debug_printf ("set socket inheritance failed, %E");
return false;
}
fd = build_fh_dev (*dev);
if (!fd.isopen ())
return false;

View File

@ -40,22 +40,10 @@ get_page_size (int in)
static long
get_nproc_values (int in)
{
switch (in)
{
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
if (!wincap.supports_smp ())
return 1;
/*FALLTHRU*/
case _SC_PHYS_PAGES:
if (wincap.supports_smp ())
{
NTSTATUS ret;
SYSTEM_BASIC_INFORMATION sbi;
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
(PVOID) &sbi,
sizeof sbi, NULL))
!= STATUS_SUCCESS)
if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
sizeof sbi, NULL)) != STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
@ -79,21 +67,16 @@ get_nproc_values (int in)
return sbi.NumberOfPhysicalPages
/ (getpagesize () / getsystempagesize ());
}
}
}
return -1;
}
static long
get_avphys (int in)
{
if (wincap.supports_smp ())
{
NTSTATUS ret;
SYSTEM_PERFORMANCE_INFORMATION spi;
if ((ret = NtQuerySystemInformation (SystemPerformanceInformation,
(PVOID) &spi,
sizeof spi, NULL))
(PVOID) &spi, sizeof spi, NULL))
!= STATUS_SUCCESS)
{
__seterrno_from_nt_status (ret);
@ -102,8 +85,6 @@ get_avphys (int in)
return -1;
}
return spi.AvailablePages / (getpagesize () / getsystempagesize ());
}
return -1;
}
enum sc_type { nsup, cons, func };

View File

@ -1,7 +1,7 @@
/* syslog.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006 Red Hat, Inc.
2006, 2007 Red Hat, Inc.
This file is part of Cygwin.
@ -28,22 +28,8 @@ details. */
#include "thread.h"
#include "cygtls.h"
/* FIXME: These should probably be in the registry. */
/* FIXME: The Win95 path should be whatever slash is */
#define WIN95_EVENT_LOG_PATH "C:\\CYGWIN_SYSLOG.TXT"
#define CYGWIN_LOG_NAME "Cygwin"
/*
* Utility function to help enable moving
* WIN95_EVENT_LOG_PATH into registry later.
*/
static const char *
get_win95_event_log_path ()
{
return WIN95_EVENT_LOG_PATH;
}
/* openlog: save the passed args. Don't open the
system log (NT) or log file (95) yet. */
extern "C" void
@ -382,42 +368,6 @@ vsyslog (int priority, const char *message, va_list ap)
return;
}
if (!wincap.has_eventlog ())
{
/* Add a priority string - not needed for systems with
eventlog capability. */
switch (LOG_PRI (priority))
{
case LOG_EMERG:
pass.print ("%s: ", "LOG_EMERG");
break;
case LOG_ALERT:
pass.print ("%s: ", "LOG_ALERT");
break;
case LOG_CRIT:
pass.print ("%s: ", "LOG_CRIT");
break;
case LOG_ERR:
pass.print ("%s: ", "LOG_ERR");
break;
case LOG_WARNING:
pass.print ("%s: ", "LOG_WARNING");
break;
case LOG_NOTICE:
pass.print ("%s: ", "LOG_NOTICE");
break;
case LOG_INFO:
pass.print ("%s: ", "LOG_INFO");
break;
case LOG_DEBUG:
pass.print ("%s: ", "LOG_DEBUG");
break;
default:
pass.print ("%s: ", "LOG_ERR");
break;
}
}
/* Print out the variable part */
if (pass.print_va (message, ap) == -1)
return;
@ -438,11 +388,9 @@ vsyslog (int priority, const char *message, va_list ap)
}
int fd;
if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) >= 0)
;
else if (wincap.has_eventlog ())
if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) < 0)
{
/* For NT, open the event log and send the message */
/* If syslogd isn't present, open the event log and send the message */
HANDLE hEventSrc = RegisterEventSourceA (NULL, (_my_tls.locals.process_ident != NULL) ?
_my_tls.locals.process_ident : CYGWIN_LOG_NAME);
if (hEventSrc == NULL)
@ -455,43 +403,6 @@ vsyslog (int priority, const char *message, va_list ap)
debug_printf ("ReportEventA failed with %E");
DeregisterEventSource (hEventSrc);
}
else
{
/* Under Windows 95, append the message to the log file */
char timestamp[24];
time_t ctime;
FILE *fp = fopen (get_win95_event_log_path (), "a");
if (fp == NULL)
{
debug_printf ("failed to open file %s",
get_win95_event_log_path ());
return;
}
strftime (timestamp, sizeof timestamp, "%Y-%m-%d %H:%M:%S : ",
localtime (&(ctime = time (NULL))));
/* Now to prevent several syslog messages from being
interleaved, we must lock the first byte of the file
This works on Win32 even if we created the file above.
*/
HANDLE fHandle = cygheap->fdtab[fileno (fp)]->get_handle ();
for (int i = 0;; i++)
if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
if (i == 3)
{
debug_printf ("failed to lock file %s", get_win95_event_log_path ());
fclose (fp);
return;
}
else
usleep (1000);
else
break;
fputs (timestamp, fp);
fputs (msg_strings[0], fp);
fputc ('\n', fp);
fclose (fp);
}
}
extern "C" void

View File

@ -1,7 +1,7 @@
/* times.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005 Red Hat, Inc.
2005, 2006, 2007 Red Hat, Inc.
This file is part of Cygwin.

View File

@ -19,13 +19,7 @@ static NO_COPY wincaps wincap_unknown = {
is_server:false,
has_security:true,
has_security_descriptor_control:false,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:false,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:false,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:true,
@ -78,13 +72,7 @@ static NO_COPY wincaps wincap_nt4 = {
is_server:false,
has_security:true,
has_security_descriptor_control:false,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:false,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:false,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:true,
@ -137,13 +125,7 @@ static NO_COPY wincaps wincap_nt4sp4 = {
is_server:false,
has_security:true,
has_security_descriptor_control:false,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:true,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:false,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:true,
@ -196,13 +178,7 @@ static NO_COPY wincaps wincap_2000 = {
is_server:false,
has_security:true,
has_security_descriptor_control:true,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:true,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:true,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:true,
@ -255,13 +231,7 @@ static NO_COPY wincaps wincap_xp = {
is_server:false,
has_security:true,
has_security_descriptor_control:true,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:true,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:true,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:true,
@ -314,13 +284,7 @@ static NO_COPY wincaps wincap_2003 = {
is_server:true,
has_security:true,
has_security_descriptor_control:true,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:true,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:true,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:false,
@ -373,13 +337,7 @@ static NO_COPY wincaps wincap_vista = {
is_server:false,
has_security:true,
has_security_descriptor_control:true,
has_lock_file_ex:true,
has_signal_object_and_wait:true,
has_eventlog:true,
has_ip_helper_lib:true,
has_set_handle_information:true,
has_set_handle_information_on_console_handles:true,
supports_smp:true,
map_view_of_file_ex_sucks:false,
altgr_is_ctrl_alt:true,
has_physical_mem_access:false,

View File

@ -19,13 +19,7 @@ struct wincaps
unsigned is_server : 1;
unsigned has_security : 1;
unsigned has_security_descriptor_control : 1;
unsigned has_lock_file_ex : 1;
unsigned has_signal_object_and_wait : 1;
unsigned has_eventlog : 1;
unsigned has_ip_helper_lib : 1;
unsigned has_set_handle_information : 1;
unsigned has_set_handle_information_on_console_handles: 1;
unsigned supports_smp : 1;
unsigned map_view_of_file_ex_sucks : 1;
unsigned altgr_is_ctrl_alt : 1;
unsigned has_physical_mem_access : 1;
@ -94,13 +88,7 @@ public:
bool IMPLEMENT (is_server)
bool IMPLEMENT (has_security)
bool IMPLEMENT (has_security_descriptor_control)
bool IMPLEMENT (has_lock_file_ex)
bool IMPLEMENT (has_signal_object_and_wait)
bool IMPLEMENT (has_eventlog)
bool IMPLEMENT (has_ip_helper_lib)
bool IMPLEMENT (has_set_handle_information)
bool IMPLEMENT (has_set_handle_information_on_console_handles)
bool IMPLEMENT (supports_smp)
bool IMPLEMENT (map_view_of_file_ex_sucks)
bool IMPLEMENT (altgr_is_ctrl_alt)
bool IMPLEMENT (has_physical_mem_access)