From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by sourceware.org (Postfix) with ESMTPS id 016AD3858D37 for ; Sat, 12 Aug 2023 22:43:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 016AD3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nrubsig.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f50.google.com with SMTP id ca18e2360f4ac-790930d78e8so106887039f.1 for ; Sat, 12 Aug 2023 15:43:19 -0700 (PDT) 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: In-Reply-To: From: Roland Mainz Date: Sun, 13 Aug 2023 00:42:52 +0200 Message-ID: Subject: Re: Cygwin breaks net use Z: /delete in scripts? To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 List-Id: On Fri, Aug 11, 2023 at 10:55=E2=80=AFAM Corinna Vinschen via Cygwin 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 wor= ks. > > > > 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 < #!/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.k= sh $ 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.ks= h 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 machin= e ? ---- 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. --=20 __ . . __ (o.\ \/ /.o) roland.mainz@nrubsig.org \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /=3D=3D\ O\ TEL +49 641 3992797 (;O/ \/ \O;)