diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2013-05-14 16:07:46 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2013-05-14 16:10:42 +0200 |
| commit | 2a3d27552f17a5b378344620bec7d255bac65a8d (patch) | |
| tree | 1f04f471af05982933c3badd2fe31aafc3becd30 | |
| parent | 01997cf32d4492b9898283ced45e8a4a6fd161b8 (diff) | |
| download | strace-2a3d27552f17a5b378344620bec7d255bac65a8d.tar.gz strace-2a3d27552f17a5b378344620bec7d255bac65a8d.tar.bz2 strace-2a3d27552f17a5b378344620bec7d255bac65a8d.tar.xz | |
Hide startup syscalls.
Tested with "./strace [-D] [-q] [-bexecve] env true",
all cases seem to work.
* defs.h: Declare new variable: bool hide_log_until_execve.
* strace.c: Define hide_log_until_execve.
Rename skip_startup_execve to skip_one_b_execve.
(startup_child): Do not set skip_one_b_execve = 1 here.
(init): If "strace PROG" case (as opposed to "strace -pPID"),
set skip_one_b_execve and hide_log_until_execve to 1.
(trace): Don't print signal messages if hide_log_until_execve == 1.
* syscall.c (trace_syscall_entering):
Skip syscall printing if hide_log_until_execve == 1.
Reset hide_log_until_execve if we enter execve syscall.
(trace_syscall_exiting): Skip syscall printing if hide_log_until_execve == 1.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
| -rw-r--r-- | defs.h | 1 | ||||
| -rw-r--r-- | strace.c | 20 | ||||
| -rw-r--r-- | syscall.c | 12 |
3 files changed, 22 insertions, 11 deletions
@@ -542,6 +542,7 @@ extern bool Tflag; extern unsigned int qflag; extern bool not_failing_only; extern bool show_fd_path; +extern bool hide_log_until_execve; /* are we filtering traces based on paths? */ extern const char **paths_selected; #define tracing_paths (paths_selected != NULL) @@ -124,7 +124,10 @@ bool not_failing_only = 0; bool show_fd_path = 0; static bool detach_on_execve = 0; -static bool skip_startup_execve = 0; +/* Are we "strace PROG" and need to skip detach on first execve? */ +static bool skip_one_b_execve = 0; +/* Are we "strace PROG" and need to hide everything until execve? */ +bool hide_log_until_execve = 0; static int exit_code = 0; static int strace_child = 0; @@ -1163,7 +1166,6 @@ startup_child(char **argv) kill_save_errno(pid, SIGKILL); perror_msg_and_die("Unexpected wait status %x", status); } - skip_startup_execve = 1; } /* Else: NOMMU case, we have no way to sync. * Just attach to it as soon as possible. @@ -1192,7 +1194,6 @@ startup_child(char **argv) alloctcb(pid); /* attaching will be done later, by startup_attach */ /* note: we don't do newoutf(tcp) here either! */ - skip_startup_execve = 1; /* NOMMU BUG! -D mode is active, we (child) return, * and we will scribble over parent's stack! @@ -1788,6 +1789,8 @@ init(int argc, char *argv[]) * in the startup_child() mode we kill the spawned process anyway. */ if (argv[0]) { + hide_log_until_execve = 1; + skip_one_b_execve = 1; startup_child(argv); } @@ -2074,11 +2077,10 @@ trace(void) } dont_switch_tcbs: - if (event == PTRACE_EVENT_EXEC && detach_on_execve) { - if (!skip_startup_execve) - detach(tcp); - /* This was initial execve for "strace PROG". Skip. */ - skip_startup_execve = 0; + if (event == PTRACE_EVENT_EXEC) { + if (detach_on_execve && !skip_one_b_execve) + detach(tcp); /* do "-b execve" thingy */ + skip_one_b_execve = 0; } /* Set current output file */ @@ -2222,7 +2224,7 @@ trace(void) # define PC_FORMAT_STR "" # define PC_FORMAT_ARG /* nothing */ #endif - if (qflag < 2) { + if (qflag < 2 && !hide_log_until_execve) { printleader(tcp); if (!stopped) { tprintf("--- %s ", signame(sig)); @@ -1985,6 +1985,14 @@ trace_syscall_entering(struct tcb *tcp) goto ret; } + if ( sys_execve == tcp->s_ent->sys_func +# if defined(SPARC) || defined(SPARC64) + || sys_execv == tcp->s_ent->sys_func +# endif + ) { + hide_log_until_execve = 0; + } + #if defined(SYS_socket_subcall) || defined(SYS_ipc_subcall) while (1) { # ifdef SYS_socket_subcall @@ -2015,7 +2023,7 @@ trace_syscall_entering(struct tcb *tcp) tcp->flags &= ~TCB_FILTERED; - if (cflag == CFLAG_ONLY_STATS) { + if (cflag == CFLAG_ONLY_STATS || hide_log_until_execve) { res = 0; goto ret; } @@ -2503,7 +2511,7 @@ trace_syscall_exiting(struct tcb *tcp) get_error(tcp); /* never fails */ if (need_fork_exec_workarounds) syscall_fixup_for_fork_exec(tcp); - if (filtered(tcp)) + if (filtered(tcp) || hide_log_until_execve) goto ret; } |
