From patchwork Fri Mar 13 01:40:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 6001091 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 84CBC9F380 for ; Fri, 13 Mar 2015 01:42:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BAE5920351 for ; Fri, 13 Mar 2015 01:42:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4CCB2034F for ; Fri, 13 Mar 2015 01:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755413AbbCMBk5 (ORCPT ); Thu, 12 Mar 2015 21:40:57 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:52119 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754955AbbCMBky (ORCPT ); Thu, 12 Mar 2015 21:40:54 -0400 Received: from mfilter34-d.gandi.net (mfilter34-d.gandi.net [217.70.178.165]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 9FBCA172071; Fri, 13 Mar 2015 02:40:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter34-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter34-d.gandi.net (mfilter34-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id mK1mg8YlKHLr; Fri, 13 Mar 2015 02:40:51 +0100 (CET) X-Originating-IP: 50.43.43.179 Received: from jtriplet-mobl1 (static-50-43-43-179.bvtn.or.frontiernet.net [50.43.43.179]) (Authenticated sender: josh@joshtriplett.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 48C9C172077; Fri, 13 Mar 2015 02:40:47 +0100 (CET) Date: Thu, 12 Mar 2015 18:40:45 -0700 From: Josh Triplett To: Al Viro , Andrew Morton , Andy Lutomirski , Ingo Molnar , Kees Cook , Oleg Nesterov , "Paul E. McKenney" , "H. Peter Anvin" , Rik van Riel , Thomas Gleixner , Thiago Macieira , Michael Kerrisk , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, x86@kernel.org Subject: [PATCH 4/6] signal: Factor out a helper function to process task_struct exit_code Message-ID: <8a32364b6abda58bd85e08e0e671e3bfb14d489c.1426180120.git.josh@joshtriplett.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP do_notify_parent includes the code to convert the exit_code field of struct task_struct to the code and status fields that accompany SIGCHLD. Factor that out into a new helper function task_exit_code_status, to allow other methods of task exit notification to share that code. Signed-off-by: Josh Triplett Signed-off-by: Thiago Macieira --- include/linux/sched.h | 1 + kernel/signal.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 9ec36fd..668c58f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2386,6 +2386,7 @@ extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *, extern int kill_pgrp(struct pid *pid, int sig, int priv); extern int kill_pid(struct pid *pid, int sig, int priv); extern int kill_proc_info(int, struct siginfo *, pid_t); +extern void task_exit_code_status(int exit_code, s32 *code, s32 *status); extern __must_check bool do_notify_parent(struct task_struct *, int); extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); extern void force_sig(int, struct task_struct *); diff --git a/kernel/signal.c b/kernel/signal.c index a390499..f959d07 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1613,6 +1613,20 @@ ret: return ret; } +/* Translate exit_code to code and status. */ +void task_exit_code_status(int exit_code, s32 *code, s32 *status) +{ + *status = exit_code & 0x7f; + if (exit_code & 0x80) + *code = CLD_DUMPED; + else if (exit_code & 0x7f) + *code = CLD_KILLED; + else { + *code = CLD_EXITED; + *status = exit_code >> 8; + } +} + /* * Let a parent know about the death of a child. * For a stopped/continued status change, use do_notify_parent_cldstop instead. @@ -1668,15 +1682,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig) info.si_utime = cputime_to_clock_t(utime + tsk->signal->utime); info.si_stime = cputime_to_clock_t(stime + tsk->signal->stime); - info.si_status = tsk->exit_code & 0x7f; - if (tsk->exit_code & 0x80) - info.si_code = CLD_DUMPED; - else if (tsk->exit_code & 0x7f) - info.si_code = CLD_KILLED; - else { - info.si_code = CLD_EXITED; - info.si_status = tsk->exit_code >> 8; - } + task_exit_code_status(tsk->exit_code, &info.si_code, &info.si_status); psig = tsk->parent->sighand; spin_lock_irqsave(&psig->siglock, flags);