10 #include <sys/types.h>
11 #include <sys/xattr.h>
12 #include <sys/socket.h>
20 #define ERROR(err, ...) \
22 do_log(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
28 do_log(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
37 static void do_log(const char *file, int line, const char *func, const char *fmt, ...)
44 len = vasprintf(&message, fmt, args);
50 printf("%s:%d(%s): %s\n", file, line, func, message);
54 static int run_child(const char *path, int fd)
60 c = (getpid() % 10) + 48;
62 ret = setxattr(path, "user.test", &c, 1, 0);
65 "setxattr failed: %s\n",
69 /* Tell parent what we wrote */
70 nwritten = write(fd, &c, 1);
80 static int run_parent(const char *path)
93 ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
95 ERROR(ERR_SYSCALL, "socketpair failed: %s\n", strerror(errno));
100 ERROR(ERR_SYSCALL, "fork failed: %s\n", strerror(errno));
104 return run_child(path, fds[1]);
110 /* Read expected value from child */
111 nread = read(child_fd, &expected, 1);
116 /* Wait for the child to go away*/
117 nread = read(child_fd, &expected, 1);
119 ERROR(ERR_CALL, "Non-0 read\n");
125 nread = getxattr(path, "user.test", &got, 1);
128 "getxattr failed: %s\n",
132 printf("expected: %c, got: %c\n", expected, got);
133 if (expected != got) {
135 "Expected: %c, got: %c\n",
145 int main(int argc, char **argv)
152 ERROR(ERR_USAGE, "Usage: %s <PATH>\n", argv[0]);
156 sa = (struct sigaction) {
157 .sa_handler = SIG_IGN,
158 .sa_flags = SA_NOCLDWAIT,
161 ret = sigaction(SIGCHLD, &sa, NULL);
163 ERROR(ERR_SYSCALL, "sigaction failed: %s\n", strerror(errno));
167 return run_parent(path);