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.
This commit is contained in:
Дмитрий Левин 2015-09-18 17:44:16 +00:00
parent 6c528f5502
commit 2950de3631
5 changed files with 30 additions and 48 deletions

4
defs.h
View File

@ -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);

15
net.c
View File

@ -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;
}

7
poll.c
View File

@ -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, ", ...");
}

View 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];

34
time.c
View File

@ -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)
{