From: Dmitry V. Levin Date: Mon, 17 Sep 2012 23:20:54 +0000 (+0000) Subject: Use perror_msg instead of perror X-Git-Tag: v4.8~215 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a71bcdab254e4cd93b8f1e93c659644eb70ea9b;p=strace Use perror_msg instead of perror * signal.c (sys_sigreturn): Use perror_msg instead of perror. * strace.c (tprintf, tprints, detach, startup_attach): Likewise. * syscall.c (get_scno): Likewise. * util.c (umoven, umovestr): Likewise. --- diff --git a/signal.c b/signal.c index 1441de17..efe335c2 100644 --- a/signal.c +++ b/signal.c @@ -990,12 +990,12 @@ sys_sigreturn(struct tcb *tcp) m_siginfo_t si; sigset_t sigm; if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) { - perror("sigreturn: PTRACE_GETREGS"); + perror_msg("%s", "sigreturn: PTRACE_GETREGS"); return 0; } i1 = regs.u_regs[U_REG_O1]; if (umove(tcp, i1, &si) < 0) { - perror("sigreturn: umove"); + perror_msg("%s", "sigreturn: umove"); return 0; } long_to_sigset(si.si_mask, &sigm); @@ -1024,7 +1024,7 @@ sys_sigreturn(struct tcb *tcp) m_siginfo_t si; sigset_t sigm; if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) { - perror("sigreturn: PTRACE_GETREGS"); + perror_msg("%s", "sigreturn: PTRACE_GETREGS"); return 0; } sp = regs.regs[29]; @@ -1039,7 +1039,7 @@ sys_sigreturn(struct tcb *tcp) long regs[PT_MAX+1]; sigset_t sigm; if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) { - perror("sigreturn: PTRACE_GETREGS"); + perror_msg("%s", "sigreturn: PTRACE_GETREGS"); return 0; } if (umove(tcp, regs[PT_USP], &sc) < 0) diff --git a/strace.c b/strace.c index 8fbd8ced..1331e38b 100644 --- a/strace.c +++ b/strace.c @@ -515,8 +515,7 @@ tprintf(const char *fmt, ...) int n = strace_vfprintf(current_tcp->outf, fmt, args); if (n < 0) { if (current_tcp->outf != stderr) - perror(outfname == NULL - ? "" : outfname); + perror_msg("%s", outfname); } else current_tcp->curcol += n; } @@ -533,7 +532,7 @@ tprints(const char *str) return; } if (current_tcp->outf != stderr) - perror(!outfname ? "" : outfname); + perror_msg("%s", outfname); } } @@ -750,15 +749,15 @@ detach(struct tcb *tcp) } else if (errno != ESRCH) { /* Shouldn't happen. */ - perror("detach: ptrace(PTRACE_DETACH, ...)"); + perror_msg("%s", "detach: ptrace(PTRACE_DETACH, ...)"); } else if (my_tkill(tcp->pid, 0) < 0) { if (errno != ESRCH) - perror("detach: checking sanity"); + perror_msg("%s", "detach: checking sanity"); } else if (!sigstop_expected && my_tkill(tcp->pid, SIGSTOP) < 0) { if (errno != ESRCH) - perror("detach: stopping child"); + perror_msg("%s", "detach: stopping child"); } else sigstop_expected = 1; @@ -771,21 +770,21 @@ detach(struct tcb *tcp) if (errno == ECHILD) /* Already gone. */ break; if (errno != EINVAL) { - perror("detach: waiting"); + perror_msg("%s", "detach: waiting"); break; } #endif /* __WALL */ /* No __WALL here. */ if (waitpid(tcp->pid, &status, 0) < 0) { if (errno != ECHILD) { - perror("detach: waiting"); + perror_msg("%s", "detach: waiting"); break; } #ifdef __WCLONE /* If no processes, try clones. */ if (waitpid(tcp->pid, &status, __WCLONE) < 0) { if (errno != ECHILD) - perror("detach: waiting"); + perror_msg("%s", "detach: waiting"); break; } #endif /* __WCLONE */ @@ -934,7 +933,7 @@ startup_attach(void) } ntid -= nerr; if (ntid == 0) { - perror("attach: ptrace(PTRACE_ATTACH, ...)"); + perror_msg("%s", "attach: ptrace(PTRACE_ATTACH, ...)"); droptcb(tcp); continue; } @@ -955,7 +954,7 @@ startup_attach(void) } /* if (opendir worked) */ } /* if (-f) */ if (ptrace_attach_or_seize(tcp->pid) < 0) { - perror("attach: ptrace(PTRACE_ATTACH, ...)"); + perror_msg("%s", "attach: ptrace(PTRACE_ATTACH, ...)"); droptcb(tcp); continue; } diff --git a/syscall.c b/syscall.c index 52d742f7..cda017c5 100644 --- a/syscall.c +++ b/syscall.c @@ -721,7 +721,7 @@ get_scno(struct tcb *tcp) errno = 0; opcode = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)(pc-sizeof(long)), 0); if (errno) { - perror("peektext(pc-oneword)"); + perror_msg("%s", "peektext(pc-oneword)"); return -1; } diff --git a/util.c b/util.c index 9ca49b27..8254677f 100644 --- a/util.c +++ b/util.c @@ -789,9 +789,10 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr) if (r < 0) { if (errno == ENOSYS) process_vm_readv_not_supported = 1; - else if (errno != EINVAL && errno != ESRCH) /* EINVAL is seen if process is gone */ - /* strange... */ - perror("process_vm_readv"); + else if (errno != EINVAL && errno != ESRCH) + /* EINVAL or ESRCH could be seen if process is gone, + * all the rest is strange and should be reported. */ + perror_msg("%s", "process_vm_readv"); goto vm_readv_didnt_work; } return r; @@ -899,9 +900,11 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr) if (r < 0) { if (errno == ENOSYS) process_vm_readv_not_supported = 1; - else if (errno != EINVAL && errno != ESRCH) /* EINVAL is seen if process is gone */ - /* strange... */ - perror("process_vm_readv"); + else if (errno != EINVAL && errno != ESRCH) + /* EINVAL or ESRCH could be seen + * if process is gone, all the rest + * is strange and should be reported. */ + perror_msg("%s", "process_vm_readv"); goto vm_readv_didnt_work; } if (memchr(local[0].iov_base, '\0', r))