]> granicus.if.org Git - strace/commitdiff
Hide startup syscalls.
authorDenys Vlasenko <dvlasenk@redhat.com>
Tue, 14 May 2013 14:07:46 +0000 (16:07 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Tue, 14 May 2013 14:10:42 +0000 (16:10 +0200)
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>
defs.h
strace.c
syscall.c

diff --git a/defs.h b/defs.h
index 58cdf999b44e5cdebf8c1a523d1e9b9e96feb812..3f07c4f38f7e858e39993ff2a4b057488aeae73e 100644 (file)
--- 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)
index f6f6e89814234ccb5fe3857b31ce36094722dd45..84a443c07ff6c5a0fce8d96937feda9a5f363784 100644 (file)
--- 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));
index 833dacd3ad19d0d13d1b2837b135b0255f66a865..7efee0e43e132c8827199c03f379ae3f636dfbab 100644 (file)
--- 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;
        }