From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) by sourceware.org (Postfix) with ESMTPS id 6617A3857003 for ; Thu, 25 Feb 2021 17:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6617A3857003 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M3DBb-1lG8zk354P-003bi5 for ; Thu, 25 Feb 2021 18:03:37 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id 2ACFBA80D4E; Thu, 25 Feb 2021 18:03:37 +0100 (CET) Date: Thu, 25 Feb 2021 18:03:37 +0100 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: fstat and similar methods in fhandler_socket_local and fhandler_socket_unix Message-ID: Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: <508b12a5-9797-9236-a5b5-d8ff5968ad5d@cornell.edu> <76be1cd8-0b9a-3689-0b9e-cea689178a16@cornell.edu> <0be341b4-371e-2941-4407-93bef6ff3871@cornell.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0be341b4-371e-2941-4407-93bef6ff3871@cornell.edu> X-Provags-ID: V03:K1:i5fx1IMBdvaz5e2DiO+6dqDKa8+H6lDB0L4tEb1Rk+wN/jehubu zczSU4f63r9xRrm8Xn2F3UKVfUNi1lMLaXftQw+Aln41OsLGUSjoj5eGV81AEgRnr3pAyVw qV2R6q/Z69f09wU5NDd3AtCSEyCP7IR9Oc4Rf1g2/Cge6SnnwO8K/GygPbPoKOupCilBMwd yeNRsA4QXzNvexacXdxNg== X-UI-Out-Filterresults: notjunk:1;V03:K0:q4eXjmg+Xww=:MhJx9OYtHOUECKeU4jH6VC TbIfFFTgRFldkrlei34HpTOpkZwdAXMrsiEcXxKnDGMhvrgyY0E/L3iPJhyRRU0sAqShGZRhP 35vBw5yj8ex6scpZW6j/S+rJYEsPAStDXhnPA03kBHkT43+KqXStU4jTSgfpgrQjaluzeUgwa TbxOSxwhv9BXH9WIVcyUXl6RFqhaasftBs+z8OaGWF3Oh+OcViO/1/jGYLfD0xUP2C4euvxvu TpA5UgxSXbCiHEx3nw80Ru8mHSmMBRD+fF+GsYzvEa8InQOG8cxmCFA2Y89Bdmw0gadwCJErD 9FXyyPkqolFTUSiF+9uYEwl2wYgJOBwimohiviVF8pEZsT8usAglWYqb5L36Tfgxuc478b3Je Yr9V2dbqFXCQuywVWubyesc+cL3xxr4TyZnuSfRSXQIXJTMR/Ugj9KflM/9hrZ0obFg16ACwe snE1dHnpIQ== X-Spam-Status: No, score=-101.1 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2021 17:03:40 -0000 On Feb 25 08:18, Ken Brown via Cygwin-developers wrote: > While working on this, I discovered that linkat(AT_EMPTY_PATH) doesn't > currently work on socket files opened with O_PATH. I started debugging this > (not finished yet), and it occurred to me that the implementation of > linkat(AT_EMPTY_PATH) could be simplified like this: > > --- a/winsup/cygwin/syscalls.cc > +++ b/winsup/cygwin/syscalls.cc > @@ -4962,6 +4962,8 @@ linkat (int olddirfd, const char *oldpathname, > int flags) > { > tmp_pathbuf tp; > + fhandler_base *fh = NULL; > + > __try > { > if (flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) > @@ -4970,21 +4972,19 @@ linkat (int olddirfd, const char *oldpathname, > __leave; > } > char *oldpath = tp.c_get (); > - /* AT_EMPTY_PATH with an empty oldpathname is equivalent to > - > - linkat(AT_FDCWD, "/proc/self/fd/", newdirfd, > - newname, AT_SYMLINK_FOLLOW); > - > - Convert the request accordingly. */ > if ((flags & AT_EMPTY_PATH) && oldpathname && oldpathname[0] == '\0') > { > + /* Operate directly on olddirfd. */ > if (olddirfd == AT_FDCWD) > { > set_errno (EPERM); > __leave; > } > - __small_sprintf (oldpath, "/proc/%d/fd/%d", myself->pid, olddirfd); > - flags = AT_SYMLINK_FOLLOW; > + cygheap_fdget cfd (olddirfd); > + if (cfd < 0) > + __leave; > + fh = cfd; > + flags = 0; > } > else if (gen_full_path_at (oldpath, olddirfd, oldpathname)) > __leave; > @@ -5003,6 +5003,8 @@ linkat (int olddirfd, const char *oldpathname, > } > strcpy (oldpath, old_name.get_posix ()); > } > + if (fh) > + return fh->link (newpath); > return link (oldpath, newpath); > } > __except (EFAULT) {} Good idea. Just a small comment why you set flags to 0 might be nice. > This seems to work fine on regular files and on socket files opened with > O_PATH, after I tweak fhandler_socket_local::link (see below). I haven't > tested other file types yet. For most of them that should end up in fhandler_base:link anyway. Thanks, Corinna