netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: "Daniel T. Lee" <danieltimlee@gmail.com>
Cc: "Toke Høiland-Jørgensen" <toke@redhat.com>,
	"David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, brouer@redhat.com
Subject: Re: [PATCH net-next v5 2/4] samples: pktgen: fix proc_cmd command result check logic
Date: Mon, 7 Oct 2019 10:15:37 +0200	[thread overview]
Message-ID: <20191007101537.24c1961c@carbon> (raw)
In-Reply-To: <20191005082509.16137-3-danieltimlee@gmail.com>

On Sat,  5 Oct 2019 17:25:07 +0900
"Daniel T. Lee" <danieltimlee@gmail.com> 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 <danieltimlee@gmail.com>
> ---

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>

> 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.

>  ## -- General shell tricks --
>  
>  function root_check_run_with_sudo() {



-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

  reply	other threads:[~2019-10-07  8:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-05  8:25 [PATCH net-next v5 0/4] samples: pktgen: allow to specify destination IP range Daniel T. Lee
2019-10-05  8:25 ` [PATCH net-next v5 1/4] samples: pktgen: make variable consistent with option Daniel T. Lee
2019-10-07  7:33   ` Jesper Dangaard Brouer
2019-10-05  8:25 ` [PATCH net-next v5 2/4] samples: pktgen: fix proc_cmd command result check logic Daniel T. Lee
2019-10-07  8:15   ` Jesper Dangaard Brouer [this message]
2019-10-07 11:37     ` Daniel T. Lee
2019-10-07 13:20       ` Jesper Dangaard Brouer
2019-10-05  8:25 ` [PATCH net-next v5 3/4] samples: pktgen: add helper functions for IP(v4/v6) CIDR parsing Daniel T. Lee
2019-10-07  8:16   ` Jesper Dangaard Brouer
2019-10-05  8:25 ` [PATCH net-next v5 4/4] samples: pktgen: allow to specify destination IP range (CIDR) Daniel T. Lee
2019-10-07  8:19   ` Jesper Dangaard Brouer
2019-10-06 13:35 ` [PATCH net-next v5 0/4] samples: pktgen: allow to specify destination IP range David Miller
2019-10-07 13:26 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191007101537.24c1961c@carbon \
    --to=brouer@redhat.com \
    --cc=danieltimlee@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).