From patchwork Mon Jun 6 14:45:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 9158455 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D95160759 for ; Mon, 6 Jun 2016 14:45:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EEC826E5D for ; Mon, 6 Jun 2016 14:45:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03BDE2821F; Mon, 6 Jun 2016 14:45:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4020326E5D for ; Mon, 6 Jun 2016 14:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbcFFOpf (ORCPT ); Mon, 6 Jun 2016 10:45:35 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:56076 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753035AbcFFOpd (ORCPT ); Mon, 6 Jun 2016 10:45:33 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1b9vmU-0003kO-C3; Tue, 07 Jun 2016 00:45:30 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1b9vmS-0006A2-1W; Mon, 06 Jun 2016 22:45:28 +0800 Date: Mon, 6 Jun 2016 22:45:27 +0800 From: Herbert Xu To: Stephen Kitt Cc: dash@vger.kernel.org Subject: [PATCH v2] jobs: Handle string-based job descriptors Message-ID: <20160606144527.GA23630@gondor.apana.org.au> References: <1464940471-9819-1-git-send-email-steve@sk2.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1464940471-9819-1-git-send-email-steve@sk2.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Jun 03, 2016 at 09:54:31AM +0200, Stephen Kitt wrote: > When looking for a job using a string descriptor, e.g. > > fg %man > > the relevant loop in src/jobs.c only ever exits to the err label. With > this patch, when the end condition is reached, we check whether a job > was found, and if so, set things up to exit correctly via gotit. > Multiple matches are already caught using the test in the match block. > > Signed-off-by: Stephen Kitt Thanks for the patch. I'd prefer to move that logic out of the loop, like this: ---8<--- From: Stephen Kitt When looking for a job using a string descriptor, e.g. fg %man the relevant loop in src/jobs.c only ever exits to the err label. With this patch, when the end condition is reached, we check whether a job was found, and if so, set things up to exit correctly via gotit. Multiple matches are already caught using the test in the match block. Signed-off-by: Stephen Kitt Signed-off-by: Herbert Xu diff --git a/src/jobs.c b/src/jobs.c index 3997863..4f02e38 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -714,9 +714,7 @@ check: } found = 0; - while (1) { - if (!jp) - goto err; + while (jp) { if (match(jp->ps[0].cmd, p)) { if (found) goto err; @@ -726,6 +724,10 @@ check: jp = jp->prev_job; } + if (!found) + goto err; + jp = found; + gotit: #if JOBS err_msg = "job %s not created under job control";