public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Cygwin breaks net use Z: /delete in scripts?
       [not found] <CANH4o6MPFhU-zaFiK+CRFi3HQRMTEW=yYc5kgiUP8O2Q2-L1Ww@mail.gmail.com>
@ 2023-08-11  8:55 ` Corinna Vinschen
  2023-08-12 22:42   ` Roland Mainz
  0 siblings, 1 reply; 3+ messages in thread
From: Corinna Vinschen @ 2023-08-11  8:55 UTC (permalink / raw)
  To: Martin Wege; +Cc: cygwin


First of all, do not send unsolicited email to my private address.
Especially, please don't use my company email address.

Keep Cygwin stuff on the cygwin list.

On Aug 11 10:25, Martin Wege wrote:
> Hello,
> 
> 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.


Corinna

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

* Re: Cygwin breaks net use Z: /delete in scripts?
  2023-08-11  8:55 ` Cygwin breaks net use Z: /delete in scripts? Corinna Vinschen
@ 2023-08-12 22:42   ` Roland Mainz
       [not found]     ` <CANH4o6PVVKA+eZpH5T6tqEM4+5hZ0t92A7rJgJuJXX_+zqK4gA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Roland Mainz @ 2023-08-12 22:42 UTC (permalink / raw)
  To: cygwin

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

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

* Re: Cygwin breaks net use Z: /delete in scripts?
       [not found]     ` <CANH4o6PVVKA+eZpH5T6tqEM4+5hZ0t92A7rJgJuJXX_+zqK4gA@mail.gmail.com>
@ 2023-08-13 18:01       ` Martin Wege
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Wege @ 2023-08-13 18:01 UTC (permalink / raw)
  To: cygwin

On Sun, Aug 13, 2023 at 7:13 PM Martin Wege <martin.l.wege@gmail.com> wrote:
>
> On Sun, Aug 13, 2023 at 12:43 AM Roland Mainz via Cygwin
> <cygwin@cygwin.com> wrote:
> >
> > 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 ?
>
> Yes, usually 12-14 filesystems mounted per machine. This includes user
> directories, and several directories where the software and production
> data come from. I still have to test whether putting software on a
> local disk solves the problem. Maybe I should better call this a
> workaround for a silly Windows restriction.

Yeah, putting software on a local disk allows me to do a successful
net use Z: /delete

So what do we do now? File a bug at Microsoft support, and they fix
that for Windows 12 in 2038?

Thanks,
Martin

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

end of thread, other threads:[~2023-08-13 18:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CANH4o6MPFhU-zaFiK+CRFi3HQRMTEW=yYc5kgiUP8O2Q2-L1Ww@mail.gmail.com>
2023-08-11  8:55 ` Cygwin breaks net use Z: /delete in scripts? Corinna Vinschen
2023-08-12 22:42   ` Roland Mainz
     [not found]     ` <CANH4o6PVVKA+eZpH5T6tqEM4+5hZ0t92A7rJgJuJXX_+zqK4gA@mail.gmail.com>
2023-08-13 18:01       ` Martin Wege

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).