]> granicus.if.org Git - strace/blobdiff - xattr.c
Move ioctl syscall parser to ioctl.c
[strace] / xattr.c
diff --git a/xattr.c b/xattr.c
index 42c9be8ff3e8ce0e810dab59d6ce0862ef52d315..5fbdec88de93f1a5c1fd81db35c030a2fec94649 100644 (file)
--- a/xattr.c
+++ b/xattr.c
@@ -1,10 +1,7 @@
 #include "defs.h"
 
-#ifdef HAVE_LINUX_XATTR_H
-# include <linux/xattr.h>
-#else
-# define XATTR_CREATE 1
-# define XATTR_REPLACE 2
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
 #endif
 
 #include "xlat/xattrflags.h"
@@ -15,44 +12,46 @@ print_xattr_val(struct tcb *tcp, int failed,
                unsigned long insize,
                unsigned long size)
 {
+       char *buf;
+       unsigned int len;
+
        if (insize == 0)
-               failed = 1;
-       if (!failed) {
-               unsigned long capacity = 4 * size + 1;
-               unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
-               if (buf == NULL || /* probably a bogus size argument */
-                       umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
-                       failed = 1;
-               }
-               else {
-                       unsigned char *out = buf;
-                       unsigned char *in = &buf[3 * size];
-                       size_t i;
-                       for (i = 0; i < size; ++i) {
-                               if (in[i] >= ' ' && in[i] <= 0x7e)
-                                       *out++ = in[i];
-                               else {
-#define tohex(n) "0123456789abcdef"[n]
-                                       *out++ = '\\';
-                                       *out++ = 'x';
-                                       *out++ = tohex(in[i] / 16);
-                                       *out++ = tohex(in[i] % 16);
-                               }
-                       }
-                       /* Don't print terminating NUL if there is one.  */
-                       if (i > 0 && in[i - 1] == '\0')
-                               out -= 4;
-                       *out = '\0';
-                       tprintf(", \"%s\", %ld", buf, insize);
-               }
+               goto failed;
+
+       len = size;
+       if (size != (unsigned long) len)
+               goto failed;
+
+       if (!len) {
+               tprintf(", \"\", %ld", insize);
+               return;
+       }
+
+       buf = malloc(len);
+       if (!buf)
+               goto failed;
+
+       if (umoven(tcp, arg, len, buf) < 0) {
                free(buf);
+               goto failed;
        }
-       if (failed)
-               tprintf(", 0x%lx, %ld", arg, insize);
+
+       /* Don't print terminating NUL if there is one. */
+       if (buf[len - 1] == '\0')
+               --len;
+
+       tprints(", ");
+       print_quoted_string(buf, len, 0);
+       tprintf(", %ld", insize);
+
+       free(buf);
+       return;
+
+failed:
+       tprintf(", 0x%lx, %ld", arg, insize);
 }
 
-int
-sys_setxattr(struct tcb *tcp)
+SYS_FUNC(setxattr)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
@@ -65,8 +64,7 @@ sys_setxattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_fsetxattr(struct tcb *tcp)
+SYS_FUNC(fsetxattr)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
@@ -79,8 +77,7 @@ sys_fsetxattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_getxattr(struct tcb *tcp)
+SYS_FUNC(getxattr)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
@@ -93,8 +90,7 @@ sys_getxattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_fgetxattr(struct tcb *tcp)
+SYS_FUNC(fgetxattr)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
@@ -125,8 +121,7 @@ print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
        tprintf(", %lu", size);
 }
 
-int
-sys_listxattr(struct tcb *tcp)
+SYS_FUNC(listxattr)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
@@ -137,8 +132,7 @@ sys_listxattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_flistxattr(struct tcb *tcp)
+SYS_FUNC(flistxattr)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
@@ -149,8 +143,7 @@ sys_flistxattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_removexattr(struct tcb *tcp)
+SYS_FUNC(removexattr)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
@@ -160,8 +153,7 @@ sys_removexattr(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_fremovexattr(struct tcb *tcp)
+SYS_FUNC(fremovexattr)
 {
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);