linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Daniel T. Lee" <danieltimlee@gmail.com>,
	Jesper Dangaard Brouer <brouer@redhat.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.4 17/71] samples: pktgen: fix proc_cmd command result check logic
Date: Tue, 10 Dec 2019 17:32:22 -0500	[thread overview]
Message-ID: <20191210223316.14988-17-sashal@kernel.org> (raw)
In-Reply-To: <20191210223316.14988-1-sashal@kernel.org>

From: "Daniel T. Lee" <danieltimlee@gmail.com>

[ Upstream commit 3cad8f911575191fb3b81d8ed0e061e30f922223 ]

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 205e4cde46012..065a7e296ee31 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
+
 ## -- General shell tricks --
 
 function root_check_run_with_sudo() {
-- 
2.20.1


  parent reply	other threads:[~2019-12-10 22:38 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 22:32 [PATCH AUTOSEL 4.4 01/71] drm: mst: Fix query_payload ack reply struct Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 02/71] iio: light: bh1750: Resolve compiler warning and make code more readable Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 03/71] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 04/71] spi: Add call to spi_slave_abort() function when spidev driver is released Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 05/71] staging: rtl8188eu: fix possible null dereference Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 06/71] rtlwifi: prevent memory leak in rtl_usb_probe Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 07/71] IB/iser: bound protection_sg size by data_sg size Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 08/71] media: am437x-vpfe: Setting STD to current value is not an error Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 09/71] media: i2c: ov2659: fix s_stream return value Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 10/71] media: i2c: ov2659: Fix missing 720p register config Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 11/71] media: ov6650: Fix stored frame format not in sync with hardware Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 12/71] tools/power/cpupower: Fix initializer override in hsw_ext_cstates Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 13/71] usb: renesas_usbhs: add suspend event support in gadget mode Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 14/71] hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not idled Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 15/71] regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 16/71] media: flexcop-usb: fix NULL-ptr deref in flexcop_usb_transfer_init() Sasha Levin
2019-12-10 22:32 ` Sasha Levin [this message]
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 18/71] iio: proximity: sx9500: fix iio_triggered_buffer_{predisable,postenable} positions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 19/71] mwifiex: pcie: Fix memory leak in mwifiex_pcie_init_evt_ring Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 20/71] media: ti-vpe: vpe: fix a v4l2-compliance warning about invalid pixel format Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 21/71] media: ti-vpe: vpe: fix a v4l2-compliance failure about frame sequence number Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 22/71] media: ti-vpe: vpe: Make sure YUYV is set as default format Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 23/71] extcon: sm5502: Reset registers during initialization Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 24/71] x86/mm: Use the correct function type for native_set_fixmap() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 25/71] perf report: Add warning when libunwind not compiled in Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 26/71] usb: usbfs: Suppress problematic bind and unbind uevents Sasha Levin
2019-12-11  7:47   ` Greg Kroah-Hartman
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 27/71] iio: adc: max1027: Reset the device at probe time Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 28/71] iio: dac: ad7303: replace mlock with own lock Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 29/71] Bluetooth: hci_core: fix init for HCI_USER_CHANNEL Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 30/71] drm/gma500: fix memory disclosures due to uninitialized bytes Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 31/71] x86/ioapic: Prevent inconsistent state when moving an interrupt Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 32/71] arm64: psci: Reduce the waiting time for cpu_psci_cpu_kill() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 33/71] ALSA: hda - Fix pending unsol events at shutdown Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 34/71] libata: Ensure ata_port probe has completed before detach Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 35/71] ata: sata_mv, avoid trigerrable BUG_ON Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 36/71] pinctrl: sh-pfc: sh7734: Fix duplicate TCLK1_B Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 37/71] bnx2x: Fix PF-VF communication over multi-cos queues Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 38/71] spi: img-spfi: fix potential double release Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 39/71] rtlwifi: fix memory leak in rtl92c_set_fw_rsvdpagepkt() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 40/71] perf probe: Fix to find range-only function instance Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 41/71] perf probe: Fix to list probe event with correct line number Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 42/71] perf probe: Walk function lines in lexical blocks Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 43/71] perf probe: Fix to probe an inline function which has no entry pc Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 44/71] perf probe: Fix to show ranges of variables in functions without entry_pc Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 45/71] perf probe: Fix to show inlined function callsite " Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 46/71] perf probe: Skip overlapped location on searching variables Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 47/71] perf probe: Return a better scope DIE if there is no best scope Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 48/71] perf probe: Fix to show calling lines of inlined functions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 49/71] perf probe: Skip end-of-sequence and non statement lines Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 50/71] perf probe: Filter out instances except for inlined subroutine and subprogram Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 51/71] ath10k: fix get invalid tx rate for Mesh metric Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 52/71] media: pvrusb2: Fix oops on tear-down when radio support is not present Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 53/71] media: si470x-i2c: add missed operations in remove Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 54/71] EDAC/ghes: Fix grain calculation Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 55/71] spi: pxa2xx: Add missed security checks Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 56/71] ASoC: rt5677: Mark reg RT5677_PWR_ANLG2 as volatile Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 57/71] net: bcmgenet: Add RGMII_RXID support Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 58/71] parport: load lowlevel driver if ports not found Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 59/71] cpufreq: Register drivers only after CPU devices have been registered Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 60/71] x86/crash: Add a forward declaration of struct kimage Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 61/71] RDMA/qib: Validate ->show()/store() callbacks before calling them Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 62/71] spi: tegra20-slink: add missed clk_unprepare Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 63/71] btrfs: don't prematurely free work in end_workqueue_fn() Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 64/71] iwlwifi: check kasprintf() return value Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 65/71] fbtft: Make sure string is NULL terminated Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 66/71] crypto: sun4i-ss - Fix 64-bit size_t warnings on sun4i-ss-hash.c Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 67/71] crypto: vmx - Avoid weird build failures Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 68/71] libtraceevent: Fix memory leakage in copy_filter_type Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 69/71] perf parse: Fix potential memory leak when handling tracepoint errors Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 70/71] perf intel-bts: Does not support AUX area sampling Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 71/71] net: phy: initialise phydev speed and duplex sanely Sasha Levin

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=20191210223316.14988-17-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=brouer@redhat.com \
    --cc=danieltimlee@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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).