From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 13369 invoked from network); 9 Oct 2020 20:54:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Oct 2020 20:54:14 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1602276854; b=WzjVfjkcAJ7X+vNB5Rn9k8ftAsY8IeGpyPnh/lZfwd9/LLoroKrTAgCeBwDWN7aHWYs/j6GldI 0gnd+QT3XyBHPJgQN+BHrRPs9xGYL1TqAPNx8vQ4/r8nAoqpLi7nqpek2m0y5LeT0OGYmNbjcJ Pgxw4yZ1Lnujtg0xXjyTkaKthYLjw8VN+cuBn3+N2p/xUmPjX3YtQ6Zx3Q09+uz58WvQLCcHY7 HpeHVN9ZeJOKqvchT0OiCavC2BbWOiyKImCX5fJti9mX8r8PNG9x8UYOV5dOXsys7JUj9YaNcb Ew2GEQxQQuRvd8ouWauhJsuj8NNP+Em62e5phqmY8f2Ftg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oo1-f50.google.com) smtp.remote-ip=209.85.161.50; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1602276854; bh=c9HFYsuAPVFK1qNZRc2Css1eFs53fncaB/J5+zARSB8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:DKIM-Signature:DKIM-Signature; b=NG87ZSPqs1WmnXtET6q+tUou33Sri3SZo1+oKbndz099XJo17aBChScUsWcUlV/P9tib9RPWNU +QgW7k84dRK7MbFvdWZ91HrGauo9UcasRHls+yb1QIgt+sUuJ31yXloGaL/t4P2MGHaHu8nRFy 6iF+HDb4fhXM6+mTkIz9sZM7vZrmGn7USW2jABBR/wA4Ijok7uJTkoT5Sya7hatBtx7VfRvg3K jsDEjQsWu9nf2if8TDyrDtlDstKPHe/IAukw4uxyAHgEsVw6Vx09T3Z9l6/6mJ4EYKcB5FZK8v o8FH9Xv0auTq0PqRnJM7BiztdlpdJVfVgYek5XfWXPjmTA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:To:From:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=OK/DT0OZdXQTZKGoEFxRW3m1TjcOITk1THne4RinEeM=; b=npbetqrjvpJjhXTa2cd7dITV9h 2EkR8P5iysM6IuD76Kx1i3kPKHs+ajfmNrmkAcbYGseKJl2nwNN6xNeUGWL4wiDpQMIUvkQnotDXJ MGoxPX3vcwLsWraBjX8rHx2zpgtU8gXTOQf4mBNC2w2aS5UGGtSSDDlCPIbLDkqrQTqlBFLVVsRIa j+V1HjiyQumcHlasWuTyS8DT0F1hZ5C9jISH/Jr6x3adlIfA8LwWNv7/s0jBaOm0yseYdG1LRgvxO 4SHGaB0iEGeo/Gk7Pg0MtAmXnZswjLw/VoxKoTUGn+1q8WSrMFTQ1evcmj6F+ydnHjuQRMDWMhUdB AGDWm2DA==; Received: from authenticated user by zero.zsh.org with local id 1kQzP3-000IuO-20; Fri, 09 Oct 2020 20:54:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oo1-f50.google.com) smtp.remote-ip=209.85.161.50; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-oo1-f50.google.com ([209.85.161.50]:36484) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kQzOr-000Ikz-F5; Fri, 09 Oct 2020 20:54:01 +0000 Received: by mail-oo1-f50.google.com with SMTP id z1so2683270ooj.3 for ; Fri, 09 Oct 2020 13:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=OK/DT0OZdXQTZKGoEFxRW3m1TjcOITk1THne4RinEeM=; b=TM6xVnhczV+MkbG/zh5ALxeFjbuiQlN+E05TIVu9qKQv8+UomE2oG3ETKnESVefYLB 9dA9QbahmIT6D3pNRcdwe3+P2ORBR5ZMiQEfl7gRAfqquCWiyjammJZHYzG1RwJcru6E QTYisKGrKvjxDt1ok97V7NI8JjGzc1o6e7q7Eol19uCAziGqELut1JU9KH5zHbQUBpEf BnyasxJc+MZQR9q7S5JAuL58031pUhwQIKAw1aScHEfCdfgAXv88U5Pwf2qWSlhpUzBY 13nFn4ErNuxrLrhj+kPVnno/E+THIpgX8jZNU+ep9U3wVtq+beQI3ETdVeVE5wJHVDa/ QodA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=OK/DT0OZdXQTZKGoEFxRW3m1TjcOITk1THne4RinEeM=; b=tazspEwFB7rLZQ86J0TCU9e7y3d66pheZyv9grS1EKcLowu1YS0WaSksSMIJaH4ezV RKE+ZQJmEf1Ehf1gVtHOuG6y/kBnurtHrcaEfOyU0YBhgySxP34zKVCcaWdg6Di1f9EA ePtQCGqQw5Fb7cZ1/BxfAZrUfwsghH4xO6j5nKUKg6FYNgC44Z7i7XU5RSX/YENJnoAc 98VYKIRGZkEHvqnz9IACEPmmcto1FNUOiXuHHANbDuJzaMv1T89Xqdqv/KTFpbin8Qie 13+LM+JbljsbDoszyJvCI/JsUFUC86fulogCVWaaR2PN0EQ9j7oFAYLw7r79lK8GQA9p YASA== X-Gm-Message-State: AOAM532BeLWFiK11bkvdd59nuuDOMKJa0qcCGRIpW089Iz6j14oLe/gY 5n7bN8rma6pP3dNBH5GdMlUo46p7tTY= X-Google-Smtp-Source: ABdhPJwJq0/bkmniHPvCk/hgQXjU+w8Si4L1MDd+qNlIRgErlpf7TbIF3aWRpHDDvCHW0CITmQs75Q== X-Received: by 2002:a4a:5547:: with SMTP id e68mr10429271oob.49.1602276840117; Fri, 09 Oct 2020 13:54:00 -0700 (PDT) Received: from CptOrmolo.darkstar (cpe-70-113-147-195.tx.res.rr.com. [70.113.147.195]) by smtp.gmail.com with ESMTPSA id t2sm7572310oie.26.2020.10.09.13.53.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:53:59 -0700 (PDT) Date: Fri, 9 Oct 2020 15:53:57 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: Re: [patch] Avoid race in zf_mkdir Message-ID: <20201009205357.GA6449@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org References: <20201009200737.GA78914@CptOrmolo.darkstar> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 47440 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Fri, Oct 09, 2020 at 01:47:49PM -0700, Bart Schaefer wrote: > On Fri, Oct 9, 2020 at 1:35 PM Roman Perepelitsa < > roman.perepelitsa@gmail.com> wrote: > > > On Fri, Oct 9, 2020 at 10:25 PM Bart Schaefer > > wrote: > > > > > > Er, sorry, this doesn't actually avoid the race, it just prevents the > > error message from being shown by whichever shell loses the race. > > > > I think this is the expected behavior. It's prescribed by POSIX for mkdir. > > > [...] > > > > > The patch is incorrect for a different reason. If `zf_mkdir -p foo` is > > racing with another process that's doing `mkdir foo && rmdir foo`, the > > zf_mkdir call must never fail but with this patch it can fail. > > > > Hm ... in that case the code shouldn't call stat() unless the mkdir() gives > EEXIST? And then ignore ENOENT from stat()? > > What if another process is doing "touch foo && rm foo"? How is it possible > to distinguish that from mkdir+rmdir ? > > Or are we confusing the requirements for mkdir(2) from those for mkdir(1) > ? I don't have the spec handy. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html I suppose we could stat before and after if after mkdir errno = EEXIST.