From: Denys Vlasenko Date: Mon, 12 Mar 2012 22:02:26 +0000 (+0100) Subject: Preparatory cosmetic changes for the next commit X-Git-Tag: v4.7~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e856a1c9215d292a7c41695928e8552788bc43c;p=strace Preparatory cosmetic changes for the next commit * strace.c (tprintf): Move function up in the source file. No code changes. (tprints): Likewise. (printleader): Likewise. (tabto): Likewise. Signed-off-by: Denys Vlasenko --- diff --git a/strace.c b/strace.c index c662c587..6196e67e 100644 --- a/strace.c +++ b/strace.c @@ -337,6 +337,102 @@ static void kill_save_errno(pid_t pid, int sig) errno = saved_errno; } +void +tprintf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (outf) { + int n = vfprintf(outf, fmt, args); + if (n < 0) { + if (outf != stderr) + perror(outfname == NULL + ? "" : outfname); + } else + curcol += n; + } + va_end(args); +} + +void +tprints(const char *str) +{ + if (outf) { + int n = fputs(str, outf); + if (n >= 0) { + curcol += strlen(str); + return; + } + if (outf != stderr) + perror(outfname == NULL + ? "" : outfname); + } +} + +void +printleader(struct tcb *tcp) +{ + if (printing_tcp) { + if (printing_tcp->ptrace_errno) { + if (printing_tcp->flags & TCB_INSYSCALL) { + tprints(" ) "); + tabto(); + } + tprints("= ? \n"); + printing_tcp->ptrace_errno = 0; + } else if (!outfname || followfork < 2 || printing_tcp == tcp) { + printing_tcp->flags |= TCB_REPRINT; + tprints(" \n"); + } + } + + printing_tcp = tcp; + curcol = 0; + + if (print_pid_pfx) + tprintf("%-5d ", tcp->pid); + else if (nprocs > 1 && !outfname) + tprintf("[pid %5u] ", tcp->pid); + + if (tflag) { + char str[sizeof("HH:MM:SS")]; + struct timeval tv, dtv; + static struct timeval otv; + + gettimeofday(&tv, NULL); + if (rflag) { + if (otv.tv_sec == 0) + otv = tv; + tv_sub(&dtv, &tv, &otv); + tprintf("%6ld.%06ld ", + (long) dtv.tv_sec, (long) dtv.tv_usec); + otv = tv; + } + else if (tflag > 2) { + tprintf("%ld.%06ld ", + (long) tv.tv_sec, (long) tv.tv_usec); + } + else { + time_t local = tv.tv_sec; + strftime(str, sizeof(str), "%T", localtime(&local)); + if (tflag > 1) + tprintf("%s.%06ld ", str, (long) tv.tv_usec); + else + tprintf("%s ", str); + } + } + if (iflag) + printcall(tcp); +} + +void +tabto(void) +{ + if (curcol < acolumn) + tprints(acolumn_spaces + curcol); +} + /* * When strace is setuid executable, we have to swap uids * before and after filesystem and process management operations. @@ -2036,99 +2132,3 @@ trace(void) } return 0; } - -void -tprintf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - if (outf) { - int n = vfprintf(outf, fmt, args); - if (n < 0) { - if (outf != stderr) - perror(outfname == NULL - ? "" : outfname); - } else - curcol += n; - } - va_end(args); -} - -void -tprints(const char *str) -{ - if (outf) { - int n = fputs(str, outf); - if (n >= 0) { - curcol += strlen(str); - return; - } - if (outf != stderr) - perror(outfname == NULL - ? "" : outfname); - } -} - -void -printleader(struct tcb *tcp) -{ - if (printing_tcp) { - if (printing_tcp->ptrace_errno) { - if (printing_tcp->flags & TCB_INSYSCALL) { - tprints(" ) "); - tabto(); - } - tprints("= ? \n"); - printing_tcp->ptrace_errno = 0; - } else if (!outfname || followfork < 2 || printing_tcp == tcp) { - printing_tcp->flags |= TCB_REPRINT; - tprints(" \n"); - } - } - - printing_tcp = tcp; - curcol = 0; - - if (print_pid_pfx) - tprintf("%-5d ", tcp->pid); - else if (nprocs > 1 && !outfname) - tprintf("[pid %5u] ", tcp->pid); - - if (tflag) { - char str[sizeof("HH:MM:SS")]; - struct timeval tv, dtv; - static struct timeval otv; - - gettimeofday(&tv, NULL); - if (rflag) { - if (otv.tv_sec == 0) - otv = tv; - tv_sub(&dtv, &tv, &otv); - tprintf("%6ld.%06ld ", - (long) dtv.tv_sec, (long) dtv.tv_usec); - otv = tv; - } - else if (tflag > 2) { - tprintf("%ld.%06ld ", - (long) tv.tv_sec, (long) tv.tv_usec); - } - else { - time_t local = tv.tv_sec; - strftime(str, sizeof(str), "%T", localtime(&local)); - if (tflag > 1) - tprintf("%s.%06ld ", str, (long) tv.tv_usec); - else - tprintf("%s ", str); - } - } - if (iflag) - printcall(tcp); -} - -void -tabto(void) -{ - if (curcol < acolumn) - tprints(acolumn_spaces + curcol); -}