]> granicus.if.org Git - strace/commitdiff
util: return string size in printstr
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 17 Sep 2017 02:58:07 +0000 (04:58 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 19 Jan 2018 22:45:34 +0000 (22:45 +0000)
As umovestr now returns something useful, let's propagate it further.

* defs.h (printstr_ex, printpathn, printpath): Change return type from
void to int.
(printstrn, printstr): Change return type from void to int, return
printstr_ex result.
* util.c (printpathn): Return -1 on NULL addr, nul_seen (exit code of
umovestr) on success.
(printpath): Return printpathn result.
(printstr_ex): Return -1 on NULL addr, umoven/umovestr result otherwise.

defs.h
util.c

diff --git a/defs.h b/defs.h
index 2311d86022dc9e768117ee42e1b9a9be31491bc8..24226a01ec3506492b0f9e4012688d7685708c8f 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -591,14 +591,14 @@ dumpiov_upto(struct tcb *, int len, kernel_ulong_t addr, kernel_ulong_t data_siz
 extern void
 dumpstr(struct tcb *, kernel_ulong_t addr, int len);
 
-extern void
+extern int
 printstr_ex(struct tcb *, kernel_ulong_t addr, kernel_ulong_t len,
            unsigned int user_style);
 
-extern void
+extern int
 printpathn(struct tcb *, kernel_ulong_t addr, unsigned int n);
 
-extern void
+extern int
 printpath(struct tcb *, kernel_ulong_t addr);
 
 #define TIMESPEC_TEXT_BUFSIZE \
@@ -720,16 +720,16 @@ extern void unwind_print_stacktrace(struct tcb *);
 extern void unwind_capture_stacktrace(struct tcb *);
 #endif
 
-static inline void
+static inline int
 printstrn(struct tcb *tcp, kernel_ulong_t addr, kernel_ulong_t len)
 {
-       printstr_ex(tcp, addr, len, 0);
+       return printstr_ex(tcp, addr, len, 0);
 }
 
-static inline void
+static inline int
 printstr(struct tcb *tcp, kernel_ulong_t addr)
 {
-       printstr_ex(tcp, addr, -1, QUOTE_0_TERMINATED);
+       return printstr_ex(tcp, addr, -1, QUOTE_0_TERMINATED);
 }
 
 static inline int
diff --git a/util.c b/util.c
index 49cb81b085d0815ae0475ed349d601a4fea60915..1ede89895b5cf2b599f8c7908ac6bf62e3bdecde 100644 (file)
--- a/util.c
+++ b/util.c
@@ -674,8 +674,10 @@ print_quoted_cstring(const char *str, unsigned int size)
 /*
  * Print path string specified by address `addr' and length `n'.
  * If path length exceeds `n', append `...' to the output.
+ *
+ * Returns the result of umovenstr.
  */
-void
+int
 printpathn(struct tcb *const tcp, const kernel_ulong_t addr, unsigned int n)
 {
        char path[PATH_MAX];
@@ -683,7 +685,7 @@ printpathn(struct tcb *const tcp, const kernel_ulong_t addr, unsigned int n)
 
        if (!addr) {
                tprints("NULL");
-               return;
+               return -1;
        }
 
        /* Cap path length to the path buffer size */
@@ -698,13 +700,15 @@ printpathn(struct tcb *const tcp, const kernel_ulong_t addr, unsigned int n)
                path[n++] = !nul_seen;
                print_quoted_cstring(path, n);
        }
+
+       return nul_seen;
 }
 
-void
+int
 printpath(struct tcb *const tcp, const kernel_ulong_t addr)
 {
        /* Size must correspond to char path[] size in printpathn */
-       printpathn(tcp, addr, PATH_MAX - 1);
+       return printpathn(tcp, addr, PATH_MAX - 1);
 }
 
 /*
@@ -714,8 +718,11 @@ printpath(struct tcb *const tcp, const kernel_ulong_t addr)
  * Pass `user_style' on to `string_quote'.
  * Append `...' to the output if either the string length exceeds `max_strlen',
  * or QUOTE_0_TERMINATED bit is set and the string length exceeds `len'.
+ *
+ * Returns the result of umovenstr if style has QUOTE_0_TERMINATED,
+ * or the result of umoven otherwise.
  */
-void
+int
 printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
            const kernel_ulong_t len, const unsigned int user_style)
 {
@@ -729,7 +736,7 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
 
        if (!addr) {
                tprints("NULL");
-               return;
+               return -1;
        }
        /* Allocate static buffers if they are not allocated yet. */
        if (!str) {
@@ -756,7 +763,7 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
 
        if (rc < 0) {
                printaddr(addr);
-               return;
+               return rc;
        }
 
        if (size > max_strlen)
@@ -775,6 +782,8 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
        tprints(outstr);
        if (ellipsis)
                tprints("...");
+
+       return rc;
 }
 
 void