2004-08-30  Roland McGrath  <roland@redhat.com>

	* file.c (print_xattr_val): New function to show attribute values.
	(sys_setxattr, sys_fsetxattr, sys_getxattr, sys_fgetxattr): Use it.
	From Ulrich Drepper <drepper@redhat.com>.
	Fixes RH#131177.
diff --git a/file.c b/file.c
index 294a97e..ed10644 100644
--- a/file.c
+++ b/file.c
@@ -2335,6 +2335,37 @@
 	{ 0,		 NULL }
 };
 
+static void
+print_xattr_val(tcp, failed, arg, insize, size)
+struct tcb *tcp;
+int failed;
+unsigned long arg;
+size_t size;
+{
+    unsigned char buf[4 * size + 1];
+    if (!failed && umoven(tcp, arg, size, &buf[3 * size]) >= 0) {
+	unsigned char *out = buf;
+	unsigned char *in = &buf[3 * size];
+	size_t i;
+	for (i = 0; i < size; ++i)
+	    if (isprint(in[i]))
+		*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 (in[i - 1] == '\0')
+	    out -= 4;
+	*out = '\0';
+	tprintf(", \"%s\", %zd", buf, insize);
+    } else
+	tprintf(", 0x%lx, %zd", arg, insize);
+}
+
 int
 sys_setxattr(tcp)
 struct tcb *tcp;
@@ -2343,8 +2374,8 @@
 	printpath(tcp, tcp->u_arg[0]);
 	tprintf(", ");
 	printstr(tcp, tcp->u_arg[1], -1);
-	/* XXX Print value in format */
-	tprintf(", %p, %ld, ", (void *) tcp->u_arg[2], tcp->u_arg[3]);
+	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
+	tprintf(", ");
 	printflags(xattrflags, tcp->u_arg[4]);
     }
     return 0;
@@ -2357,8 +2388,8 @@
     if (entering(tcp)) {
 	tprintf("%ld, ", tcp->u_arg[0]);
 	printstr(tcp, tcp->u_arg[1], -1);
-	/* XXX Print value in format */
-	tprintf(", %p, %ld, ", (void *) tcp->u_arg[2], tcp->u_arg[3]);
+	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
+	tprintf(", ");
 	printflags(xattrflags, tcp->u_arg[4]);
     }
     return 0;
@@ -2373,8 +2404,8 @@
 	tprintf(", ");
 	printstr(tcp, tcp->u_arg[1], -1);
     } else {
-	/* XXX Print value in format */
-	tprintf(", %p, %ld", (void *) tcp->u_arg[2], tcp->u_arg[3]);
+	print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
+			tcp->u_rval);
     }
     return 0;
 }
@@ -2387,8 +2418,8 @@
 	tprintf("%ld, ", tcp->u_arg[0]);
 	printstr(tcp, tcp->u_arg[1], -1);
     } else {
-	/* XXX Print value in format */
-	tprintf(", %p, %ld", (void *) tcp->u_arg[2], tcp->u_arg[3]);
+	print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
+			tcp->u_rval);
     }
     return 0;
 }