X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=trace%2Ftrace.c;h=1c1e75753fc910fad78f4aec4c7a01f3a55d6f29;hp=d0220791eab0ff6293d99dcbb12f20c2a8a6026a;hb=67eb7e68165bfa29ab57eb82f3e40eca17662365;hpb=520ad3c71507d76738a4afa14fc51dbe57275606 diff --git a/trace/trace.c b/trace/trace.c index d022079..1c1e757 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef PTRACE_EVENT_STOP /* PTRACE_EVENT_STOP is defined in linux/ptrace.h, but this header @@ -326,7 +327,7 @@ int main(int argc, char **argv, char **envp) memcpy(&_envp[newenv], envp, envc * sizeof(char *)); ret = execve(_argv[0], _argv, _envp); - ULOG_ERR("failed to exec %s: %s\n", _argv[0], strerror(errno)); + ULOG_ERR("failed to exec %s: %m\n", _argv[0]); free(_argv); free(_envp); @@ -342,6 +343,9 @@ int main(int argc, char **argv, char **envp) return -1; } + /* Initialize uloop to catch all ptrace stops from now on. */ + uloop_init(); + int ptrace_options = PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE; switch (mode) { case UTRACE: @@ -354,15 +358,14 @@ int main(int argc, char **argv, char **envp) break; } if (ptrace(PTRACE_SEIZE, child, 0, ptrace_options) == -1) { - ULOG_ERR("PTRACE_SEIZE: %s\n", strerror(errno)); + ULOG_ERR("PTRACE_SEIZE: %m\n"); return -1; } if (ptrace(ptrace_restart, child, 0, SIGCONT) == -1) { - ULOG_ERR("ptrace_restart: %s\n", strerror(errno)); + ULOG_ERR("ptrace_restart: %m\n"); return -1; } - uloop_init(); tracer.proc.pid = child; tracer.proc.cb = tracer_cb; uloop_process_add(&tracer.proc); @@ -375,7 +378,7 @@ int main(int argc, char **argv, char **envp) case UTRACE: if (!json) if (asprintf(&json, "/tmp/%s.%u.json", basename(*argv), child) < 0) - ULOG_ERR("failed to allocate output path: %s\n", strerror(errno)); + ULOG_ERR("failed to allocate output path: %m\n"); break; case SECCOMP_TRACE: if (!violation_count)