diff options
author | Eugene Syromiatnikov <esyr@redhat.com> | 2017-12-25 23:59:36 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2019-05-21 23:30:35 +0000 |
commit | 3b4045a79da136713a7c4cc25125b1216898e86a (patch) | |
tree | ecfa7f15dd9c4b830da672a9abf9f2b05fc6f4f1 | |
parent | eccfebb41edf60338a0b548aad2abc2ac2e41d89 (diff) | |
download | strace-3b4045a79da136713a7c4cc25125b1216898e86a.tar.gz |
strace.c: move ptrace backend initialisation into a separate routine
In a preparation to TraBAL introduction.
* strace.c (tracing_backend_init): New function.
(tracing_backend_name): New macro.
(init): Move OS release detection, ptrace_setoptions initialisation,
and PTRACE_SEIZE/PTRACE_GET_SYSCALL_INFO tests to tracing_backend_init.
-rw-r--r-- | strace.c | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1618,6 +1618,26 @@ set_sighandler(int signo, void (*sighandler)(int), struct sigaction *oldact) sigaction(signo, &sa, oldact); } +bool +tracing_backend_init(int argc, char *argv[]) +{ + os_release = get_os_release(); + + if (followfork) + ptrace_setoptions |= PTRACE_O_TRACECLONE | + PTRACE_O_TRACEFORK | + PTRACE_O_TRACEVFORK; + debug_msg("ptrace_setoptions = %#x", ptrace_setoptions); + + + test_ptrace_seize(); + test_ptrace_get_syscall_info(); + + return true; +} + +#define tracing_backend_name() "ptrace" + /* * Initialization part of main() was eating much stack (~0.5k), * which was unused after init. @@ -1652,8 +1672,6 @@ init(int argc, char *argv[]) strace_tracer_pid = getpid(); - os_release = get_os_release(); - shared_log = stderr; set_sortby(DEFAULT_SORTBY); set_personality(DEFAULT_PERSONALITY); @@ -1854,6 +1872,10 @@ init(int argc, char *argv[]) error_msg("-%c has no effect with -c", 'y'); } + if (!tracing_backend_init(argc, argv)) + error_msg_and_die("Cannot initialize backend \"%s\".", + tracing_backend_name()); + for (cnt = 0; cnt < pathtrace_count; cnt++) pathtrace_select(pathtrace_paths[cnt]); free(pathtrace_paths); @@ -1887,14 +1909,6 @@ init(int argc, char *argv[]) run_gid = getgid(); } - if (followfork) - ptrace_setoptions |= PTRACE_O_TRACECLONE | - PTRACE_O_TRACEFORK | - PTRACE_O_TRACEVFORK; - debug_msg("ptrace_setoptions = %#x", ptrace_setoptions); - test_ptrace_seize(); - test_ptrace_get_syscall_info(); - /* * Is something weird with our stdin and/or stdout - * for example, may they be not open? In this case, |