summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromiatnikov <esyr@redhat.com>2017-12-25 23:59:36 +0100
committerDmitry V. Levin <ldv@altlinux.org>2019-05-21 23:30:35 +0000
commit3b4045a79da136713a7c4cc25125b1216898e86a (patch)
treeecfa7f15dd9c4b830da672a9abf9f2b05fc6f4f1
parenteccfebb41edf60338a0b548aad2abc2ac2e41d89 (diff)
downloadstrace-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.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/strace.c b/strace.c
index 74559ab33..5ea2efcb3 100644
--- a/strace.c
+++ b/strace.c
@@ -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,