public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Fails to launch batch script in some directories
       [not found] <Alexpux/MSYS2-packages/issues/1225@github.com>
@ 2018-04-20 12:33 ` David Macek
  2018-04-20 13:11   ` Brian Inglis
  2018-04-20 13:11   ` Corinna Vinschen
  0 siblings, 2 replies; 8+ messages in thread
From: David Macek @ 2018-04-20 12:33 UTC (permalink / raw)
  To: reply+00155a6ef4416c2113f58d183fd7993b49cc171de678259092cf0000000116f197cf92a169ce12d96d1e,
	cygwin

[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

Whoa, an interesting bug.  I'm forwarding this to the Cygwin mailing list for reference.  I might take a deeper look over the weekend if no-one beats me to it.

It seems like running batch files (.bat, .cmd) inside a directory with an at sign and a space (such as '@ x' or 'x @') fails.

/w/temp/@ x$ ./hello.bat
'W:\temp\@' is not recognized as an internal or external command,
operable program or batch file.

-- 
David Macek


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4002 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-20 12:33 ` Fails to launch batch script in some directories David Macek
@ 2018-04-20 13:11   ` Brian Inglis
  2018-04-20 13:11   ` Corinna Vinschen
  1 sibling, 0 replies; 8+ messages in thread
From: Brian Inglis @ 2018-04-20 13:11 UTC (permalink / raw)
  To: cygwin

On 2018-04-20 06:33, David Macek wrote:
> Whoa, an interesting bug.  I'm forwarding this to the Cygwin mailing list for
> reference.  I might take a deeper look over the weekend if no-one beats me to it.
> 
> It seems like running batch files (.bat, .cmd) inside a directory with an at
> sign and a space (such as '@ x' or 'x @') fails.
> 
> /w/temp/@ x$ ./hello.bat
> 'W:\temp\@' is not recognized as an internal or external command,
> operable program or batch file.

From strace on cmd run from directory created with same name, looks like
child_info_spawn::worker may need to escape/double quote the name if it contains
spaces:

   65  119143 [main] bash 9384 spawnve: spawnve (./ntpstatus.cmd,
./ntpstatus.cmd, 0x60006F6B0)
   34  119177 [main] bash 9384 child_info_spawn::worker: mode = 3, prog_arg =
./ntpstatus.cmd
   36  119213 [main] bash 9384 perhaps_suffix: prog './ntpstatus.cmd'
   30  119243 [main] bash 9384 normalize_posix_path: src ./ntpstatus.cmd
   28  119271 [main] bash 9384 cwdstuff::get: posix /proc/cygdrive/c/.../@ x
   29  119300 [main] bash 9384 cwdstuff::get: (/proc/cygdrive/c/.../@ x) =
cwdstuff::get (0x600000010, 32768, 1, 0), errno 108
   29  119329 [main] bash 9384 normalize_posix_path: /proc/cygdrive/c/.../@
x/ntpstatus.cmd = normalize_posix_path (./ntpstatus.cmd)
   30  119359 [main] bash 9384 mount_info::conv_to_win32_path:
conv_to_win32_path (/proc/cygdrive/c/.../@ x/ntpstatus.cmd)
   33  119392 [main] bash 9384 mount_info::cygdrive_win32_path: src
'/proc/cygdrive/c/.../@ x/ntpstatus.cmd', dst 'C:\...\@ x\ntpstatus.cmd'
   33  119425 [main] bash 9384 set_flags: flags: binary (0x2)
   28  119453 [main] bash 9384 mount_info::conv_to_win32_path: src_path
/proc/cygdrive/c/.../@ x/ntpstatus.cmd, dst C:\...\@ x\ntpstatus.cmd, flags
0x4022, rc 0
  153  119606 [main] bash 9384 symlink_info::check: 0x0 = NtCreateFile
(\??\C:\...\@ x\ntpstatus.cmd)
   85  119691 [main] bash 9384 symlink_info::check: not a symlink
   79  119770 [main] bash 9384 symlink_info::check: 0 = symlink.check(C:\...\@
x\ntpstatus.cmd, 0xFFFFA850) (0x4022)
   55  119825 [main] bash 9384 path_conv::check: this->path(C:\...\@
x\ntpstatus.cmd), has_acls(1)
   35  119860 [main] bash 9384 perhaps_suffix: buf C:\...\@ x\ntpstatus.cmd,
suffix found ''
   90  119950 [main] bash 9384 child_info_spawn::worker: priority class 32
   95  120045 [main] bash 9384 fhandler_console::need_invisible: invisible_console 0
   39  120084 [main] bash 9384 build_env: envp 0x60006F6B0
   38  120122 [main] bash 9384 spenv::retrieve: no_envblock 0
   40  120162 [main] bash 9384 spenv::retrieve: duping existing value for
'USERDOMAIN='
   48  120210 [main] bash 9384 spenv::retrieve: no_envblock 0
   39  120249 [main] bash 9384 spenv::retrieve: duping existing value for
'USERNAME='
   29  120278 [main] bash 9384 spenv::retrieve: no_envblock 0
   28  120306 [main] bash 9384 spenv::retrieve: duping existing value for
'LOGONSERVER='
   35  120341 [main] bash 9384 spenv::retrieve: no_envblock 0
   32  120373 [main] bash 9384 spenv::retrieve: no_envblock 0
   27  120400 [main] bash 9384 spenv::retrieve: duping existing value for
'USERPROFILE='
   29  120429 [main] bash 9384 spenv::retrieve: no_envblock 0
   27  120456 [main] bash 9384 spenv::retrieve: duping existing value for
'SYSTEMROOT='
   43  120499 [main] bash 9384 spenv::retrieve: no_envblock 0
   31  120530 [main] bash 9384 spenv::retrieve: duping existing value for 'WINDIR='
   37  120567 [main] bash 9384 spenv::retrieve: no_envblock 0
   30  120597 [main] bash 9384 spenv::retrieve: no_envblock 0
   27  120624 [main] bash 9384 spenv::retrieve: duping existing value for
'HOMEDRIVE='
   33  120657 [main] bash 9384 spenv::retrieve: no_envblock 0
   28  120685 [main] bash 9384 spenv::retrieve: duping existing value for
'HOMEPATH='
   34  120719 [main] bash 9384 build_env: env count 108, bytes 9407
  324  121043 [main] bash 9384 build_env: envp 0x180306DA8, envc 108
   34  121077 [main] bash 9384 child_info::child_info: subproc_ready 0x0
20253  141330 [main] bash 9384 child_info_spawn::worker: pid 9384, prog_arg
./ntpstatus.cmd, cmd line "C:\...\@ x\ntpstatus.cmd")
  102  141432 [main] bash 9384! child_info_spawn::worker: new process name
\\?\C:\...\@ x\ntpstatus.cmd
   56  141488 [main] bash 9384! fhandler_base::close_with_arch: line 1129:
/dev/pty0<0x1803054F0> usecount + -1 = 3
   31  141519 [main] bash 9384! fhandler_base::close_with_arch: not closing
archetype
   67  141586 [main] bash 9384! fhandler_base::close_with_arch: line 1129:
/dev/pty0<0x1803054F0> usecount + -1 = 2
   33  141619 [main] bash 9384! fhandler_base::close_with_arch: not closing
archetype
   34  141653 [main] bash 9384! fhandler_base::close_with_arch: line 1129:
/dev/pty0<0x1803054F0> usecount + -1 = 1
   35  141688 [main] bash 9384! fhandler_base::close_with_arch: not closing
archetype
   38  141726 [main] bash 9384! child_info_spawn::worker: spawned windows pid 9260
   52  141778 [main] bash 9384! proc_subproc: args: 1, -2145357536
--- Process 9260 created
--- Process 9384 thread 8320 created
  306  142084 [main] bash 9384! pinfo::wait: created tracking thread for pid
9384, winpid 0x242C, rd_proc_pipe 0x284
   48  142132 [main] bash 9384! proc_subproc: added pid 9384 to proc table, slot 0
   45  142177 [main] bash 9384! proc_subproc: returning 1
--- Process 9260 loaded C:\Windows\System32\ntdll.dll at 00007ffb92730000
   89  142266 [waitproc] bash 9384! cygthread::stub: thread 'waitproc', id
0x2080, stack_ptr 0x329CCD0
--- Process 9260 loaded C:\Windows\System32\kernel32.dll at 00007ffb918e0000
--- Process 9260 loaded C:\Windows\System32\KernelBase.dll at 00007ffb8f750000
--- Process 9260 loaded C:\Windows\System32\msvcrt.dll at 00007ffb91840000
--- Process 9260 thread 5056 created
--- Process 2844 created
--- Process 2844 loaded C:\Windows\System32\ntdll.dll at 00007ffb92730000
--- Process 2844 loaded C:\Windows\System32\kernel32.dll at 00007ffb918e0000
--- Process 2844 loaded C:\Windows\System32\KernelBase.dll at 00007ffb8f750000
--- Process 2844 loaded C:\Windows\System32\msvcrt.dll at 00007ffb91840000
--- Process 2844 thread 5964 created
--- Process 2844 thread 32 created
--- Process 2844 loaded C:\Windows\System32\ulib.dll at 00007ffb7dcd0000
--- Process 2844 thread 6228 created
--- Process 2844 loaded C:\Windows\System32\fsutilext.dll at 00007ffb8a980000
--- Process 2844 thread 5964 exited with status 0x0
--- Process 2844 thread 6228 exited with status 0x0
--- Process 2844 thread 32 exited with status 0x0
--- Process 2844 exited with status 0x0
--- Process 9260 thread 5056 exited with status 0x1
--- Process 9260 exited with status 0x1
45516  187782 [waitproc] bash 9384! pinfo::maybe_set_exit_code_from_windows: pid
9384, exit value - old 0x0, windows 0x1, cygwin 0x8000100
  110  187892 [waitproc] bash 9384! proc_waiter: exiting wait thread for pid 9384
   47  187939 [main] bash 9384! proc_terminate: nprocs 1
   81  188020 [main] bash 9384! proc_subproc: args: 5, 1
   80  188100 [main] bash 9384! proc_subproc: clear waiting threads
   47  188147 [main] bash 9384! proc_subproc: finished clearing
   34  188181 [main] bash 9384! proc_subproc: returning 1
   30  188211 [main] bash 9384! cygthread::terminate_thread: thread '(null)', id
0x2080, inuse 0, stack_ptr 0x329CCD0
   31  188242 [main] bash 9384! proc_terminate: leaving
   30  188272 [main] bash 9384! pinfo::maybe_set_exit_code_from_windows: pid
9384, exit value - old 0x8000100, windows 0xDEADBEEF, cygwin 0x8000100
   55  188327 [main] bash 9384! pinfo::exit: Calling ExitProcess n 0x4000000,
exitcode 0x1

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-20 12:33 ` Fails to launch batch script in some directories David Macek
  2018-04-20 13:11   ` Brian Inglis
@ 2018-04-20 13:11   ` Corinna Vinschen
  2018-04-21 15:39     ` Brian Inglis
  1 sibling, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2018-04-20 13:11 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 895 bytes --]

On Apr 20 14:33, David Macek wrote:
> Whoa, an interesting bug.  I'm forwarding this to the Cygwin mailing list for reference.  I might take a deeper look over the weekend if no-one beats me to it.
> 
> It seems like running batch files (.bat, .cmd) inside a directory with an at sign and a space (such as '@ x' or 'x @') fails.
> 
> /w/temp/@ x$ ./hello.bat
> 'W:\temp\@' is not recognized as an internal or external command,
> operable program or batch file.

Funny.  That's very likely a bug in the @file handling in function
insert_file() in dcrt0.cc.  This is basically stone-age old code
to pamper starting Cygwin tools with too long commandl ines from cmd.

I'm looking forward with what you're coming up with.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-20 13:11   ` Corinna Vinschen
@ 2018-04-21 15:39     ` Brian Inglis
  2018-04-23  6:43       ` David Macek
  0 siblings, 1 reply; 8+ messages in thread
From: Brian Inglis @ 2018-04-21 15:39 UTC (permalink / raw)
  To: cygwin

On 2018-04-20 07:11, Corinna Vinschen wrote:
> On Apr 20 14:33, David Macek wrote:
>> Whoa, an interesting bug. I'm forwarding this to the Cygwin mailing list 
>> for reference. I might take a deeper look over the weekend if no-one beats
>> me to it.
>> It seems like running batch files (.bat, .cmd) inside a directory with an 
>> at sign and a space (such as '@ x' or 'x @') fails.
>> /w/temp/@ x$ ./hello.bat
>> 'W:\temp\@' is not recognized as an internal or external command, operable
>> program or batch file.
> Funny. That's very likely a bug in the @file handling in function 
> insert_file() in dcrt0.cc. This is basically stone-age old code to pamper
> starting Cygwin tools with too long commandl ines from cmd.
> I'm looking forward with what you're coming up with.

See my other post in this thread where strace shows @ handling is not involved,
as the script directory and name are normalized and converted to a win32 path
correctly, but child_info_spawn::worker does not appear to quote args with
spaces (or apostrophes) when building the command line, despite the comment near
the top of the function.
It is not clear where this quoting is expected to be done: it looks like
child_info_spawn::worker may do this itself when a script is invoked as
"cmd|command /c script" with argc == 3, but may be expecting a called function
to do this for other cases, as for a cmd script with no args and argc == 1.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-21 15:39     ` Brian Inglis
@ 2018-04-23  6:43       ` David Macek
  2018-04-23  8:45         ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: David Macek @ 2018-04-23  6:43 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

On 21. 4. 2018 17:38, Brian Inglis wrote:
> See my other post in this thread where strace shows @ handling is not involved,
> as the script directory and name are normalized and converted to a win32 path
> correctly, but child_info_spawn::worker does not appear to quote args with
> spaces (or apostrophes) when building the command line, despite the comment near
> the top of the function.

Do you have a test case for this?  In my testing, paths with spaces (like 'x y' instead of '@ x') work just fine.

-- 
David Macek


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4002 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-23  6:43       ` David Macek
@ 2018-04-23  8:45         ` Corinna Vinschen
  2018-04-23 17:20           ` Brian Inglis
  0 siblings, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2018-04-23  8:45 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1789 bytes --]

On Apr 23 08:43, David Macek wrote:
> On 21. 4. 2018 17:38, Brian Inglis wrote:
> > See my other post in this thread where strace shows @ handling is not involved,
> > as the script directory and name are normalized and converted to a win32 path
> > correctly, but child_info_spawn::worker does not appear to quote args with
> > spaces (or apostrophes) when building the command line, despite the comment near
> > the top of the function.
> 
> Do you have a test case for this?  In my testing, paths with spaces (like 'x y' instead of '@ x') work just fine.

Brian has a point though.  It's not a space *in* a filename, it's a
*trailing* space.  And that points to the cause of the problem:

Paths with trailing spaces are invalid DOS paths.

Try this:

  bash$ mkdir "x "
  bash$ cmd
  C:\...>cd "x "
  cd "x "
  The system cannot find the path specified.

The problem is not exactly in Cygwin, it's the good old fact that Win32
tools using the WIn32 file API just can't accfess the file because they
don't see it.  The Win32 API simply deletes trailing spaces from
filenames, in and out.

Cygwin doesn't suffer this problem because it uses the underlying NT API.

https://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-specialchars

The only workaround from Cygwin's side would be to convert 0x20 spaces
to 0xf020 characters as the other invalid chars as outlined in the above
URL.  However, this would only be ok for trailing spaces, given that
leading or in-between spaces are perfectly valid.  Sounds kind of
error prone.

IMHO, better leave it as is and tell the user.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-23  8:45         ` Corinna Vinschen
@ 2018-04-23 17:20           ` Brian Inglis
  2018-04-24  7:55             ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Brian Inglis @ 2018-04-23 17:20 UTC (permalink / raw)
  To: cygwin

On 2018-04-23 02:44, Corinna Vinschen wrote:
> On Apr 23 08:43, David Macek wrote:
>> On 21. 4. 2018 17:38, Brian Inglis wrote:
>>> See my other post in this thread where strace shows @ handling is not involved,
>>> as the script directory and name are normalized and converted to a win32 path
>>> correctly, but child_info_spawn::worker does not appear to quote args with
>>> spaces (or apostrophes) when building the command line, despite the comment near
>>> the top of the function.
>> Do you have a test case for this? In my testing, paths with spaces (like
>> 'x y' instead of '@ x') work just fine.
> Brian has a point though.  It's not a space *in* a filename, it's a
> *trailing* space.  And that points to the cause of the problem:

No trailing space - middle char - the directory name was exactly as in the OP:
".../@ x/" - see strace output.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fails to launch batch script in some directories
  2018-04-23 17:20           ` Brian Inglis
@ 2018-04-24  7:55             ` Corinna Vinschen
  0 siblings, 0 replies; 8+ messages in thread
From: Corinna Vinschen @ 2018-04-24  7:55 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]

On Apr 23 11:20, Brian Inglis wrote:
> On 2018-04-23 02:44, Corinna Vinschen wrote:
> > On Apr 23 08:43, David Macek wrote:
> >> On 21. 4. 2018 17:38, Brian Inglis wrote:
> >>> See my other post in this thread where strace shows @ handling is not involved,
> >>> as the script directory and name are normalized and converted to a win32 path
> >>> correctly, but child_info_spawn::worker does not appear to quote args with
> >>> spaces (or apostrophes) when building the command line, despite the comment near
> >>> the top of the function.
> >> Do you have a test case for this? In my testing, paths with spaces (like
> >> 'x y' instead of '@ x') work just fine.
> > Brian has a point though.  It's not a space *in* a filename, it's a
> > *trailing* space.  And that points to the cause of the problem:
> 
> No trailing space - middle char - the directory name was exactly as in the OP:
> ".../@ x/" - see strace output.

My bad.  When I read the OP I read "@ " as dir name.  I missed the "x".


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-04-24  7:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Alexpux/MSYS2-packages/issues/1225@github.com>
2018-04-20 12:33 ` Fails to launch batch script in some directories David Macek
2018-04-20 13:11   ` Brian Inglis
2018-04-20 13:11   ` Corinna Vinschen
2018-04-21 15:39     ` Brian Inglis
2018-04-23  6:43       ` David Macek
2018-04-23  8:45         ` Corinna Vinschen
2018-04-23 17:20           ` Brian Inglis
2018-04-24  7:55             ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).