]> granicus.if.org Git - strace/commitdiff
Trivial tweaks to error messages
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 8 Mar 2012 10:54:10 +0000 (11:54 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 8 Mar 2012 10:54:10 +0000 (11:54 +0100)
* strace.c (test_ptrace_setoptions_followfork): Use kill_save_errno
instead of kill.
(trace): Use perror_msg instead of perror.
* count.c (set_sortby): Use error_msg_and_die instead of fprintf.
* syscall.c (qualify): Likewise.
* util.c (ptrace_restart): Expand error message.
(umoven): Likewise.
(umovestr): Likewise.
(upeek): Use perror_msg instead of sprintf + perror.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
count.c
strace.c
syscall.c
util.c

diff --git a/count.c b/count.c
index c53274750d097b522cf468f867d1bcecad80e01a..673c3540461b333a653acb9381566bb42751cd3e 100644 (file)
--- a/count.c
+++ b/count.c
@@ -130,8 +130,7 @@ set_sortby(const char *sortby)
        else if (strcmp(sortby, "nothing") == 0)
                sortfun = NULL;
        else {
-               fprintf(stderr, "invalid sortby: `%s'\n", sortby);
-               exit(1);
+               error_msg_and_die("invalid sortby: '%s'", sortby);
        }
 }
 
index 9b026e325ef9ddf8d3a90686aa2966ecce448f85..d774611cb4c1081939c714e91875a29928732e70 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -775,7 +775,7 @@ test_ptrace_setoptions_followfork(void)
                if (ptrace(PTRACE_TRACEME, 0L, 0L, 0L) < 0)
                        perror_msg_and_die("%s: PTRACE_TRACEME doesn't work",
                                           __func__);
-               kill(pid, SIGSTOP);
+               kill_save_errno(pid, SIGSTOP);
                if (fork() < 0)
                        perror_msg_and_die("fork");
                _exit(0);
@@ -789,7 +789,7 @@ test_ptrace_setoptions_followfork(void)
                if (tracee_pid <= 0) {
                        if (errno == EINTR)
                                continue;
-                       else if (errno == ECHILD)
+                       if (errno == ECHILD)
                                break;
                        kill_save_errno(pid, SIGKILL);
                        perror_msg_and_die("%s: unexpected wait result %d",
@@ -813,7 +813,7 @@ test_ptrace_setoptions_followfork(void)
                if (!WIFSTOPPED(status)) {
                        if (tracee_pid != pid)
                                kill_save_errno(tracee_pid, SIGKILL);
-                       kill(pid, SIGKILL);
+                       kill_save_errno(pid, SIGKILL);
                        error_msg_and_die("%s: unexpected wait status %x",
                                          __func__, status);
                }
@@ -1655,7 +1655,7 @@ trace(void)
                                return 0;
                        default:
                                errno = wait_errno;
-                               perror("strace: wait");
+                               perror_msg("wait");
                                return -1;
                        }
                }
index dce705641328f02ecaf2c7a21a283bbef8ef60ea..f54df0fcb3fc104ec49c967e122544fed75614db 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -510,9 +510,8 @@ qualify(const char *s)
                        continue;
                }
                if (opt->qualify(p, opt->bitflag, not)) {
-                       fprintf(stderr, "strace: invalid %s `%s'\n",
+                       error_msg_and_die("invalid %s '%s'",
                                opt->argument_name, p);
-                       exit(1);
                }
        }
        free(copy);
diff --git a/util.c b/util.c
index 640f246fde17c498e7d3bf86f938030000bd5a5a..a7cb19c0ceb1c31576d75ebc569741bc06351123 100644 (file)
--- a/util.c
+++ b/util.c
@@ -219,7 +219,7 @@ ptrace_restart(int op, struct tcb *tcp, int sig)
        if (op == PTRACE_LISTEN)
                msg = "LISTEN";
 #endif
-       perror_msg("ptrace(PTRACE_%s,1,%d)", msg, sig);
+       perror_msg("ptrace(PTRACE_%s,pid:%d,1,sig:%d)", msg, tcp->pid, sig);
        return -1;
 }
 
@@ -851,7 +851,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
                if (errno) {
                        /* But if not started, we had a bogus address. */
                        if (addr != 0 && errno != EIO && errno != ESRCH)
-                               perror("ptrace: umoven");
+                               perror_msg("umoven: PTRACE_PEEKDATA pid:%d @0x%lx", pid, addr);
                        return -1;
                }
                started = 1;
@@ -868,7 +868,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
                                return 0;
                        }
                        if (addr != 0 && errno != EIO && errno != ESRCH)
-                               perror("ptrace: umoven");
+                               perror_msg("umoven: PTRACE_PEEKDATA pid:%d @0x%lx", pid, addr);
                        return -1;
                }
                started = 1;
@@ -966,7 +966,7 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
                u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
                if (errno) {
                        if (addr != 0 && errno != EIO && errno != ESRCH)
-                               perror("umovestr");
+                               perror_msg("umovestr: PTRACE_PEEKDATA pid:%d @0x%lx", pid, addr);
                        return -1;
                }
                started = 1;
@@ -986,7 +986,7 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
                                return 0;
                        }
                        if (addr != 0 && errno != EIO && errno != ESRCH)
-                               perror("umovestr");
+                               perror_msg("umovestr: PTRACE_PEEKDATA pid:%d @0x%lx", pid, addr);
                        return -1;
                }
                started = 1;
@@ -1014,9 +1014,7 @@ upeek(struct tcb *tcp, long off, long *res)
        val = do_ptrace(PTRACE_PEEKUSER, tcp, (char *) off, 0);
        if (val == -1 && errno) {
                if (errno != ESRCH) {
-                       char buf[60];
-                       sprintf(buf, "upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)", tcp->pid, off);
-                       perror(buf);
+                       perror_msg("upeek: PTRACE_PEEKUSER pid:%d @0x%lx)", tcp->pid, off);
                }
                return -1;
        }