From owner-freebsd-hackers@freebsd.org Wed Aug 26 02:06:37 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0DDBA3C5673 for ; Wed, 26 Aug 2020 02:06:37 +0000 (UTC) (envelope-from jdavidlists@gmail.com) Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bbq3c0hc2z4VfG for ; Wed, 26 Aug 2020 02:06:35 +0000 (UTC) (envelope-from jdavidlists@gmail.com) Received: by mail-lj1-x22c.google.com with SMTP id t23so526176ljc.3 for ; Tue, 25 Aug 2020 19:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=RplQGi0sogwSUHv5At0fMiuKxrZQXQHFvbFYJemSABY=; b=qx3InHHBdBR8EdtoUqDzVkr8hVmxhoWtOcu9rq8f6zjiODabbfLVX/cphyh1+Em6pY 3XJUWVvn9DQNuAVpVZ29UTUCgkyYncpu8jgcXJ4+KziSUaqPsE6Z6kn1WFa8Ka//6pBc OhBqpW78Q6DIQdSbp+GvVeQp1VcdF+0uqyKvx59penligVHBVp3gt33ikX3XM3gNgbeP y71dYfK7HZrOkkrAJM2Yz5ol7Vu6o+pBuwglDeaIfZ2RmY+t27Fl65EfkJckOy7ALER1 FwMH1ezqB46lV6r/Byu0m+FntbGp0Xgp0IzKFNXW4x52yd49PPb51lpc61ZXVgPhKZ75 DKcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=RplQGi0sogwSUHv5At0fMiuKxrZQXQHFvbFYJemSABY=; b=lQay42s+mSjtNs+RUhuKUG+cvjXgWKWY+gZYyCUZBt/lnb6jZnc6dzXvROPKK3rF6v 7YTWq9ZRMbXxagIGZyec7mimyYBWdbjOd4RYFhmp1xqYQyQK0f9WgXV2fnyGFMjTaRUG 6BmKROKoxBMAyRR7n3xdnKqfhnNE8UfybEq/c+lKAY6hjE55xLj+TfNQy1FHFzY+fdF8 ATnsxOy4JZkp93unR8l3hHrJ7GkaMmvE2ZYAkJeprisfN+LjJQfrGUKplByiD7gpp5cB 3jiBlp1yasuR/TBvySDfLA/XHFC2nO6C9Hzt7n+Xdj7P0QpMQIFXu92dePLe4W/HKS0s 0GJg== X-Gm-Message-State: AOAM5323DcIkUYjck1AT4S6ACPeHgAmM+zpUVhHI5+Bqb165rtZ7TMRG 0+GjGJWUUnayLsHvqWnfw3Ow4ZwzK6Pyim1zHowjiHtsySis1g== X-Google-Smtp-Source: ABdhPJy1qPBkqkJalFuswq6YQXpPnZU7kmxsZa2r3UZkSAcA8YnfBcKTG+FFz/9iVMlNdEzdNwUswTlo+SQx7BV4ASk= X-Received: by 2002:a2e:b045:: with SMTP id d5mr6457116ljl.111.1598407593638; Tue, 25 Aug 2020 19:06:33 -0700 (PDT) MIME-Version: 1.0 From: J David Date: Tue, 25 Aug 2020 22:06:22 -0400 Message-ID: Subject: pidfile_open() usage in "mount" To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4Bbq3c0hc2z4VfG X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=qx3InHHB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of jdavidlists@gmail.com designates 2a00:1450:4864:20::22c as permitted sender) smtp.mailfrom=jdavidlists@gmail.com X-Spamd-Result: default: False [-0.60 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.41)[-0.409]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::22c:from]; NEURAL_SPAM_SHORT(0.81)[0.813]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; TAGGED_FROM(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Aug 2020 02:06:37 -0000 It looks like the "mount" program creates /var/run/mountd.pid every time it runs, if mountd is not itself running. This code appears in sbin/mount/mount.c: static void restart_mountd(void) { struct pidfh *pfh; pid_t mountdpid; mountdpid = 0; pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid); if (pfh != NULL) { /* Mountd is not running. */ pidfile_remove(pfh); return; } pidfile_open(3) *creates* /var/run/mountd.pid if it doesn't already exist, hence the need to delete it if the call actually succeeds. This leads to a race condition when multiple mounts occur at the same time. That case is handled later in the code: /* * Refuse to send broadcast or group signals, this has * happened due to the bugs in pidfile(3). */ if (mountdpid <= 0) { warnx("mountd pid %d, refusing to send SIGHUP", mountdpid); return; } "mount" is not "mountd." It seems inappropriate for it to, under any circumstances, create mountd's pid file. The multiple workarounds for the problems that causes don't seem like the optimal approach. This is something I'd be willing to open a bug and submit a patch for, but so as not to do work that stands no chance of being accepted, I'd like to understand first if the preferred approach would be to change mount.c not to use pidfile library calls at all, or if it would be better to add a function to the pidfile library similar to pidfile_open() designed for "consumer" use that would never create the file, leaving pidfile_open() for "producer" use? Thanks!