From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CE58C3A5A6 for ; Mon, 23 Sep 2019 14:23:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37AD9207FD for ; Mon, 23 Sep 2019 14:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437828AbfIWOXs (ORCPT ); Mon, 23 Sep 2019 10:23:48 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:40997 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437634AbfIWOXs (ORCPT ); Mon, 23 Sep 2019 10:23:48 -0400 Received: from [172.58.27.190] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iCPFc-0000sx-O6; Mon, 23 Sep 2019 14:23:41 +0000 Date: Mon, 23 Sep 2019 16:23:27 +0200 From: Christian Brauner To: Florian Weimer Cc: "Michael Kerrisk (man-pages)" , Oleg Nesterov , Christian Brauner , Jann Horn , "Eric W. Biederman" , Daniel Colascione , Joel Fernandes , linux-man , Linux API , lkml Subject: Re: For review: pidfd_send_signal(2) manual page Message-ID: <20190923142325.jowzbnwjw7g7si7j@wittgenstein> References: <87pnjr9rth.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87pnjr9rth.fsf@mid.deneb.enyo.de> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 23, 2019 at 01:26:34PM +0200, Florian Weimer wrote: > * Michael Kerrisk: > > > SYNOPSIS > > int pidfd_send_signal(int pidfd, int sig, siginfo_t info, > > unsigned int flags); > > This probably should reference a header for siginfo_t. Agreed. > > > ESRCH The target process does not exist. > > If the descriptor is valid, does this mean the process has been waited > for? Maybe this can be made more explicit. If by valid you mean "refers to a process/thread-group leader" aka is a pidfd then yes: Getting ESRCH means that the process has exited and has already been waited upon. If it had only exited but not waited upon aka is a zombie, then sending a signal will just work because that's currently how sending signals to zombies works, i.e. if you only send a signal and don't do any additional checks you won't notice a difference between a process being alive and a process being a zombie. The userspace visible behavior in terms of signaling them is identical. > > > The pidfd_send_signal() system call allows the avoidance of race > > conditions that occur when using traditional interfaces (such as > > kill(2)) to signal a process. The problem is that the traditional > > interfaces specify the target process via a process ID (PID), with > > the result that the sender may accidentally send a signal to the > > wrong process if the originally intended target process has termi‐ > > nated and its PID has been recycled for another process. By con‐ > > trast, a PID file descriptor is a stable reference to a specific > > process; if that process terminates, then the file descriptor > > ceases to be valid and the caller of pidfd_send_signal() is > > informed of this fact via an ESRCH error. > > It would be nice to explain somewhere how you can avoid the race using > a PID descriptor. Is there anything else besides CLONE_PIDFD? If you're the parent of the process you can do this without CLONE_PIDFD: pid = fork(); pidfd = pidfd_open(); ret = pidfd_send_signal(pidfd, 0, NULL, 0); if (ret < 0 && errno == ESRCH) /* pidfd refers to another, recycled process */ > > > static > > int pidfd_send_signal(int pidfd, int sig, siginfo_t *info, > > unsigned int flags) > > { > > return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags); > > } > > Please use a different function name. Thanks.