From: Dmitry V. Levin Date: Fri, 18 Sep 2015 17:44:16 +0000 (+0000) Subject: Convert another parser of struct timespec to new mpers infrastructure X-Git-Tag: v4.11~173 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2950de36314b5ea88a3741e24f948113358f7ce2;p=strace Convert another parser of struct timespec to new mpers infrastructure * print_time.c (sprint_timespec): New mpers printer. * defs.h (TIMESPEC_TEXT_BUFSIZE): Update. (sprint_timespec): Remove. * time.c (sprint_timespec): Remove. * net.c (sys_recvmmsg): Update callers. * poll.c (decode_poll_exiting): Likewise. --- diff --git a/defs.h b/defs.h index 826ab940..9b9a105d 100644 --- a/defs.h +++ b/defs.h @@ -647,11 +647,11 @@ extern bool printpair_int64(struct tcb *, long, const char *) ATTRIBUTE_FORMAT((printf, 3, 0)); extern void printpath(struct tcb *, long); extern void printpathn(struct tcb *, long, unsigned int); -#define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}")) +#define TIMESPEC_TEXT_BUFSIZE \ + (sizeof(intmax_t)*3 * 2 + sizeof("{tv_sec=%jd, tv_nsec=%jd}")) #define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE extern void printtv_bitness(struct tcb *, long, enum bitness_t, int); extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special); -extern void sprint_timespec(char *, struct tcb *, long); extern void printfd(struct tcb *, int); extern bool print_sockaddr_by_inode(const unsigned long, const char *); extern void print_dirfd(struct tcb *, int); diff --git a/net.c b/net.c index 40b5a5c3..7e8586ac 100644 --- a/net.c +++ b/net.c @@ -875,18 +875,16 @@ SYS_FUNC(recvmsg) SYS_FUNC(recvmmsg) { - /* +5 chars are for "left " prefix */ - static char str[5 + TIMESPEC_TEXT_BUFSIZE]; + static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE]; if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); if (verbose(tcp)) { - sprint_timespec(str, tcp, tcp->u_arg[4]); /* Abusing tcp->auxstr as temp storage. - * Will be used and freed on syscall exit. + * Will be used and cleared on syscall exit. */ - tcp->auxstr = xstrdup(str); + tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); } else { tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]); printflags(msg_flags, tcp->u_arg[3], "MSG_???"); @@ -897,9 +895,9 @@ SYS_FUNC(recvmmsg) } else { if (verbose(tcp)) { decode_mmsg(tcp, 0); + tprints(", "); /* timeout on entrance */ - tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}"); - free((void *) tcp->auxstr); + tprints(tcp->auxstr); tcp->auxstr = NULL; } if (syserror(tcp)) @@ -911,7 +909,8 @@ SYS_FUNC(recvmmsg) if (!verbose(tcp)) return 0; /* timeout on exit */ - sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]); + snprintf(str, sizeof(str), "left %s", + sprint_timespec(tcp, tcp->u_arg[4])); tcp->auxstr = str; return RVAL_STR; } diff --git a/poll.c b/poll.c index bf9707cf..4c3f19ea 100644 --- a/poll.c +++ b/poll.c @@ -169,12 +169,11 @@ decode_poll_exiting(struct tcb *tcp, const long pts) *outptr = '\0'; if (pts) { - char tmbuf[TIMESPEC_TEXT_BUFSIZE]; + const char *str = sprint_timespec(tcp, pts); - sprint_timespec(tmbuf, tcp, pts); - if (outptr + sizeof(", left ") + strlen(tmbuf) < end_outstr) { + if (outptr + sizeof(", left ") + strlen(str) < end_outstr) { outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left "); - outptr = stpcpy(outptr, tmbuf); + outptr = stpcpy(outptr, str); } else { outptr = stpcpy(outptr, ", ..."); } diff --git a/print_time.c b/print_time.c index 14765199..1e6aa760 100644 --- a/print_time.c +++ b/print_time.c @@ -56,6 +56,24 @@ MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr) print_timespec_t(&t); } +MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long addr) +{ + timespec_t t; + static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; + + if (!addr) { + strcpy(buf, "NULL"); + } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) || + umove(tcp, addr, &t)) { + snprintf(buf, sizeof(buf), "%#lx", addr); + } else { + snprintf(buf, sizeof(buf), time_fmt, + (intmax_t) t.tv_sec, (intmax_t) t.tv_nsec); + } + + return buf; +} + MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long addr) { timespec_t t[2]; diff --git a/time.c b/time.c index 209cb876..9a955251 100644 --- a/time.c +++ b/time.c @@ -102,40 +102,6 @@ sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int spec return buf + sprintf(buf, "%#lx", addr); } -void -sprint_timespec(char *buf, struct tcb *tcp, long addr) -{ - if (addr == 0) - strcpy(buf, "NULL"); - else if (!verbose(tcp)) - sprintf(buf, "%#lx", addr); - else { - int rc; - -#if SUPPORTED_PERSONALITIES > 1 - if (current_time_t_is_compat) { - struct timeval32 tv; - - rc = umove(tcp, addr, &tv); - if (rc >= 0) - sprintf(buf, "{%u, %u}", - tv.tv_sec, tv.tv_usec); - } else -#endif - { - struct timespec ts; - - rc = umove(tcp, addr, &ts); - if (rc >= 0) - sprintf(buf, "{%ju, %ju}", - (uintmax_t) ts.tv_sec, - (uintmax_t) ts.tv_nsec); - } - if (rc < 0) - strcpy(buf, "{...}"); - } -} - static void print_timezone(struct tcb *tcp, const long addr) {