[Patch] "strace ./app.exe" probably runs application from /bin
Running an application with strace from current directory may not work as expected. The "./" is not passed to CreateProcess() and the default app search rules apply (1. strace.exe directory, 2. cwd, ..., 6. PATH) Therefore, an old version of the same app already installed in /bin may be run instead. Testcase: $ cd /tmp $ cp /bin/date.exe ./uname.exe $ date Sat Jun 2 16:34:23 2007 $ uname CYGWIN_NT-5.1 $ ./uname Sat Jun 2 16:34:24 2007 $ strace -o nul ./uname CYGWIN_NT-5.1 Workaround: $ strace -o nul ././uname Sat Jun 2 16:34:25 2007 The attached patch should fix this. 2007-06-02 Christian Franke <[EMAIL PROTECTED]> * strace.cc (create_child): Don't remove current directory from application path. Christian --- cygwin-1.5.24-2.orig/winsup/utils/strace.cc 2006-05-24 18:50:50.00100 +0200 +++ cygwin-1.5.24-2/winsup/utils/strace.cc 2007-06-02 16:04:39.28125 +0200 @@ -313,7 +313,19 @@ create_child (char **argv) BOOL ret; DWORD flags; - *argv = cygpath (*argv, NULL); + if (strncmp(*argv, "./", 2) == 0) +{ + // cygpath() removes "./". Add another to avoid that + // CreateProcess() uses its application search rules + // (1. app dir, 2. cwd, ..., 6. PATH). + char arg0[2 + strlen(*argv) + 1]; + strcpy (arg0, "./"); + strcpy (arg0+2, *argv); + *argv = cygpath (arg0, NULL); +} + else +*argv = cygpath (*argv, NULL); + memset (&si, 0, sizeof (si)); si.cb = sizeof (si);
Re: [Patch] "strace ./app.exe" probably runs application from /bin
On Sat, Jun 02, 2007 at 04:51:31PM +0200, Christian Franke wrote: >Running an application with strace from current directory may not work >as expected. >The "./" is not passed to CreateProcess() and the default app search >rules apply >(1. strace.exe directory, 2. cwd, ..., 6. PATH) > >Therefore, an old version of the same app already installed in /bin may >be run instead. > > >Testcase: > >$ cd /tmp > >$ cp /bin/date.exe ./uname.exe > >$ date >Sat Jun 2 16:34:23 2007 > >$ uname >CYGWIN_NT-5.1 > >$ ./uname >Sat Jun 2 16:34:24 2007 > >$ strace -o nul ./uname >CYGWIN_NT-5.1 > >Workaround: > >$ strace -o nul ././uname >Sat Jun 2 16:34:25 2007 > > >The attached patch should fix this. > >2007-06-02 Christian Franke <[EMAIL PROTECTED]> > > * strace.cc (create_child): Don't remove current directory > from application path. Thanks for the problem report and test case but this is pretty clearly not the right way to deal with the issue. Putting a special case catch of "./" around a function call which is intended to deal with paths is pretty clearly a band-aid. Let me rephrase the problem: "cygpath does not properly deal with the current directory" Thanks for the patch but we won't be applying it in this form. cgf
Re: [Patch] "strace ./app.exe" probably runs application from /bin
Christopher Faylor wrote: ... Thanks for the problem report and test case but this is pretty clearly not the right way to deal with the issue. Putting a special case catch of "./" around a function call which is intended to deal with paths is pretty clearly a band-aid. Yes. Let me rephrase the problem: "cygpath does not properly deal with the current directory" It depends. Removing "./" from a path is usually OK. Except when application search should be enabled if a path is missing. I don't know whether this current behaviour of path.cc:cygpath() is required somewhere else (cygcheck.cc, dump_setup.cc ...). Thats the reason why I didn't modify cygpath() itself and used this (workaround|hack) instead. Christian
Re: [Patch] "strace ./app.exe" probably runs application from /bin
Christopher Faylor wrote: > Let me rephrase the problem: > > "cygpath does not properly deal with the current directory" > > Thanks for the patch but we won't be applying it in this form. I've been meaning to take a look at fixing this myself, because I'm tired of: $ cd /usr/bin $ cygcheck ./ls .\.\.\.\ - Cannot open $ cygcheck ls - Cannot open Error: could not find ls $ cygcheck ls.exe - Cannot open Error: could not find ls.exe $ cygcheck ./ls.exe .\ls.exe .\cygwin1.dll C:\WINXP\system32\ADVAPI32.DLL C:\WINXP\system32\ntdll.dll C:\WINXP\system32\KERNEL32.dll C:\WINXP\system32\RPCRT4.dll .\cygintl-8.dll .\cygiconv-2.dll Brian