Commit 3cad8f91 authored by Daniel T. Lee's avatar Daniel T. Lee Committed by David S. Miller

samples: pktgen: fix proc_cmd command result check logic

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: default avatarDaniel T. Lee <danieltimlee@gmail.com>
Acked-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 723d2904
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Author: Jesper Dangaaard Brouer # Author: Jesper Dangaaard Brouer
# License: GPL # License: GPL
set -o errexit
## -- General shell logging cmds -- ## -- General shell logging cmds --
function err() { function err() {
local exitcode=$1 local exitcode=$1
...@@ -58,6 +60,7 @@ function pg_set() { ...@@ -58,6 +60,7 @@ function pg_set() {
function proc_cmd() { function proc_cmd() {
local result local result
local proc_file=$1 local proc_file=$1
local status=0
# after shift, the remaining args are contained in $@ # after shift, the remaining args are contained in $@
shift shift
local proc_ctrl=${PROC_DIR}/$proc_file local proc_ctrl=${PROC_DIR}/$proc_file
...@@ -73,14 +76,14 @@ function proc_cmd() { ...@@ -73,14 +76,14 @@ function proc_cmd() {
echo "cmd: $@ > $proc_ctrl" echo "cmd: $@ > $proc_ctrl"
fi fi
# Quoting of "$@" is important for space expansion # Quoting of "$@" is important for space expansion
echo "$@" > "$proc_ctrl" echo "$@" > "$proc_ctrl" || status=$?
local status=$?
result=$(grep "Result: OK:" $proc_ctrl) if [[ "$proc_file" != "pgctrl" ]]; then
# Due to pgctrl, cannot use exit code $? from grep result=$(grep "Result: OK:" $proc_ctrl) || true
if [[ "$result" == "" ]]; then if [[ "$result" == "" ]]; then
grep "Result:" $proc_ctrl >&2 grep "Result:" $proc_ctrl >&2
fi fi
fi
if (( $status != 0 )); then if (( $status != 0 )); then
err 5 "Write error($status) occurred cmd: \"$@ > $proc_ctrl\"" err 5 "Write error($status) occurred cmd: \"$@ > $proc_ctrl\""
fi fi
...@@ -105,6 +108,8 @@ function pgset() { ...@@ -105,6 +108,8 @@ function pgset() {
fi fi
} }
[[ $EUID -eq 0 ]] && trap 'pg_ctrl "reset"' EXIT
## -- General shell tricks -- ## -- General shell tricks --
function root_check_run_with_sudo() { function root_check_run_with_sudo() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment