* [PATCH V2] tools: rcu: Added check for argument and usage function
@ 2023-01-10 11:16 Bhaskar Chowdhury
2023-01-10 17:39 ` Paul E. McKenney
0 siblings, 1 reply; 2+ messages in thread
From: Bhaskar Chowdhury @ 2023-01-10 11:16 UTC (permalink / raw)
To: unixbhaskar, linux-kernel; +Cc: paulmck
Thought it would be good to have some formatted way of letting user know
about, how to use this script properly and added some checking too for missing
argument.
cc: paulmck@kernel.org
Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
Changes from V1 : Flip the code blocks of function for logical evaluation
and strip off the path from script when displaying help
| 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
--git a/tools/rcu/extract-stall.sh b/tools/rcu/extract-stall.sh
index e565697c9f90..6ea76230f72f 100644
--- a/tools/rcu/extract-stall.sh
+++ b/tools/rcu/extract-stall.sh
@@ -1,11 +1,24 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0+
#
-# Extract any RCU CPU stall warnings present in specified file.
-# Filter out clocksource lines. Note that preceding-lines excludes the
-# initial line of the stall warning but trailing-lines includes it.
-#
-# Usage: extract-stall.sh dmesg-file [ preceding-lines [ trailing-lines ] ]
+# This is a usage function to spit out information about properly use this
+# script
+
+usage() {
+
+ echo Extract any RCU CPU stall warnings present in specified file.
+ echo Filter out clocksource lines. Note that preceding-lines excludes the
+ echo initial line of the stall warning but trailing-lines includes it.
+
+ echo Usage: $(basename $0) dmesg-file [ preceding-lines [ trailing-lines ] ]
+}
+
+# Terminate the script, if the argument is missing
+
+if [ $# -eq 0 ];then
+ usage
+ exit 1
+fi
echo $1
preceding_lines="${2-3}"
--
2.38.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH V2] tools: rcu: Added check for argument and usage function
2023-01-10 11:16 [PATCH V2] tools: rcu: Added check for argument and usage function Bhaskar Chowdhury
@ 2023-01-10 17:39 ` Paul E. McKenney
0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2023-01-10 17:39 UTC (permalink / raw)
To: Bhaskar Chowdhury; +Cc: linux-kernel
On Tue, Jan 10, 2023 at 04:46:34PM +0530, Bhaskar Chowdhury wrote:
> Thought it would be good to have some formatted way of letting user know
> about, how to use this script properly and added some checking too for missing
> argument.
>
>
> cc: paulmck@kernel.org
>
> Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
Good point on making a usage() function that stands in for the header
comment, thank you! I tweaked this a bit as shown below, so please
check to see if I messed anything up.
Thanx, Paul
------------------------------------------------------------------------
commit f4e5cfbdfe900a41375d68b6c83e438ecc519b7b
Author: Bhaskar Chowdhury <unixbhaskar@gmail.com>
Date: Tue Jan 10 16:46:34 2023 +0530
tools: rcu: Add usage function and check for argument
This commit converts extract-stall.sh script's header comment to a
usage() function, and adds an argument check. While in the area, make
this script be executable.
[ paulmck: Strength argument check, remove extraneous comment. ]
Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
diff --git a/tools/rcu/extract-stall.sh b/tools/rcu/extract-stall.sh
old mode 100644
new mode 100755
index e565697c9f90e..08a39ad44320d
--- a/tools/rcu/extract-stall.sh
+++ b/tools/rcu/extract-stall.sh
@@ -1,11 +1,25 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0+
-#
-# Extract any RCU CPU stall warnings present in specified file.
-# Filter out clocksource lines. Note that preceding-lines excludes the
-# initial line of the stall warning but trailing-lines includes it.
-#
-# Usage: extract-stall.sh dmesg-file [ preceding-lines [ trailing-lines ] ]
+
+usage() {
+ echo Extract any RCU CPU stall warnings present in specified file.
+ echo Filter out clocksource lines. Note that preceding-lines excludes the
+ echo initial line of the stall warning but trailing-lines includes it.
+ echo
+ echo Usage: $(basename $0) dmesg-file [ preceding-lines [ trailing-lines ] ]
+ echo
+ echo Error: $1
+}
+
+# Terminate the script, if the argument is missing
+
+if test -f "$1" && test -r "$1"
+then
+ :
+else
+ usage "Console log file \"$1\" missing or unreadable."
+ exit 1
+fi
echo $1
preceding_lines="${2-3}"
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-10 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 11:16 [PATCH V2] tools: rcu: Added check for argument and usage function Bhaskar Chowdhury
2023-01-10 17:39 ` Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®