diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e2c3f86c7..ec406edd0 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +Wed Aug 22 13:41:09 2001 Christopher Faylor + + * smallprint.c (console_printf): New function. + * dcrt0.cc (dll_crt0_1): Use console_printf for debugging output. + * debug.cc (debug_mark_closed): New function. + (close_handle): Use debug_mark_closed. + * debug.h: Declare new functions. + * dtable.cc (dtable::build_fhandler): Remove unneeded extern. + * spawn.cc: Cosmetic changes. + * winsup.h: Define NO_COPY for C files, too. Declare a global. + Wed Aug 22 17:31:00 2001 Corinna Vinschen * net.cc (free_char_list): New static function. diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 3a7417cae..bdaa3129c 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -876,7 +876,7 @@ _dll_crt0 () char buf[80]; if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf))) { - small_printf ("Sleeping %d, pid %u\n", atoi (buf), GetCurrentProcessId ()); + console_printf ("Sleeping %d, pid %u\n", atoi (buf), GetCurrentProcessId ()); Sleep (atoi (buf)); } #endif diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index bd58e47b4..551a12d7d 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -275,15 +275,11 @@ out: unlock_debug (); } -/* Close a known handle. Complain if !force and closing a known handle or - if the name of the handle being closed does not match the registered name. */ -BOOL __stdcall -close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) +bool __stdcall +debug_mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force) { - BOOL ret; handle_list *hl; lock_debug (); - if ((hl = find_handle (h)) && !force) { hl = hl->next; @@ -301,7 +297,7 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) hln->func, hln->ln, hln->name, hln->h); system_printf (" by %s:%d(%s<%p>)", func, ln, name, h); } - ret = CloseHandle (h); + if (hl) { handle_list *hnuke = hl->next; @@ -312,6 +308,23 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) memset (hnuke, 0, sizeof (*hnuke)); } + unlock_debug (); + return TRUE; +} + +/* Close a known handle. Complain if !force and closing a known handle or + if the name of the handle being closed does not match the registered name. */ +BOOL __stdcall +close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) +{ + BOOL ret; + lock_debug (); + + if (!debug_mark_closed (func, ln, h, name, force)) + return FALSE; + + ret = CloseHandle (h); + unlock_debug (); #if 0 /* Uncomment to see CloseHandle failures */ if (!ret) diff --git a/winsup/cygwin/debug.h b/winsup/cygwin/debug.h index 9491b60be..015627f3b 100644 --- a/winsup/cygwin/debug.h +++ b/winsup/cygwin/debug.h @@ -43,6 +43,8 @@ int __stdcall iscygthread (); # define ProtectHandle1(h,n) do {} while (0) # define ProtectHandle2(h,n) do {} while (0) # define debug_init() do {} while (0) +# define MarkCLosed(h) do {} while (0) +# define debug_mark_closed(func, ln, h, name, force) (1) #else @@ -57,6 +59,8 @@ int __stdcall iscygthread (); close_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n, TRUE) # define ForceCloseHandle2(h,n) \ close_handle (__PRETTY_FUNCTION__, __LINE__, (h), n, TRUE) +# define MarkClosed(h) \ + debug_mark_closed (__PRETTY_FUNCTION__, __LINE__, (h), #h, TRUE) # define lock_pinfo_for_update(n) lpfu(__PRETTY_FUNCTION__, __LINE__, n) # endif @@ -70,6 +74,8 @@ BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL); int __stdcall lpfu (const char *, int, DWORD timeout); void __stdcall cygbench (const char *s); extern int pinger; +extern "C" void console_printf (const char *fmt,...); +bool debug_mark_closed (const char *, int, HANDLE, const char *, BOOL); #endif /*DEBUGGING*/ #endif /*_DEBUG_H_*/ diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index c5811692c..4583a3f9c 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -232,7 +232,6 @@ dtable::build_fhandler (int fd, const char *name, HANDLE handle) { int unit; DWORD devn; - extern bool wsock_started; if ((devn = get_device_number (name, unit)) == FH_BAD) { diff --git a/winsup/cygwin/smallprint.c b/winsup/cygwin/smallprint.c index 54ae9b0a8..7e23d1a6d 100644 --- a/winsup/cygwin/smallprint.c +++ b/winsup/cygwin/smallprint.c @@ -181,7 +181,7 @@ __small_sprintf (char *dst, const char *fmt,...) void small_printf (const char *fmt,...) { - char buf[2000]; + char buf[16384]; va_list ap; DWORD done; int count; @@ -199,6 +199,29 @@ small_printf (const char *fmt,...) count = __small_vsprintf (buf, fmt, ap); va_end (ap); - WriteFile (GetStdHandle (STD_ERROR_HANDLE), buf, count, &done, 0); + WriteFile (GetStdHandle (STD_ERROR_HANDLE), buf, count, &done, NULL); FlushFileBuffers (GetStdHandle (STD_ERROR_HANDLE)); } + +#ifdef DEBUGGING +static HANDLE NO_COPY console_handle = NULL; +void +console_printf (const char *fmt,...) +{ + char buf[16384]; + va_list ap; + DWORD done; + int count; + extern SECURITY_ATTRIBUTES sec_none; + + if (!console_handle) + console_handle = CreateFileA ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, + &sec_none, OPEN_EXISTING, 0, 0); + va_start (ap, fmt); + count = __small_vsprintf (buf, fmt, ap); + va_end (ap); + + WriteFile (console_handle, buf, count, &done, NULL); + FlushFileBuffers (console_handle); +} +#endif diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 73df3f31f..110efa325 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -131,7 +131,7 @@ find_exec (const char *name, path_conv& buf, const char *mywinenv, } while (*path && *++path); -errout: + errout: /* Couldn't find anything in the given path. Take the appropriate action based on null_if_not_found. */ if (null_if_notfound) @@ -139,7 +139,7 @@ errout: else buf.check (name); -out: + out: debug_printf ("%s = find_exec (%s)", (char *) buf, name); if (known_suffix) *known_suffix = suffix ?: strchr (buf, '\0'); @@ -175,7 +175,7 @@ iscmd (const char *argv0, const char *what) class linebuf { -public: + public: size_t ix; char *buf; size_t alloced; @@ -223,7 +223,7 @@ class av { char **argv; int calloced; -public: + public: int argc; av (int ac, const char * const *av) : calloced (0), argc (ac) { @@ -547,7 +547,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, TRUE, DUPLICATE_SAME_ACCESS)) ciresrv.moreinfo->myself_pinfo = NULL; -skip_arg_parsing: + skip_arg_parsing: PROCESS_INFORMATION pi = {NULL, 0, 0, 0}; si.lpReserved = NULL; si.lpDesktop = NULL; @@ -861,8 +861,7 @@ skip_arg_parsing: return (int) res; } -extern "C" -int +extern "C" int cwait (int *result, int pid, int) { return waitpid (pid, result, 0); @@ -923,8 +922,7 @@ _spawnve (HANDLE hToken, int mode, const char *path, const char *const *argv, * Most of these based on (and copied from) newlib/libc/posix/execXX.c */ -extern "C" -int +extern "C" int spawnl (int mode, const char *path, const char *arg0, ...) { int i; @@ -944,8 +942,7 @@ spawnl (int mode, const char *path, const char *arg0, ...) return _spawnve (NULL, mode, path, (char * const *) argv, cur_environ ()); } -extern "C" -int +extern "C" int spawnle (int mode, const char *path, const char *arg0, ...) { int i; @@ -968,8 +965,7 @@ spawnle (int mode, const char *path, const char *arg0, ...) (char * const *) envp); } -extern "C" -int +extern "C" int spawnlp (int mode, const char *path, const char *arg0, ...) { int i; @@ -989,8 +985,7 @@ spawnlp (int mode, const char *path, const char *arg0, ...) return spawnvpe (mode, path, (char * const *) argv, cur_environ ()); } -extern "C" -int +extern "C" int spawnlpe (int mode, const char *path, const char *arg0, ...) { int i; @@ -1012,30 +1007,26 @@ spawnlpe (int mode, const char *path, const char *arg0, ...) return spawnvpe (mode, path, (char * const *) argv, envp); } -extern "C" -int +extern "C" int spawnv (int mode, const char *path, const char * const *argv) { return _spawnve (NULL, mode, path, argv, cur_environ ()); } -extern "C" -int +extern "C" int spawnve (int mode, const char *path, char * const *argv, const char * const *envp) { return _spawnve (NULL, mode, path, argv, envp); } -extern "C" -int +extern "C" int spawnvp (int mode, const char *path, const char * const *argv) { return spawnvpe (mode, path, argv, cur_environ ()); } -extern "C" -int +extern "C" int spawnvpe (int mode, const char *file, const char * const *argv, const char * const *envp) { diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index d0b2548fc..1b73a2f52 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -24,6 +24,8 @@ details. */ # define memset __builtin_memset #endif +#define NO_COPY __attribute__((section(".data_cygwin_nocopy"))) + #ifdef __cplusplus #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L @@ -97,8 +99,6 @@ extern HANDLE title_mutex; /**************************** Convenience ******************************/ -#define NO_COPY __attribute__((section(".data_cygwin_nocopy"))) - /* Used when treating / and \ as equivalent. */ #define SLASH_P(ch) \ ({ \ @@ -204,6 +204,8 @@ int __stdcall __check_null_invalid_struct_errno (const void *s, unsigned sz) __a #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__) void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2))); +extern bool wsock_started; + /* Printf type functions */ extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn)); extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;