From 792011508a5faae82e03a8b49ca1718b5b29be06 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 8 May 2001 15:16:49 +0000 Subject: [PATCH] * cygheap.cc (_cfree): Add regparm attribute. (_crealloc): Ditto. * dcrt0.cc (dll_crt0_1): Default to always checking for executable for now. * dtable.cc (dtable::not_open): Move method. * dtable.h (dtable): Here. * exceptions.cc (ctrl_c_handler): Don't expect process group leader to handle a signal if it doesn't exist. * fhandler.h (fhandler_base): Make openflags protected. * localtime.c (tzsetwall): Check for __CYGWIN__ as well as __WIN32__. * path.cc (path_conv::check): Add some comments. Change strcat to assignment. * lib/_cygwin_S_IEXEC.cc (_cygwin_bob__): Eliminate. * fhandler_tty.cc (fhandler_console::dup): Set controlling terminal if necessary. * fhandler_tty.cc (fhandler_tty_slave::dup): Ditto. --- winsup/cygwin/ChangeLog | 24 +++++++++++++++++++++++ winsup/cygwin/cygheap.cc | 2 ++ winsup/cygwin/dcrt0.cc | 5 +---- winsup/cygwin/dtable.cc | 11 ----------- winsup/cygwin/dtable.h | 12 +++++++++++- winsup/cygwin/exceptions.cc | 5 +++-- winsup/cygwin/fhandler.h | 2 +- winsup/cygwin/fhandler_console.cc | 2 +- winsup/cygwin/fhandler_tty.cc | 1 + winsup/cygwin/lib/_cygwin_S_IEXEC.cc | 6 ------ winsup/cygwin/localtime.c | 2 +- winsup/cygwin/path.cc | 29 +++++++++++++++++++++++++--- 12 files changed, 71 insertions(+), 30 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 3a53964f1..47dec1516 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,27 @@ +Tue May 8 11:09:59 2001 Christopher Faylor + + * cygheap.cc (_cfree): Add regparm attribute. + (_crealloc): Ditto. + + * dcrt0.cc (dll_crt0_1): Default to always checking for executable for now. + + * dtable.cc (dtable::not_open): Move method. + * dtable.h (dtable): Here. + + * exceptions.cc (ctrl_c_handler): Don't expect process group leader to + handle a signal if it doesn't exist. + + * fhandler.h (fhandler_base): Make openflags protected. + + * localtime.c (tzsetwall): Check for __CYGWIN__ as well as __WIN32__. + + * path.cc (path_conv::check): Add some comments. Change strcat to assignment. + + * lib/_cygwin_S_IEXEC.cc (_cygwin_bob__): Eliminate. + + * fhandler_tty.cc (fhandler_console::dup): Set controlling terminal if necessary. + * fhandler_tty.cc (fhandler_tty_slave::dup): Ditto. + Mon May 7 21:33:17 2001 Christopher Faylor * include/sys/file.h: Revert special X_OK usage. Just make it a diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 61de33eff..7cad22b5e 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -115,6 +115,7 @@ _cmalloc (int size) return rvc->data; } +static void __stdcall _cfree (void *ptr) __attribute__((regparm(1))); static void __stdcall _cfree (void *ptr) { @@ -126,6 +127,7 @@ _cfree (void *ptr) cygheap_protect->release (); } +static void *__stdcall _crealloc (void *ptr, int size) __attribute__((regparm(2))); static void *__stdcall _crealloc (void *ptr, int size) { diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index e25c31144..1036feb2d 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -109,7 +109,7 @@ extern "C" /* impure_ptr */ &reent_data, }; bool ignore_case_with_glob = FALSE; - int __declspec (dllexport) _check_for_executable = FALSE; + int __declspec (dllexport) _check_for_executable = TRUE; #ifdef DEBUGGING int pinger = 0; #endif @@ -753,9 +753,6 @@ dll_crt0_1 () longjmp (fork_info->jmp, fork_info->cygpid); } - if (!CYGWIN_VERSION_CHECK_FOR_S_IEXEC) - _check_for_executable = TRUE; - #ifdef DEBUGGING { extern void fork_init (); diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 19a589b3c..0e0942cde 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -125,17 +125,6 @@ stdio_init (void) } } -int -dtable::not_open (int fd) -{ - SetResourceLock(LOCK_FD_LIST, READ_LOCK, "not_open"); - - int res = fd < 0 || fd >= (int)size || fds[fd] == NULL; - - ReleaseResourceLock(LOCK_FD_LIST, READ_LOCK, "not open"); - return res; -} - int dtable::find_unused_handle (int start) { diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index b67cfbcc1..f81d916b7 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -11,6 +11,8 @@ details. */ /* Initial and increment values for cygwin's fd table */ #define NOFILE_INCR 32 +#include "thread.h" + class dtable { fhandler_base **fds; @@ -41,7 +43,15 @@ public: fhandler_base *build_fhandler (int fd, DWORD dev, const char *name, int unit = -1); fhandler_base *build_fhandler (int fd, const char *name, HANDLE h); - int not_open (int n) __attribute__ ((regparm(1))); + int not_open (int fd) + { + SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open"); + + int res = fd < 0 || fd >= (int) size || fds[fd] == NULL; + + ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "not open"); + return res; + } int find_unused_handle (int start); int find_unused_handle () { return find_unused_handle (first_fd_for_open);} void release (int fd); diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index d9a812fcd..6c35f39bb 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -904,8 +904,9 @@ ctrl_c_handler (DWORD type) tty_min *t = cygwin_shared->tty.get_tty (myself->ctty); /* Ignore this if we're not the process group lead since it should be handled *by* the process group leader. */ - if (t->getpgid () && (t->getpgid () != myself->pid || - (GetTickCount () - t->last_ctrl_c) < MIN_CTRL_C_SLOP)) + if (t->getpgid () && pid_exists (t->getpgid ()) && + (t->getpgid () != myself->pid || + (GetTickCount () - t->last_ctrl_c) < MIN_CTRL_C_SLOP)) return TRUE; else /* Otherwise we just send a SIGINT to the process group and return TRUE (to indicate diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 73aadd607..4101da545 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -150,11 +150,11 @@ private: unsigned long namehash; /* hashed filename, used as inode num */ +protected: /* Full unix path name of this file */ /* File open flags from open () and fcntl () calls */ int openflags; -protected: char *rabuf; /* used for crlf conversion in text files */ size_t ralen; size_t raixget; diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 01d90fe22..b6408e50e 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -595,7 +595,7 @@ fhandler_console::dup (fhandler_base *child) { fhandler_console *fhc = (fhandler_console *) child; - if (!fhc->open (get_name (), get_flags (), 0)) + if (!fhc->open (get_name (), get_flags () & ~O_NOCTTY, 0)) system_printf ("error opening console, %E"); fhc->default_color = default_color; diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 1a6ffb4a2..ce499c89c 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -783,6 +783,7 @@ fhandler_tty_common::dup (fhandler_base *child) fts->tcinit (get_ttyp ()); attach_tty (ttynum); + tc->set_ctty (ttynum, openflags & ~O_NOCTTY); HANDLE nh; diff --git a/winsup/cygwin/lib/_cygwin_S_IEXEC.cc b/winsup/cygwin/lib/_cygwin_S_IEXEC.cc index 5f57c94d3..371126073 100644 --- a/winsup/cygwin/lib/_cygwin_S_IEXEC.cc +++ b/winsup/cygwin/lib/_cygwin_S_IEXEC.cc @@ -19,9 +19,3 @@ unsigned _cygwin_S_IXGRP = S_IXGRP; unsigned _cygwin_S_IXOTH = S_IXOTH; unsigned _cygwin_X_OK = X_OK; }; - -extern int __declspec (dllimport) _check_for_executable; -struct _cygwin_bob__ -{ - _cygwin_bob__ () {_check_for_executable = 1;} -} _cygwin_dummy_bob__; diff --git a/winsup/cygwin/localtime.c b/winsup/cygwin/localtime.c index b69f4e50d..f46517210 100644 --- a/winsup/cygwin/localtime.c +++ b/winsup/cygwin/localtime.c @@ -1429,7 +1429,7 @@ tzsetwall P((void)) } } #endif /* defined ALL_STATE */ -#ifdef _WIN32 +#if defined (_WIN32) || defined (__CYGWIN__) #define is_upper(c) ((unsigned)(c) - 'A' <= 26) { TIME_ZONE_INFORMATION tz; diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 053fab2a4..6ca78b470 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -386,6 +386,9 @@ path_conv::check (const char *src, unsigned opt, MALLOC_CHECK; assert (src); char *p = strrchr (src, '/'); + /* Detect if the user was looking for a directory. We have to strip the + trailing slash initially and add it back on at the end due to Windows + brain damage. */ if (p) { if (p[1] == '\0' || strcmp (p, "/.") == 0) @@ -434,9 +437,11 @@ path_conv::check (const char *src, unsigned opt, full_path = this->path; } + /* Convert to native path spec sans symbolic link info. */ error = mount_table->conv_to_win32_path (path_copy, full_path, devn, unit, &sym.pflags); + /* devn should not be a device. If it is, then stop parsing now. */ if (devn != FH_BAD) { fileattr = 0; @@ -453,7 +458,10 @@ path_conv::check (const char *src, unsigned opt, *tail = '\0'; if (full_path[0] && full_path[1] == ':' && full_path[2] == '\0') - strcat (full_path, "\\"); + { + full_path[2] = '\\'; + full_path[3] = '\0'; + } if ((opt & PC_SYM_IGNORE) && pcheck_case == PCHECK_RELAXED) { @@ -529,13 +537,16 @@ path_conv::check (const char *src, unsigned opt, break; } /* No existing file found. */ - } + /* Find the "tail" of the path, e.g. in '/for/bar/baz', + /baz is the tail. */ char *newtail = strrchr (path_copy, '/'); if (tail != path_end) *tail = '/'; + /* Exit loop if there is no tail or we are at the + beginning of a UNC path */ if (!newtail || newtail == path_copy || (newtail == path_copy + 1 && newtail[-1] == '/')) goto out; // all done @@ -556,6 +567,9 @@ path_conv::check (const char *src, unsigned opt, MALLOC_CHECK; + /* The tail is pointing at a null pointer. Increment it and get the length. + If the tail was empty then this increment will end up pointing to the extra + \0 added to path_copy above. */ int taillen = strlen (++tail); int buflen = strlen (sym.contents); if (buflen + taillen > MAX_PATH) @@ -565,24 +579,32 @@ path_conv::check (const char *src, unsigned opt, return; } + /* Strip off current directory component since this is the part that refers + to the symbolic link. */ if ((p = strrchr (path_copy, '/')) == NULL) p = path_copy; *p = '\0'; char *headptr; if (isabspath (sym.contents)) - headptr = tmp_buf; + headptr = tmp_buf; /* absolute path */ else { + /* Copy the first part of the path and point to the end. */ strcpy (tmp_buf, path_copy); headptr = strchr (tmp_buf, '\0'); } + /* See if we need to separate first part + symlink contents with a / */ if (headptr > tmp_buf && headptr[-1] != '/') *headptr++ = '/'; + /* Copy the symlink contents to the end of tmp_buf. + Convert slashes. FIXME? */ for (p = sym.contents; *p; p++) *headptr++ = *p == '\\' ? '/' : *p; + + /* Copy any tail component */ if (tail >= path_end) *headptr = '\0'; else @@ -591,6 +613,7 @@ path_conv::check (const char *src, unsigned opt, strcpy (headptr, tail); } + /* Now evaluate everything all over again. */ src = tmp_buf; }