[v3] usertools/dpdk-setup.sh: fix dpdk-setup's behaviour on non-alphanumeric inputs
Checks
Commit Message
Combine https://patches.dpdk.org/patch/67855/ with v2 of this patch to fix
the overall behaviour of dpdk-setup.sh on non-alphanumeric inputs.
Instead of crashing the script will prompt the user to re-enter the input
in case of non-alphanumberic input.
Bugzilla ID: 419
Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com> Muhammad Bilal <m.bilal@emumba.com>
---
usertools/dpdk-setup.sh | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
+ echo "Please enter a numeric value"
+ fi
+
if [ "$QUIT" == "0" ] ; then
echo
@@ -320,14 +320,18 @@ set_non_numa_pages()
echo " enter '64' to reserve 64 * 2MB pages"
echo -n "Number of pages: "
read Pages
+ numeric="^[[:digit:]]+$"
+ PG_PATH="/sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}"
+ if [[ $Pages =~ $numeric ]]; then
+ echo "echo $Pages > $PG_PATH/nr_hugepages" > .echo_tmp
+ echo "Reserving hugepages"
+ sudo sh .echo_tmp
+ rm -f .echo_tmp
+ create_mnt_huge
+ else
+ echo "Please enter a numeric value"
+ fi
- echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
-
- echo "Reserving hugepages"
- sudo sh .echo_tmp
- rm -f .echo_tmp
-
- create_mnt_huge
}
#
@@ -343,10 +347,16 @@ set_numa_pages()
echo " enter '64' to reserve 64 * 2MB pages on each node"
echo > .echo_tmp
+ numeric="^[[:digit:]]+$"
for d in /sys/devices/system/node/node? ; do
node=$(basename $d)
echo -n "Number of pages for $node: "
read Pages
+ while [[ ! "$Pages" =~ $numeric ]]; do
+ echo "Please enter a numeric value"
+ echo -n "Number of pages for $node: "
+ read Pages
+ done
echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
done
echo "Reserving hugepages"
@@ -595,7 +605,11 @@ while [ "$QUIT" == "0" ]; do
echo -n "Option: "
read our_entry
echo ""
- echo -n "Option: "
- read our_entry
+ read -p "Option: " our_entry
+ [ $? -eq 0 ] || exit 0
+
echo ""
- ${OPTIONS[our_entry]} ${our_entry}
-
+ numeric="^[[:digit:]]+$"
+ if [[ "$our_entry" =~ $numeric ]]; then
+ ${OPTIONS[our_entry]} ${our_entry}
+ else