Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples: pktgen: fix append mode failed issue

Each sample script sources functions.sh before parameters.sh
which makes $APPEND undefined when trapping EXIT no matter in
append mode or not. Due to this when sample scripts finished
they always do "pgctrl reset" which resets pktgen config.

So move trap to each script after sourcing parameters.sh
and trap EXIT explicitly.

Signed-off-by: J.J. Martzki <mars14850@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

J.J. Martzki and committed by
David S. Miller
a27ac539 f56d1eea

+37 -6
+7 -6
samples/pktgen/functions.sh
··· 108 108 fi 109 109 } 110 110 111 - if [[ -z "$APPEND" ]]; then 112 - if [[ $EUID -eq 0 ]]; then 113 - # Cleanup pktgen setup on exit if thats not "append mode" 114 - trap 'pg_ctrl "reset"' EXIT 115 - fi 116 - fi 111 + function trap_exit() 112 + { 113 + # Cleanup pktgen setup on exit if thats not "append mode" 114 + if [[ -z "$APPEND" ]] && [[ $EUID -eq 0 ]]; then 115 + trap 'pg_ctrl "reset"' EXIT 116 + fi 117 + } 117 118 118 119 ## -- General shell tricks -- 119 120
+4
samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
··· 33 33 34 34 # Parameter parsing via include 35 35 source ${basedir}/parameters.sh 36 + 37 + # Trap EXIT first 38 + trap_exit 39 + 36 40 # Using invalid DST_MAC will cause the packets to get dropped in 37 41 # ip_rcv() which is part of the test 38 42 if [ -z "$DEST_IP" ]; then
+4
samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh
··· 14 14 15 15 # Parameter parsing via include 16 16 source ${basedir}/parameters.sh 17 + 18 + # Trap EXIT first 19 + trap_exit 20 + 17 21 if [ -z "$DEST_IP" ]; then 18 22 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1" 19 23 fi
+4
samples/pktgen/pktgen_sample01_simple.sh
··· 13 13 # - go look in parameters.sh to see which setting are avail 14 14 # - required param is the interface "-i" stored in $DEV 15 15 source ${basedir}/parameters.sh 16 + 17 + # Trap EXIT first 18 + trap_exit 19 + 16 20 # 17 21 # Set some default params, if they didn't get set 18 22 if [ -z "$DEST_IP" ]; then
+3
samples/pktgen/pktgen_sample02_multiqueue.sh
··· 14 14 # Required param: -i dev in $DEV 15 15 source ${basedir}/parameters.sh 16 16 17 + # Trap EXIT first 18 + trap_exit 19 + 17 20 [ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely 18 21 19 22 # Base Config
+4
samples/pktgen/pktgen_sample03_burst_single_flow.sh
··· 25 25 26 26 # Parameter parsing via include 27 27 source ${basedir}/parameters.sh 28 + 29 + # Trap EXIT first 30 + trap_exit 31 + 28 32 # Set some default params, if they didn't get set 29 33 if [ -z "$DEST_IP" ]; then 30 34 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
+4
samples/pktgen/pktgen_sample04_many_flows.sh
··· 12 12 13 13 # Parameter parsing via include 14 14 source ${basedir}/parameters.sh 15 + 16 + # Trap EXIT first 17 + trap_exit 18 + 15 19 # Set some default params, if they didn't get set 16 20 if [ -z "$DEST_IP" ]; then 17 21 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
+4
samples/pktgen/pktgen_sample05_flow_per_thread.sh
··· 16 16 17 17 # Parameter parsing via include 18 18 source ${basedir}/parameters.sh 19 + 20 + # Trap EXIT first 21 + trap_exit 22 + 19 23 # Set some default params, if they didn't get set 20 24 if [ -z "$DEST_IP" ]; then 21 25 [ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
+3
samples/pktgen/pktgen_sample06_numa_awared_queue_irq_affinity.sh
··· 14 14 # Required param: -i dev in $DEV 15 15 source ${basedir}/parameters.sh 16 16 17 + # Trap EXIT first 18 + trap_exit 19 + 17 20 # Base Config 18 21 [ -z "$COUNT" ] && COUNT="20000000" # Zero means indefinitely 19 22 [ -z "$CLONE_SKB" ] && CLONE_SKB="0"