Cygwin 破坏了脚本中的 net use Z: /delete?

问题描述 投票:0回答:1

Cygwin 以某种方式破坏了网络共享的卸载,但前提是

net use /delete
发生在 bash shell 脚本中。

示例: 在 Z 上挂载 SMB 网络共享: 不要碰Z:!

然后在 bash 脚本中执行 net use /delete:

net use Z: /delete

结果:

Systemfehler 1794 aufgetreten。 Der Redirector 已被修改并可在 Speicher 中使用。

如果我在交互式 bash shell 中执行

net use Z: /delete
,它就会起作用。

谁能解释一下吗?

bash cygwin
1个回答
0
投票
I think it's the problem that a shell keeps a fd open to the shell
script's file.

Example:
---- snip ----
$ cat shellfd.ksh
#!/bin/ksh93
# shell script printing the fd which the shell
# process has open right now
ls -l /proc/$$/fd/
true # needed here so ksh93 doesn't make a tail optimisation
exit 0
$ bash shellfd.ksh
total 0
lrwx------ 1 test001 users 64 Aug 13 00:26 0 -> /dev/pts/7
lrwx------ 1 test001 users 64 Aug 13 00:26 1 -> /dev/pts/7
lrwx------ 1 test001 users 64 Aug 13 00:26 2 -> /dev/pts/7
lr-x------ 1 test001 users 64 Aug 13 00:26 255 -> /cygdrive/h/tmp/shellfd.ksh
$ ksh93 shellfd.ksh
total 0
lrwx------ 1 test001 users 64 Aug 13 00:26 0 -> /dev/pts/7
lrwx------ 1 test001 users 64 Aug 13 00:26 1 -> /dev/pts/7
lr-x------ 1 test001 users 64 Aug 13 00:26 10 -> /cygdrive/h/tmp/shellfd.ksh
lrwx------ 1 test001 users 64 Aug 13 00:26 2 -> /dev/pts/7
---- snip ----

So both bash4 an ksh93 keep a fd to the shell script ("shellfd.ksh")
around (I even tried /usr/bin/shcomp to make shell bytecode, but the
issue remains...)

And here comes the nasty part: If shellfd.ksh is on a network
filesystem (in my test setup my home dir, mounted at H:), then in some
cases (I do not know why) a $ net use Z: /delete # will fail with
error #1794 if both network filesystems are from the same server.

This is NOT the same as the script tries to unmount the filesystem it
is residing on - Z: is mounted separately, and a different exported
directory than H:, and yet I can reproduce that issue (after around
30-40 experiments, until I remembered that ksh93 keeps a fd to the
script open).

This sounds a lot like a Windows bug.

Martin: Do you have more than one network filesystem mounted on your machine ?

----

Bye,
Roland

P.S.: There is no way to close the fd to the script from within the
same script, e.g. $ command exec 10<&- # will the trigger the shell
interpreters just to |dup()| the fd to another number.
© www.soinside.com 2019 - 2024. All rights reserved.