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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 60411C47404 for ; Mon, 7 Oct 2019 13:21:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A8802084D for ; Mon, 7 Oct 2019 13:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728572AbfJGNVs (ORCPT ); Mon, 7 Oct 2019 09:21:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24004 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbfJGNVT (ORCPT ); Mon, 7 Oct 2019 09:21:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06CE610DCC8E; Mon, 7 Oct 2019 13:21:19 +0000 (UTC) Received: from carbon (ovpn-200-24.brq.redhat.com [10.40.200.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id E79769CAA; Mon, 7 Oct 2019 13:20:59 +0000 (UTC) Date: Mon, 7 Oct 2019 15:20:58 +0200 From: Jesper Dangaard Brouer To: "Daniel T. Lee" Cc: Toke =?UTF-8?B?SMO4aWxhbmQtSsO4cmdlbnNlbg==?= , "David S . Miller" , netdev , brouer@redhat.com Subject: Re: [PATCH net-next v5 2/4] samples: pktgen: fix proc_cmd command result check logic Message-ID: <20191007152058.3571dd60@carbon> In-Reply-To: References: <20191005082509.16137-1-danieltimlee@gmail.com> <20191005082509.16137-3-danieltimlee@gmail.com> <20191007101537.24c1961c@carbon> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 07 Oct 2019 13:21:19 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, 7 Oct 2019 20:37:31 +0900 "Daniel T. Lee" wrote: > On Mon, Oct 7, 2019 at 5:15 PM Jesper Dangaard Brouer wrote: > > > > On Sat, 5 Oct 2019 17:25:07 +0900 > > "Daniel T. Lee" wrote: > > > > > Currently, proc_cmd is used to dispatch command to 'pg_ctrl', 'pg_thread', > > > 'pg_set'. proc_cmd is designed to check command result with grep the > > > "Result:", but this might fail since this string is only shown in > > > 'pg_thread' and 'pg_set'. > > > > > > This commit fixes this logic by grep-ing the "Result:" string only when > > > the command is not for 'pg_ctrl'. > > > > > > For clarity of an execution flow, 'errexit' flag has been set. > > > > > > To cleanup pktgen on exit, trap has been added for EXIT signal. > > > > > > Signed-off-by: Daniel T. Lee > > > --- > > > > Acked-by: Jesper Dangaard Brouer > > > > > Changes since v5: > > > * when script runs sudo, run 'pg_ctrl "reset"' on EXIT with trap > > > > > > samples/pktgen/functions.sh | 17 +++++++++++------ > > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > > > diff --git a/samples/pktgen/functions.sh b/samples/pktgen/functions.sh > > > index 4af4046d71be..40873a5d1461 100644 > > > --- a/samples/pktgen/functions.sh > > > +++ b/samples/pktgen/functions.sh > > > @@ -5,6 +5,8 @@ > > > # Author: Jesper Dangaaard Brouer > > > # License: GPL > > > > > > +set -o errexit > > > + > > > ## -- General shell logging cmds -- > > > function err() { > > > local exitcode=$1 > > > @@ -58,6 +60,7 @@ function pg_set() { > > > function proc_cmd() { > > > local result > > > local proc_file=$1 > > > + local status=0 > > > # after shift, the remaining args are contained in $@ > > > shift > > > local proc_ctrl=${PROC_DIR}/$proc_file > > > @@ -73,13 +76,13 @@ function proc_cmd() { > > > echo "cmd: $@ > $proc_ctrl" > > > fi > > > # Quoting of "$@" is important for space expansion > > > - echo "$@" > "$proc_ctrl" > > > - local status=$? > > > + echo "$@" > "$proc_ctrl" || status=$? > > > > > > - result=$(grep "Result: OK:" $proc_ctrl) > > > - # Due to pgctrl, cannot use exit code $? from grep > > > - if [[ "$result" == "" ]]; then > > > - grep "Result:" $proc_ctrl >&2 > > > + if [[ "$proc_file" != "pgctrl" ]]; then > > > + result=$(grep "Result: OK:" $proc_ctrl) || true > > > + if [[ "$result" == "" ]]; then > > > + grep "Result:" $proc_ctrl >&2 > > > + fi > > > fi > > > if (( $status != 0 )); then > > > err 5 "Write error($status) occurred cmd: \"$@ > $proc_ctrl\"" > > > @@ -105,6 +108,8 @@ function pgset() { > > > fi > > > } > > > > > > +[[ $EUID -eq 0 ]] && trap 'pg_ctrl "reset"' EXIT > > > + > > > > This is fine, but you could have placed the 'trap' handler in > > parameters.sh file, as all scripts first source functions.sh and then > > call root_check_run_with_sudo, before sourcing parameters.sh. > > > > Yes, this will work since 'parameters.sh' is only sourced when it is > on root, but I've thought this file only focuses on parsing parameters > not the general workflow of the pktgen script. > > So I thought 'functions.sh' is more suitable place to add trap rather > than 'paramters.sh'. > > What do you think? I agree. I'm fine with this approach. I've already ACK'ed the patch. -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer