Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp994406ybn; Wed, 25 Sep 2019 10:41:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7NtKyFIrYlzU82ZbhWdM4tXQkocbtGgjv2Z8wkmQpzMhXaJj0U/efMjJIJgExAy3l2OfK X-Received: by 2002:a17:906:e109:: with SMTP id gj9mr409235ejb.160.1569433284686; Wed, 25 Sep 2019 10:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569433284; cv=none; d=google.com; s=arc-20160816; b=e270hE1Y/13vLH9tK2HArWfY+rIw1n8Jm/D9AzlLi6wMUR9FTxn9nlBcyfymnA9+YW m2IME+a4StZ3nUjoHiY3kgLPkz99duT5DD2o0NFaF+VfzLPzDy6bi8lebbrV62jD5Hs2 GSafsXKDnvJdQTmxh9NBOc4XYU6MtH3q/UUBikBGVL3qp5789hc48LCbXWbr4S7wDO7r 7uzcyIdZ3z8furSLI8Lz74Ksmzp5n0Cw81Qa2btw4qx02Hw/E8lQ8EAHa7MA2Ghr5xQz UMZnGkaPmW/Tc8kgNPGKL8ceicZ9ENZcuRzBucVtV73Gi40FQKK07rBZ2QzM3mRev/Gi p6Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=75NSDDdf4+FFgkdmkKcm+3apWvZMTEu19vH3G9CRXW8=; b=C2dmySLzU0mnU4GIBubTgovay9zf9LRE3xwkFvjjM4jOLy+NWu9rnbbgL5qzVOA+sl Q3EwVLnC/Qa6bCaDBhxi+CtTNCRkBFLIrb7BYInjcWq2MowfyU4gUKsiYhTOlt3kvFR0 Lu2s9AXj7q3xe4EDOxWoEwyrpg8kDcFiVs2ZDktFvx4EEiD4cBdag9Iq5JbSDV6U2jcQ /+Qkg/1NYrs3TVOfl4juiXq2KarhCTcIEXqCDeJNnauO9PzBHLyaxgE6IO692OayqmVk io02Df0Z4KovHUxdTB4TA0WbFeYDRoXfX6y3CLWohqWhE8I1iVLoGFkDHEAUZJPzCmlT OIgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si116752ejc.310.2019.09.25.10.41.00; Wed, 25 Sep 2019 10:41:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437793AbfIWOXs (ORCPT + 99 others); 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.