]> granicus.if.org Git - strace/commitdiff
Convert another parser of struct timespec to new mpers infrastructure
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 18 Sep 2015 17:44:16 +0000 (17:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Sep 2015 01:04:49 +0000 (04:04 +0300)
* 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.

defs.h
net.c
poll.c
print_time.c
time.c

diff --git a/defs.h b/defs.h
index 826ab94005ba32682223f907ed187c6b3d9d489b..9b9a105d723cef3b7297604826df1f6447ff9082 100644 (file)
--- 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 40b5a5c3f6d31294a2dae66f3a69d176a474337d..7e8586ac69795eb19586c6b3e34bf91dbb0929a4 100644 (file)
--- 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 bf9707cf03b6febb6719983a534830eff186ff83..4c3f19ead995d2ffbaf0b5ac71ddd45073be2f89 100644 (file)
--- 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, ", ...");
                }
index 147651996605e2719c5cef35ef264246a9eae31a..1e6aa76001cb9dfed33a64f638ba35bd6d9d7f2c 100644 (file)
@@ -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 209cb8763568a551d9403eaf014bda256886b8e8..9a955251013ac9f33bc79a7383feeacf72221916 100644 (file)
--- 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)
 {