diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-10-23 16:33:11 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-10-23 16:33:11 -0400 |
commit | 34f2e0b9b69ddbc2f2e7503e887f16fca9fdfee2 (patch) | |
tree | 16bbf243101b66d34853f060eda98c3eb9abc2c0 | |
parent | b5223457bca23f214fb35f3ffdc372bf67cfe190 (diff) | |
download | systemtap-steved-34f2e0b9b69ddbc2f2e7503e887f16fca9fdfee2.tar.gz systemtap-steved-34f2e0b9b69ddbc2f2e7503e887f16fca9fdfee2.tar.xz systemtap-steved-34f2e0b9b69ddbc2f2e7503e887f16fca9fdfee2.zip |
BZ467652: support old-style stap -c "FOO > BAR" usage by backing down to sh -c if needed.
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | runtime/staprun/mainloop.c | 34 |
2 files changed, 32 insertions, 9 deletions
@@ -29,8 +29,11 @@ - Target process mode (stap -c CMD or -x PID) now implicitly restricts all "process.*" probes to the given child process. (It does not affect - kernel.* or other probe types.) The CMD string is now executed directly, - rather than via a /bin/sh -c subshell. + kernel.* or other probe types.) The CMD string is normally run directly, + rather than via a /bin/sh -c subshell, since then utrace/uprobe probes + receive a fairly "clean" event stream. If metacharacters like + redirection operators were present in CMD, then "sh -c CMD" is still + used, and utrace/uprobe probes will receive events from the shell. % stap -e 'probe process.syscall, process.end { printf("%s %d %s\n", execname(), pid(), pp())}'\ diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c index 8db42d7d..9221d8a6 100644 --- a/runtime/staprun/mainloop.c +++ b/runtime/staprun/mainloop.c @@ -118,6 +118,7 @@ void start_cmd(void) /* We're in the target process. Let's start the execve of target_cmd, */ int rc; wordexp_t words; + char *sh_c_argv[4] = { NULL, NULL, NULL, NULL }; a.sa_handler = SIG_DFL; sigaction(SIGINT, &a, NULL); @@ -127,14 +128,32 @@ void start_cmd(void) probe a new child process, not a mishmash of shell-interpreted stuff. */ rc = wordexp (target_cmd, & words, WRDE_NOCMD|WRDE_UNDEF); - switch (rc) + if (rc == WRDE_BADCHAR) { - case 0: break; - case WRDE_BADCHAR: _err ("wordexp: invalid shell meta-character in -c COMMAND\n"); _exit(1); - case WRDE_SYNTAX: _err ("wordexp: syntax error (unmatched quotes?) in -c COMMAND\n"); _exit(1); - default: _err ("wordexp: parsing error (%d)\n", rc); _exit (1); + /* The user must have used a shell metacharacter, thinking that + we use system(3) to evaluate 'stap -c CMD'. We could generate + an error message ... but let's just do what the user meant. + rhbz 467652. */ + sh_c_argv[0] = "sh"; + sh_c_argv[1] = "-c"; + sh_c_argv[2] = target_cmd; + sh_c_argv[3] = NULL; + } + else + { + switch (rc) + { + case 0: + break; + case WRDE_SYNTAX: + _err ("wordexp: syntax error (unmatched quotes?) in -c COMMAND\n"); + _exit(1); + default: + _err ("wordexp: parsing error (%d)\n", rc); + _exit (1); + } + if (words.we_wordc < 1) { _err ("empty -c COMMAND"); _exit (1); } } - if (words.we_wordc < 1) { _err ("empty -c COMMAND"); _exit (1); } rc = ptrace (PTRACE_TRACEME, 0, 0, 0); if (rc < 0) perror ("ptrace me"); @@ -149,7 +168,8 @@ void start_cmd(void) /* Note that execvp() is not a direct system call; it does a $PATH search in glibc. We would like to filter out these dummy syscalls from the utrace events seen by scripts. */ - if (execvp (words.we_wordv[0], words.we_wordv) < 0) + if (execvp ((sh_c_argv[0] == NULL ? words.we_wordv[0] : sh_c_argv[0]), + (sh_c_argv[0] == NULL ? words.we_wordv : sh_c_argv)) < 0) perror(target_cmd); /* (There is no need to wordfree() words; they are or will be gone.) */ |