diff options
author | Dave Brolley <brolley@redhat.com> | 2010-01-11 20:13:40 -0500 |
---|---|---|
committer | Dave Brolley <brolley@redhat.com> | 2010-01-11 20:13:40 -0500 |
commit | a0ace4915e5d963c28fa3b54f87afef34b82b6a5 (patch) | |
tree | 8498bb2c48473f92334e29eb7dcf7f9460b8ad8b | |
parent | 44f348171ea72bf8a195fd281a3226541468b65c (diff) | |
download | systemtap-steved-a0ace4915e5d963c28fa3b54f87afef34b82b6a5.tar.gz systemtap-steved-a0ace4915e5d963c28fa3b54f87afef34b82b6a5.tar.xz systemtap-steved-a0ace4915e5d963c28fa3b54f87afef34b82b6a5.zip |
Rework filtering of client options. Add testsuite.
-rw-r--r-- | main.cxx | 86 | ||||
-rw-r--r-- | session.h | 8 | ||||
-rw-r--r-- | testsuite/systemtap.server/client_args.exp | 102 | ||||
-rw-r--r-- | testsuite/systemtap.server/test.stp | 1 |
4 files changed, 130 insertions, 67 deletions
@@ -429,44 +429,6 @@ checkOptions (systemtap_session &s) cerr << "You can't specify -g and --unprivileged together." << endl; optionsConflict = true; } - if (s.stap_client) - { - if (s.stap_client_a) - { - cerr << "You can't specify -a and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_B) - { - cerr << "You can't specify -B and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_D) - { - cerr << "You can't specify -D and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_I) - { - cerr << "You can't specify -I and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_m) - { - cerr << "You can't specify -m and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_r) - { - cerr << "You can't specify -r and --unprivileged together." << endl; - optionsConflict = true; - } - if (s.stap_client_R) - { - cerr << "You can't specify -R and --unprivileged together." << endl; - optionsConflict = true; - } - } } if (!s.kernel_symtab_path.empty()) @@ -578,14 +540,8 @@ main (int argc, char * const argv []) s.load_only = false; s.skip_badvars = false; s.unprivileged = false; - s.stap_client = false; - s.stap_client_a = false; - s.stap_client_B = false; - s.stap_client_D = false; - s.stap_client_I = false; - s.stap_client_m = false; - s.stap_client_r = false; - s.stap_client_R = false; + bool client_options = false; + string client_options_disallowed; // Location of our signing certificate. // If we're root, use the database in SYSCONFDIR, otherwise @@ -668,7 +624,7 @@ main (int argc, char * const argv []) #define LONG_OPT_VERBOSE_PASS 5 #define LONG_OPT_SKIP_BADVARS 6 #define LONG_OPT_UNPRIVILEGED 7 -#define LONG_OPT_STAP_CLIENT 8 +#define LONG_OPT_CLIENT_OPTIONS 8 // NB: also see find_hash(), usage(), switch stmt below, stap.1 man page static struct option long_options[] = { { "kelf", 0, &long_opt, LONG_OPT_KELF }, @@ -678,7 +634,7 @@ main (int argc, char * const argv []) { "skip-badvars", 0, &long_opt, LONG_OPT_SKIP_BADVARS }, { "vp", 1, &long_opt, LONG_OPT_VERBOSE_PASS }, { "unprivileged", 0, &long_opt, LONG_OPT_UNPRIVILEGED }, - { "stap-client", 0, &long_opt, LONG_OPT_STAP_CLIENT }, + { "client-options", 0, &long_opt, LONG_OPT_CLIENT_OPTIONS }, { NULL, 0, NULL, 0 } }; int grc = getopt_long (argc, argv, "hVvtp:I:e:o:R:r:a:m:kgPc:x:D:bs:uqwl:d:L:FS:B:", @@ -719,7 +675,8 @@ main (int argc, char * const argv []) break; case 'I': - s.stap_client_I = s.stap_client; + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-I" : ", -I"; s.include_path.push_back (string (optarg)); break; @@ -754,12 +711,14 @@ main (int argc, char * const argv []) break; case 'R': - s.stap_client_R = s.stap_client; + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-R" : ", -R"; s.runtime_path = string (optarg); break; case 'm': - s.stap_client_m = s.stap_client; + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-m" : ", -m"; s.module_name = string (optarg); save_module = true; { @@ -806,13 +765,15 @@ main (int argc, char * const argv []) break; case 'r': - s.stap_client_r = s.stap_client; + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-r" : ", -r"; setup_kernel_release(s, optarg); break; case 'a': - s.stap_client_a = s.stap_client; - s.architecture = string(optarg); + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-a" : ", -a"; + s.architecture = string(optarg); break; case 'k': @@ -859,7 +820,8 @@ main (int argc, char * const argv []) break; case 'D': - s.stap_client_D = s.stap_client; + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-D" : ", -D"; s.macros.push_back (string (optarg)); break; @@ -898,8 +860,9 @@ main (int argc, char * const argv []) break; case 'B': - s.stap_client_B = s.stap_client; - s.kbuildflags.push_back (string (optarg)); + if (client_options) + client_options_disallowed += client_options_disallowed.empty () ? "-B" : ", -B"; + s.kbuildflags.push_back (string (optarg)); break; case 0: @@ -952,8 +915,8 @@ main (int argc, char * const argv []) case LONG_OPT_UNPRIVILEGED: s.unprivileged = true; break; - case LONG_OPT_STAP_CLIENT: - s.stap_client = true; + case LONG_OPT_CLIENT_OPTIONS: + client_options = true; break; default: cerr << "Internal error parsing command arguments." << endl; @@ -968,6 +931,11 @@ main (int argc, char * const argv []) } // Check for options conflicts. + if (client_options && s.unprivileged && ! client_options_disallowed.empty ()) + { + cerr << "You can't specify " << client_options_disallowed << " when --unprivileged is specified." << endl; + usage (s, 1); + } checkOptions (s); // Warn in case the target kernel release doesn't match the running one. @@ -117,14 +117,6 @@ struct systemtap_session bool need_uprobes; bool load_only; // flight recorder mode bool unprivileged; - bool stap_client; - bool stap_client_a; - bool stap_client_B; - bool stap_client_D; - bool stap_client_I; - bool stap_client_m; - bool stap_client_r; - bool stap_client_R; // NB: It is very important for all of the above (and below) fields // to be cleared in the systemtap_session ctor (elaborate.cxx) diff --git a/testsuite/systemtap.server/client_args.exp b/testsuite/systemtap.server/client_args.exp new file mode 100644 index 00000000..35d418ee --- /dev/null +++ b/testsuite/systemtap.server/client_args.exp @@ -0,0 +1,102 @@ +set test "Server Client Arguments" + +# stap_run_exact only works for 'make installcheck' +if {[info procs installtest_p] != "" && ![installtest_p]} { untested $test; return } + +# Test that stap on the server side will correctly accept/reject certain +# arguments in unprivileged mode. +set test_file $srcdir/systemtap.server/test.stp + +set no_error_result "# parse tree dump +# file $test_file +probe begin{ +exit() +} + +" + +# First test valid combinations +set valid_options [list \ + "-a i386" \ + "-B X=Y" \ + "-D X=Y" \ + "-I /tmp" \ + "-m test" \ + "-R /tmp" \ + "-r [exec uname -r]" \ + "-a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r]" \ + "--unprivileged" \ + "--unprivileged -a i386" \ + "--unprivileged -B X=Y" \ + "--unprivileged -D X=Y" \ + "--unprivileged -I /tmp" \ + "--unprivileged -m test" \ + "--unprivileged -R /tmp" \ + "--unprivileged -r [exec uname -r]" \ + "--unprivileged -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r]" \ + "--client-options" \ + "--client-options -a i386" \ + "--client-options -B X=Y" \ + "--client-options -D X=Y" \ + "--client-options -I /tmp" \ + "--client-options -m test" \ + "--client-options -R /tmp" \ + "--client-options -r [exec uname -r]" \ + "--client-options -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r]" \ + "--unprivileged --client-options" \ + "--unprivileged -a i386 --client-options" \ + "--unprivileged -B X=Y --client-options" \ + "--unprivileged -D X=Y --client-options" \ + "--unprivileged -I /tmp --client-options" \ + "--unprivileged -m test --client-options" \ + "--unprivileged -R /tmp --client-options" \ + "--unprivileged -r [exec uname -r] --client-options" \ + "--unprivileged -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r] --client-options" \ +] + +set ::result_string "$no_error_result" +foreach options $valid_options { + eval stap_run_exact {"$test: $options"} $test_file -p1 $options +} + +# Now test invalid combinations. +set error_regexp ".*You can't specify (-\[aBDImRr\], )*-\[aBDImRr\] when --unprivileged is specified.*" + +set invalid_options [list \ + "--unprivileged --client-options -a i386" \ + "--unprivileged --client-options -B X=Y" \ + "--unprivileged --client-options -D X=Y" \ + "--unprivileged --client-options -I /tmp" \ + "--unprivileged --client-options -m test" \ + "--unprivileged --client-options -R /tmp" \ + "--unprivileged --client-options -r [exec uname -r]" \ + "--unprivileged --client-options -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r]" \ + "--client-options --unprivileged -a i386" \ + "--client-options --unprivileged -B X=Y" \ + "--client-options --unprivileged -D X=Y" \ + "--client-options --unprivileged -I /tmp" \ + "--client-options --unprivileged -m test" \ + "--client-options --unprivileged -R /tmp" \ + "--client-options --unprivileged -r [exec uname -r]" \ + "--client-options --unprivileged -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r]" \ + "--client-options -a i386 --unprivileged" \ + "--client-options -B X=Y --unprivileged" \ + "--client-options -D X=Y --unprivileged" \ + "--client-options -I /tmp --unprivileged" \ + "--client-options -m test --unprivileged" \ + "--client-options -R /tmp --unprivileged" \ + "--client-options -r [exec uname -r] --unprivileged" \ + "--client-options -a i386 -B X=Y -D X=Y -I /tmp -m test -R /tmp -r [exec uname -r] --unprivileged" \ +] + +foreach options $invalid_options { + verbose -log "eval exec stap $options" + catch {eval exec stap -p1 $options} res_stap + verbose -log $res_stap + + if {[regexp $error_regexp $res_stap]} { + pass "$test: $options" + } else { + fail "$test: $options" + } +} diff --git a/testsuite/systemtap.server/test.stp b/testsuite/systemtap.server/test.stp new file mode 100644 index 00000000..e0f4117f --- /dev/null +++ b/testsuite/systemtap.server/test.stp @@ -0,0 +1 @@ +probe begin { exit (); } |