This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[Patch] "strace ./app.exe" probably runs application from /bin
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin-patches at cygwin dot com
- Date: Sat, 02 Jun 2007 16:51:31 +0200
- Subject: [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 <franke@computer.org>
* 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.001000000 +0200
+++ cygwin-1.5.24-2/winsup/utils/strace.cc 2007-06-02 16:04:39.281250000 +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);