Index: src/run.c =================================================================== RCS file: /cvs/cygwin-apps/run/src/run.c,v retrieving revision 1.10 diff -u -p -r1.10 run.c --- src/run.c 2 Dec 2009 02:51:54 -0000 1.10 +++ src/run.c 18 Aug 2010 18:35:47 -0000 @@ -198,6 +198,33 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPre { STARTUPINFO start; PROCESS_INFORMATION child; +#if defined(__CYGWIN__) + /* Special CWD handling needed when calling CreateProcess() from a + * cygwin program, when cygwin kernel is 1.7.6 or above. See discussion + * in the following threads: + * http://cygwin.com/ml/cygwin/2010-08/msg00205.html + * http://cygwin.com/ml/cygwin-developers/2010-08/msg00002.html + */ + char * win32_cwd; + long size; + char *posix_buf; + char *posix_cwd = NULL; + size = pathconf(".", _PC_PATH_MAX); + if ((posix_buf = (char *)malloc((size_t)size)) != NULL) + { + posix_cwd = getcwd(posix_buf, (size_t)size); + if (posix_cwd) + { +# if defined(HAVE_DECL_CYGWIN_CONV_PATH) + win32_cwd = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A, (void *) posix_cwd); +# else + win32_cwd = (char *) malloc (MAX_PATH); + if (win32_cwd) + cygwin_conv_to_win32_path (posix_cwd, win32_cwd); +# endif + } + } +#endif ZeroMemory( &child, sizeof(PROCESS_INFORMATION) ); ZeroMemory (&start, sizeof (STARTUPINFO)); start.cb = sizeof (STARTUPINFO); @@ -209,9 +236,26 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPre FALSE, /* handles are NOT inherited, */ 0, /* creation flags */ NULL, /* use parent's environment */ - NULL, /* use parent's current directory */ +#if defined(__CYGWIN__) + win32_cwd, /* working directory; may be null */ +#else + NULL, /* use parent's working directory */ +#endif &start, /* STARTUPINFO pointer */ &child); /* receives PROCESS_INFORMATION */ +#if defined(__CYGWIN__) + if (win32_cwd) + { + free (win32_cwd); + win32_cwd = NULL; + } + if (posix_buf) + { + free (posix_buf); + posix_buf = NULL; + posix_cwd = NULL; + } +#endif if (ret_code == 0) { Trace(("getlasterror: %d\n", GetLastError()));