From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932816AbbCPXZw (ORCPT ); Mon, 16 Mar 2015 19:25:52 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:53961 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932108AbbCPXZt (ORCPT ); Mon, 16 Mar 2015 19:25:49 -0400 Date: Mon, 16 Mar 2015 16:25:41 -0700 From: josh@joshtriplett.org To: Kees Cook Cc: Al Viro , Andrew Morton , Andy Lutomirski , Ingo Molnar , Oleg Nesterov , "Paul E. McKenney" , "H. Peter Anvin" , Rik van Riel , Thomas Gleixner , Michael Kerrisk , Thiago Macieira , LKML , Linux API , "linux-fsdevel@vger.kernel.org" , "x86@kernel.org" Subject: Re: [PATCH v2 0/7] CLONE_FD: Task exit notification via file descriptor Message-ID: <20150316232541.GA31751@cloud> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 16, 2015 at 02:44:20PM -0700, Kees Cook wrote: > On Sun, Mar 15, 2015 at 12:59 AM, Josh Triplett wrote: > > - Make poll on a CLONE_FD for an exited task also return POLLHUP, for > > compatibility with FreeBSD's pdfork. Thanks to David Drysdale for calling > > attention to pdfork. > > I think POLLHUP should be mentioned in the manpage (now it only > mentions POLLIN). Added for v3. > > CLONE_FD > > Return a file descriptor associated with the new process, stor‐ > > ing it in location clonefd in the parent's address space. When > > the new process exits, the file descriptor will become available > > for reading. > > > > Unlike using signalfd(2) for the SIGCHLD signal, the file > > descriptor returned by clone4() with the CLONE_FD flag works > > even with SIGCHLD unblocked in one or more threads of the parent > > process, allowing the process to have different handlers for > > different child processes, such as those created by a library, > > without introducing race conditions around process-wide signal > > handling. > > > > clonefd_flags may contain the following additional flags for use > > with CLONE_FD: > > > > > > O_CLOEXEC > > Set the close-on-exec flag on the new file descriptor. > > See the description of the O_CLOEXEC flag in open(2) for > > reasons why this may be useful. > > This begs the question: what happens when all CLONE_FD fds for a > process are closed? Will the parent get SIGCHLD instead, will it > auto-reap, or will it be un-wait-able (I assume not this...) Whether the parent gets SIGCHLD is determined only by what signal you request in clone; if you clone with CLONE_FD | SIGCHLD (or CLONE_AUTOREAP | CLONE_FD | SIGCHLD), you'll get notification via both clonefd (if you have one) and signal (if you have a handler). If you pass a 0 signal (just CLONE_FD or CLONE_AUTOREAP | CLONE_FD), you'll receive no signal, only the notification via clonefd. Independently, if you have CLONE_AUTOREAP set, the process will autoreap. Those are all orthogonal now. If you close the clonefd, nothing special happens other than a put_task_struct. While this is conceptually somewhat like a pipe, the data is actually generated at read time, so the task exit doesn't care whether there's a live clonefd or not. (Or, in the future, if there are multiple live clonefds for the same process.) > Looks promising! Thanks! And thanks for catching the manpage issue. I'd definitely welcome any comments you have on the implementation as well. - Josh Triplett