* cygtls.h (_cygtls): Perform minor reformatting.
* winsup.h (close_all_files): Reflect argument change. * dtable.cc (close_all_files): Ditto. * dtable.h: Ditto. * fhandler.h: Ditto. * spawn.cc (spawn_guts): Move close_all_files back to its original location in first P_OVERLAY test but use argument denoting that handles are only supposed to be closed, not released (more work to be done here). * syscalls.cc (close_all_files): Take an argument denoting whether to release closed files or not. * path.cc (symlink): Change argument names to reflect linux man page. (symlink_worker): Ditto. Also appropriately set ENOENT for empty strings.
This commit is contained in:
		| @@ -1,3 +1,22 @@ | ||||
| 2005-07-04  Christopher Faylor  <cgf@timesys.com> | ||||
|  | ||||
|         * cygtls.h (_cygtls): Perform minor reformatting. | ||||
|  | ||||
| 	* winsup.h (close_all_files): Reflect argument change. | ||||
| 	* dtable.cc (close_all_files): Ditto. | ||||
| 	* dtable.h: Ditto. | ||||
| 	* fhandler.h: Ditto. | ||||
| 	* spawn.cc (spawn_guts): Move close_all_files back to its original | ||||
| 	location in first P_OVERLAY test but use argument denoting that handles | ||||
| 	are only supposed to be closed, not released (more work to be done | ||||
| 	here). | ||||
| 	* syscalls.cc (close_all_files): Take an argument denoting whether to | ||||
| 	release closed files or not. | ||||
|  | ||||
|         * path.cc (symlink): Change argument names to reflect linux man page. | ||||
|         (symlink_worker): Ditto.  Also appropriately set ENOENT for empty strings. | ||||
|  | ||||
|  | ||||
| 2005-07-04  Pierre Humblet <pierre.humblet@ieee.org> | ||||
|  | ||||
| 	* cygheap.h (struct init_cygheap): Delete cygwin_regname member. | ||||
|   | ||||
| @@ -252,10 +252,7 @@ class myfault | ||||
| { | ||||
|   jmp_buf buf; | ||||
| public: | ||||
|   ~myfault () __attribute__ ((always_inline)) | ||||
|     { | ||||
|       _my_tls.clear_fault (buf); | ||||
|     } | ||||
|   ~myfault () __attribute__ ((always_inline)) { _my_tls.clear_fault (buf); } | ||||
|   inline int faulted (int myerrno = 0) __attribute__ ((always_inline)) | ||||
|   { | ||||
|     return _my_tls.setup_fault (buf, myerrno); | ||||
|   | ||||
| @@ -84,7 +84,7 @@ public: | ||||
|   fhandler_base **add_archetype (); | ||||
|   void delete_archetype (fhandler_base *); | ||||
|   friend void dtable_init (); | ||||
|   friend void __stdcall close_all_files (); | ||||
|   friend void __stdcall close_all_files (bool); | ||||
|   friend class cygheap_fdmanip; | ||||
|   friend class cygheap_fdget; | ||||
|   friend class cygheap_fdnew; | ||||
|   | ||||
| @@ -82,7 +82,7 @@ enum query_state { | ||||
| class fhandler_base | ||||
| { | ||||
|   friend class dtable; | ||||
|   friend void close_all_files (); | ||||
|   friend void close_all_files (bool); | ||||
|  | ||||
|   struct status_flags | ||||
|   { | ||||
|   | ||||
| @@ -2615,48 +2615,48 @@ set_symlink_ea (const char* frompath, const char* topath) | ||||
| bool allow_winsymlinks = true; | ||||
|  | ||||
| extern "C" int | ||||
| symlink (const char *topath, const char *frompath) | ||||
| symlink (const char *oldpath, const char *newpath) | ||||
| { | ||||
|   return symlink_worker (topath, frompath, allow_winsymlinks, false); | ||||
|   return symlink_worker (oldpath, newpath, allow_winsymlinks, false); | ||||
| } | ||||
|  | ||||
| int | ||||
| symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| symlink_worker (const char *oldpath, const char *newpath, bool use_winsym, | ||||
| 		bool isdevice) | ||||
| { | ||||
|   HANDLE h; | ||||
|   int res = -1; | ||||
|   path_conv win32_path, win32_topath; | ||||
|   path_conv win32_path, win32_oldpath; | ||||
|   char from[CYG_MAX_PATH + 5]; | ||||
|   char cwd[CYG_MAX_PATH], *cp = NULL, c = 0; | ||||
|   char w32topath[CYG_MAX_PATH]; | ||||
|   char reltopath[CYG_MAX_PATH] = { 0 }; | ||||
|   char w32oldpath[CYG_MAX_PATH]; | ||||
|   char reloldpath[CYG_MAX_PATH] = { 0 }; | ||||
|   DWORD written; | ||||
|   SECURITY_ATTRIBUTES sa = sec_none_nih; | ||||
|   security_descriptor sd; | ||||
|  | ||||
|   /* POSIX says that empty 'frompath' is invalid input while empty | ||||
|      'topath' is valid -- it's symlink resolver job to verify if | ||||
|   /* POSIX says that empty 'newpath' is invalid input while empty | ||||
|      'oldpath' is valid -- it's symlink resolver job to verify if | ||||
|      symlink contents point to existing filesystem object */ | ||||
|   myfault efault; | ||||
|   if (efault.faulted (EFAULT)) | ||||
|     goto done; | ||||
|   if (!*topath || !*frompath) | ||||
|   if (!*oldpath || !*newpath) | ||||
|     { | ||||
|       set_errno (EINVAL); | ||||
|       set_errno (ENOENT); | ||||
|       goto done; | ||||
|     } | ||||
|  | ||||
|   if (strlen (topath) >= CYG_MAX_PATH) | ||||
|   if (strlen (oldpath) >= CYG_MAX_PATH) | ||||
|     { | ||||
|       set_errno (ENAMETOOLONG); | ||||
|       goto done; | ||||
|     } | ||||
|  | ||||
|   win32_path.check (frompath, PC_SYM_NOFOLLOW); | ||||
|   win32_path.check (newpath, PC_SYM_NOFOLLOW); | ||||
|   if (use_winsym && !win32_path.exists ()) | ||||
|     { | ||||
|       strcpy (from, frompath); | ||||
|       strcpy (from, newpath); | ||||
|       strcat (from, ".lnk"); | ||||
|       win32_path.check (from, PC_SYM_NOFOLLOW); | ||||
|     } | ||||
| @@ -2667,7 +2667,7 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
|       goto done; | ||||
|     } | ||||
|  | ||||
|   syscall_printf ("symlink (%s, %s)", topath, win32_path.get_win32 ()); | ||||
|   syscall_printf ("symlink (%s, %s)", oldpath, win32_path.get_win32 ()); | ||||
|  | ||||
|   if (win32_path.is_auto_device ()) | ||||
|     { | ||||
| @@ -2680,13 +2680,13 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
|     create_how = CREATE_NEW; | ||||
|   else if (isdevice) | ||||
|     { | ||||
|       strcpy (w32topath, topath); | ||||
|       strcpy (w32oldpath, oldpath); | ||||
|       create_how = CREATE_ALWAYS; | ||||
|       (void) SetFileAttributes (win32_path, FILE_ATTRIBUTE_NORMAL); | ||||
|     } | ||||
|   else | ||||
|     { | ||||
|       if (!isabspath (topath)) | ||||
|       if (!isabspath (oldpath)) | ||||
| 	{ | ||||
| 	  getcwd (cwd, CYG_MAX_PATH); | ||||
| 	  if ((cp = strrchr (from, '/')) || (cp = strrchr (from, '\\'))) | ||||
| @@ -2695,23 +2695,23 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	      *cp = '\0'; | ||||
| 	      chdir (from); | ||||
| 	    } | ||||
| 	  backslashify (topath, reltopath, 0); | ||||
| 	  backslashify (oldpath, reloldpath, 0); | ||||
| 	  /* Creating an ITEMIDLIST requires an absolute path.  So if we | ||||
| 	     create a shortcut file, we create relative and absolute Win32 | ||||
| 	     paths, the first for the relpath field and the latter for the | ||||
| 	     ITEMIDLIST field. */ | ||||
| 	  if (GetFileAttributes (reltopath) == INVALID_FILE_ATTRIBUTES) | ||||
| 	  if (GetFileAttributes (reloldpath) == INVALID_FILE_ATTRIBUTES) | ||||
| 	    { | ||||
| 	      win32_topath.check (topath, PC_SYM_NOFOLLOW); | ||||
| 	      if (win32_topath.error != ENOENT) | ||||
| 		strcpy (use_winsym ? reltopath : w32topath, win32_topath); | ||||
| 	      win32_oldpath.check (oldpath, PC_SYM_NOFOLLOW); | ||||
| 	      if (win32_oldpath.error != ENOENT) | ||||
| 		strcpy (use_winsym ? reloldpath : w32oldpath, win32_oldpath); | ||||
| 	    } | ||||
| 	  else if (!use_winsym) | ||||
| 	    strcpy (w32topath, reltopath); | ||||
| 	    strcpy (w32oldpath, reloldpath); | ||||
| 	  if (use_winsym) | ||||
| 	    { | ||||
| 	      win32_topath.check (topath, PC_SYM_NOFOLLOW); | ||||
| 	      strcpy (w32topath, win32_topath); | ||||
| 	      win32_oldpath.check (oldpath, PC_SYM_NOFOLLOW); | ||||
| 	      strcpy (w32oldpath, win32_oldpath); | ||||
| 	    } | ||||
| 	  if (cp) | ||||
| 	    { | ||||
| @@ -2721,8 +2721,8 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	} | ||||
|       else | ||||
| 	{ | ||||
| 	  win32_topath.check (topath, PC_SYM_NOFOLLOW); | ||||
| 	  strcpy (w32topath, win32_topath); | ||||
| 	  win32_oldpath.check (oldpath, PC_SYM_NOFOLLOW); | ||||
| 	  strcpy (w32oldpath, win32_oldpath); | ||||
| 	} | ||||
|       create_how = CREATE_NEW; | ||||
|     } | ||||
| @@ -2761,7 +2761,7 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	  hres = SHGetDesktopFolder (&psl); | ||||
| 	  if (SUCCEEDED (hres)) | ||||
| 	    { | ||||
| 	      MultiByteToWideChar (CP_ACP, 0, w32topath, -1, wc_path, | ||||
| 	      MultiByteToWideChar (CP_ACP, 0, w32oldpath, -1, wc_path, | ||||
| 				   CYG_MAX_PATH); | ||||
| 	      hres = psl->ParseDisplayName (NULL, NULL, wc_path, NULL, | ||||
| 					    &pidl, NULL); | ||||
| @@ -2780,19 +2780,19 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	      psl->Release (); | ||||
| 	    } | ||||
| 	  /* Creating a description */ | ||||
| 	  *(unsigned short *)cp = len = strlen (topath); | ||||
| 	  memcpy (cp += 2, topath, len); | ||||
| 	  *(unsigned short *)cp = len = strlen (oldpath); | ||||
| 	  memcpy (cp += 2, oldpath, len); | ||||
| 	  cp += len; | ||||
| 	  /* Creating a relpath */ | ||||
| 	  if (reltopath[0]) | ||||
| 	  if (reloldpath[0]) | ||||
| 	    { | ||||
| 	      *(unsigned short *)cp = len = strlen (reltopath); | ||||
| 	      memcpy (cp += 2, reltopath, len); | ||||
| 	      *(unsigned short *)cp = len = strlen (reloldpath); | ||||
| 	      memcpy (cp += 2, reloldpath, len); | ||||
| 	    } | ||||
| 	  else | ||||
| 	    { | ||||
| 	      *(unsigned short *)cp = len = strlen (w32topath); | ||||
| 	      memcpy (cp += 2, w32topath, len); | ||||
| 	      *(unsigned short *)cp = len = strlen (w32oldpath); | ||||
| 	      memcpy (cp += 2, w32oldpath, len); | ||||
| 	    } | ||||
| 	  cp += len; | ||||
| 	  success = WriteFile (h, buf, cp - buf, &written, NULL) | ||||
| @@ -2803,7 +2803,7 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	  /* This is the old technique creating a symlink. */ | ||||
| 	  char buf[sizeof (SYMLINK_COOKIE) + CYG_MAX_PATH + 10]; | ||||
|  | ||||
| 	  __small_sprintf (buf, "%s%s", SYMLINK_COOKIE, topath); | ||||
| 	  __small_sprintf (buf, "%s%s", SYMLINK_COOKIE, oldpath); | ||||
| 	  DWORD len = strlen (buf) + 1; | ||||
|  | ||||
| 	  /* Note that the terminating nul is written.  */ | ||||
| @@ -2828,7 +2828,7 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
| 	  SetFileAttributes (win32_path, attr); | ||||
|  | ||||
| 	  if (!isdevice && win32_path.fs_has_ea ()) | ||||
| 	    set_symlink_ea (win32_path, topath); | ||||
| 	    set_symlink_ea (win32_path, oldpath); | ||||
| 	  res = 0; | ||||
| 	} | ||||
|       else | ||||
| @@ -2840,8 +2840,8 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, | ||||
|     } | ||||
|  | ||||
| done: | ||||
|   syscall_printf ("%d = symlink_worker (%s, %s, %d, %d)", res, topath, | ||||
| 		  frompath, use_winsym, isdevice); | ||||
|   syscall_printf ("%d = symlink_worker (%s, %s, %d, %d)", res, oldpath, | ||||
| 		  newpath, use_winsym, isdevice); | ||||
|   return res; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -800,6 +800,7 @@ spawn_guts (const char * prog_arg, const char *const *argv, | ||||
|       strace.execing = 1; | ||||
|       myself.hProcess = hExeced = pi.hProcess; | ||||
|       strcpy (myself->progname, real_path); // FIXME: race? | ||||
|       close_all_files (true); | ||||
|       sigproc_printf ("new process name %s", myself->progname); | ||||
|       /* If wr_proc_pipe doesn't exist then this process was not started by a cygwin | ||||
| 	 process.  So, we need to wait around until the process we've just "execed" | ||||
| @@ -869,7 +870,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, | ||||
|   switch (mode) | ||||
|     { | ||||
|     case _P_OVERLAY: | ||||
|       close_all_files (); | ||||
|       if (!synced) | ||||
| 	/* let myself.exit handle this */; | ||||
|       else if (myself->wr_proc_pipe) | ||||
|   | ||||
| @@ -94,7 +94,7 @@ static int __stdcall stat_worker (const char *name, struct __stat64 *buf, | ||||
|    ensure we don't leave any such files lying around.  */ | ||||
|  | ||||
| void __stdcall | ||||
| close_all_files () | ||||
| close_all_files (bool norelease) | ||||
| { | ||||
|   cygheap->fdtab.lock (); | ||||
|  | ||||
| @@ -106,7 +106,8 @@ close_all_files () | ||||
| 	debug_printf ("closing fd %d", i); | ||||
| #endif | ||||
| 	fh->close (); | ||||
| 	cygheap->fdtab.release (i); | ||||
| 	if (!norelease) | ||||
| 	  cygheap->fdtab.release (i); | ||||
|       } | ||||
|  | ||||
|   if (cygheap->ctty) | ||||
|   | ||||
| @@ -223,7 +223,7 @@ void uinfo_init (void); | ||||
| void events_init (void); | ||||
| void events_terminate (void); | ||||
|  | ||||
| void __stdcall close_all_files (); | ||||
| void __stdcall close_all_files (bool = false); | ||||
|  | ||||
| /* Globals that handle initialization of winsock in a child process. */ | ||||
| extern HANDLE wsock32_handle; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user