]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - tools/checkusage.sh
3 ## This script is potentially dangerous! Don't run it on
8 if [ "$#" -lt 1 ]; then
9 echo "usage: $0 program..." >&2
10 echo " or try 'make checkusage' to check all built programs" >&2
15 cmds
=$
(echo $@ |
tr ' ' '\n' |
sort)
17 # set env to dump all output to files
18 test -z "$CU_DUMP" ||
rm -f /tmp
/checkusage--
{help,version
,unknownopt
}
20 ## Set alternative options for --help, --version
21 ## or --unknownopt. "x" means "not implemented".
24 ## alt_whereis__help="-h" # in past whereis(1) had no longopt for --help
25 ## alt_more__help="x" # more(1) had neither --help nor -h
27 alt_fsck__unknownopt
="x" # fsck passes unknown opts to fsck.ext4, etc.
28 alt_mkfs__unknownopt
="x" # dito
29 alt_kill__unknownopt
="inval pids" # trick, kill does not use errtryhelp()
30 if [ $
(id
-ru) -eq 0 ]; then
31 alt_sulogin__unknownopt
="x" # would hang at pwd prompt
34 function exec_option
{
38 local tofile
="/tmp/checkusage$opt"
40 local alt
="alt_${cmdb}${opt}"
43 alt
=$
(eval printf -- \"\$
${alt}\")
44 if test -n "$alt"; then
45 if test "$alt" = "x"; then
51 test -z "$CU_DUMP" ||
{
52 echo "##########################################################"
57 out
=$
("$cmd" $opt 2>/dev
/null
)
58 err
=$
("$cmd" $opt 2>&1 >/dev
/null
)
61 # hardcoded ... nologin should always return false
62 if test "$cmdb" = "nologin" &&
63 test "$opt" = "--help" -o "$opt" = "--version"; then
64 if test "$ret" = "0"; then
65 echo "$cmdb, $opt, should return false"
78 if ! exec_option
"$cb" "$c" --help; then
82 if test $ret != 0; then
83 echo "$cb: $opt, returns error"
85 if test -z "$out"; then
86 echo "$cb: $opt, no stdout"
88 if test -n "$err"; then
89 echo "$cb: $opt, non-empty stderr"
95 function check_version
{
99 if ! exec_option
"$cb" "$c" --version; then
103 if test $ret != 0; then
104 echo "$cb: $opt, returns error"
106 if test -z "$out"; then
107 echo "$cb: $opt, no stdout"
109 if test -n "$err"; then
110 echo "$cb: $opt, non-empty stderr"
115 function check_unknownopt
{
120 if ! exec_option
"$cb" "$c" --unknownopt; then
124 if test $ret = 0; then
125 echo "$cb: $opt, returns no error"
127 if test -n "$out"; then
128 echo "$cb: $opt, non-empty stdout"
130 if test -z "$err"; then
131 echo "$cb: $opt, no stderr"
132 elif test -z "$nohelp" -o "$nohelp" != "yes"; then
133 out_len
=$
(echo "$out" |
wc -l)
134 err_len
=$
(echo "$err" |
wc -l)
135 if test "$err_len" -gt 2; then
136 echo "$cb: $opt, stderr too long: $err_len"
137 elif test "$err_len" -lt 2; then
138 echo "$cb: $opt, stderr too short: $err_len"
145 if ! type "$c" &>/dev
/null
; then
146 echo "$cb: does not exist"
151 if ! check_help
"$cb" "$c"; then
154 check_version
"$cb" "$c"
155 check_unknownopt
"$cb" "$c" "$nohelp"