Eliminate code duplication in time printing, reduce a few static buffers
text data bss dec hex filename
238454 664 28772 267890 41672 strace.before
238106 664 28676 267446 414b6 strace
* defs.h: Add TIMESPEC_TEXT_BUFSIZE and TIMEVAL_TEXT_BUFSIZE defines.
Add 'int special' parameter to sprinttv().
* time.c (sprinttv): Add 'int special' parameter, and use it
similarly to 'int special' parameter of printtv_bitness().
(printtv_bitness): Use sprinttv() instead of duplicating its code.
(print_timespec): Use sprint_timespec() instead of duplicating
its code.
* desc.c (decode_select): Use TIMEVAL_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.
* net.c (sys_recvmsg): Use TIMESPEC_TEXT_BUFSIZE instead of 128
for static buffer size.
* stream.c (decode_poll): Use TIMESPEC_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/net.c b/net.c
index 4e8df10..67acfb8 100644
--- a/net.c
+++ b/net.c
@@ -1753,12 +1753,16 @@
int
sys_recvmmsg(struct tcb *tcp)
{
- static char str[128];
- if (entering(tcp)) {
+ /* +5 chars are for "left " prefix */
+ static char str[5 + TIMESPEC_TEXT_BUFSIZE];
+ if (entering(tcp)) {
tprintf("%ld, ", tcp->u_arg[0]);
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.
+ */
tcp->auxstr = strdup(str);
} else {
tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
@@ -1790,8 +1794,7 @@
if (!verbose(tcp))
return 0;
/* timeout on exit */
- strcpy(str, "left ");
- sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
+ sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
tcp->auxstr = str;
return RVAL_STR;
}