delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/08/12/18:43:38

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E51A3858C31
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1691880216;
bh=PUgFOYn6XwXFXjDO7+chRnmgVIeig0yAAGpvotcwM9E=;
h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=MfOBQej2EllXQ0dtwTcJ/MLe4hs9iGP6UiXzEHrGImS5mSGYwlLBtq5AaJ0gEPuQW
nkL0QiXiiyFtdwuPwIAsHlTi/wg/JwSopOMeHteBvogPzcJRHOVFcWz0HlnGI3o1a7
G8l9yEnJsYRDK5fKAa8vgJpsW6JqfoMLFd4hvsjE=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 016AD3858D37
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1691880199; x=1692484999;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=1gKtGnD92WXJmnBZfpwprhk0BT1N1ybafW4JHRxofEs=;
b=hunh46MglBoGbztbrd64wHokJ8QDivPK5rE6B0GXtTP9eYzATTVZo4+AKfxTLEDYpZ
jPGhi547h0rMfwPP8CU6LMcSZButQu1M6zRaODTGTKW6vvnaF/EltXWGO4AeG6cca6ai
aC0WB6hxOLalQzuF8vmJZOgzjhq5jQbWlNQObCZTDe/wE6/LpHI6US3AfSyiL4kkuRj2
E2tDk0/yXmmFWbLBCnqmgmamqGyAu+lw2hG0FnitSNMo8824yuzjzJA/+MnRTkKSmcqh
vyN9L1pBVlrYXRxg8ofzo/+0x4rWiIbkmEIJfd/lxtXli8fPuapykMOPCeizRUTxyFFg
5SCg==
X-Gm-Message-State: AOJu0YwWn6Drcw2zaE/MM090coaaR1OnKD2TvmKPNCoIIWItGA4xyN2m
zkicYMhUfQB7K0Tg/p26TiajGgp1jqugc1Nd3W4fMO0lchI=
X-Google-Smtp-Source: AGHT+IESq2ehcR7MJx4XX3bx0MW09GGgsSwK63N9SDsQwMudTNNqZRbn/Ybur7r8u62zsihlHy4ZxTil1USu25l5TXE=
X-Received: by 2002:a6b:e005:0:b0:787:34d:f1a4 with SMTP id
z5-20020a6be005000000b00787034df1a4mr8451172iog.4.1691880198955; Sat, 12 Aug
2023 15:43:18 -0700 (PDT)
MIME-Version: 1.0
References: <CANH4o6MPFhU-zaFiK+CRFi3HQRMTEW=yYc5kgiUP8O2Q2-L1Ww AT mail DOT gmail DOT com>
<ZNX3a2DoNnY4whY8 AT calimero DOT vinschen DOT de>
In-Reply-To: <ZNX3a2DoNnY4whY8@calimero.vinschen.de>
Date: Sun, 13 Aug 2023 00:42:52 +0200
Message-ID: <CAKAoaQmxjomp1UGTha0dkKMdEQNacraOXp_Wscxpwk+w7o6ZTA@mail.gmail.com>
Subject: Re: Cygwin breaks net use Z: /delete in scripts?
To: cygwin AT cygwin DOT com
X-Spam-Status: No, score=3.7 required=5.0 tests=BAYES_40, FOREIGN_BODY1,
FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,
KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,
SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.6
X-Spam-Level: ***
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Roland Mainz via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Roland Mainz <roland DOT mainz AT nrubsig DOT org>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 37CMhb3r016625

On Fri, Aug 11, 2023 at 10:55 AM Corinna Vinschen via Cygwin
<cygwin AT cygwin DOT 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 DOT mainz AT nrubsig DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019