From: Denys Vlasenko Date: Tue, 14 May 2013 14:07:46 +0000 (+0200) Subject: Hide startup syscalls. X-Git-Tag: v4.8~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a3d27552f17a5b378344620bec7d255bac65a8d;p=strace 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 --- diff --git a/defs.h b/defs.h index 58cdf999..3f07c4f3 100644 --- a/defs.h +++ b/defs.h @@ -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) diff --git a/strace.c b/strace.c index f6f6e898..84a443c0 100644 --- a/strace.c +++ b/strace.c @@ -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)); diff --git a/syscall.c b/syscall.c index 833dacd3..7efee0e4 100644 --- a/syscall.c +++ b/syscall.c @@ -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; }