On Fri, Aug 11, 2023 at 10:55 AM Corinna Vinschen via Cygwin
<cygwin@cygwin.com> wrote:
[snip]
> On Aug 11 10:25, Martin Wege wrote:
> > Cygwin somehow breaks unmounting of network shares, but ONLY if the
> > net use /delete happens in a bash shell script.
> >
> > Example:
> > Mount SMB network share on Z:
> > Do not touch Z:!
> >
> > Then do a net use /delete in a bash script:
> > net use Z: /delete
> > Systemfehler 1794 aufgetreten.
> > Der Redirector wird verwendet und kann nicht aus dem Speicher entfernt 
> > werden.
> >
> > If I execute the net use Z: /delete in an interactive bash shell it works.
> >
> > Can anyone explain this?
>
> Something is wrong on your side, but no, I can't explain it.  It's
> not related to Cygwin:
>
> $ cat > b.sh <<EOF
> #!/bin/bash
> net use Z: /delete
> EOF
> $ chmod +x b.sh
> $ net use Z: \\\\server\\share
> The command completed successfully.
>
> B:[~]$ ./b.sh
> Z: was deleted successfully.

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.
-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

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

Reply via email to