Esempio n. 1
0
int
main(int argc, char *argv[])
{
	assert(argc == 2);

	static const char dir[] = "..";
	struct stat before, after;

	if (stat(".", &before))
		perror_msg_and_fail("stat");

	long rval = syscall(__NR_chdir, dir);

	if (stat(".", &after))
		perror_msg_and_fail("stat");

	if (before.st_dev != after.st_dev || before.st_ino != after.st_ino)
		error_msg_and_fail("syscall succeeded");
	if (atol(argv[1]) != rval)
		error_msg_and_fail("expected retval %s, got retval %ld",
				   argv[1], rval);

	printf("chdir(\"%s\") = %ld (INJECTED)\n", dir, rval);

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 2
0
int
main(void)
{
	const char * const fname = tail_memdup(LINKPATH, sizeof(LINKPATH));
	const char * const hex_fname =
		hexquote_strndup(fname, sizeof(LINKPATH) - 1);

	const unsigned int size = sizeof(TARGET) - 1;
	char * const buf = tail_alloc(size);

	(void) unlink(fname);

	long rc = syscall(__NR_readlink, fname, buf, size);
	printf("readlink(\"%s\", %p, %u) = -1 ENOENT (%m)\n",
	       hex_fname, buf, size);

	if (symlink(TARGET, fname))
		perror_msg_and_fail("symlink");

	rc = syscall(__NR_readlink, fname, buf, size);
	if (rc < 0) {
		perror("readlink");
		(void) unlink(fname);
		return 77;
	}
	const char * const hex_buf = hexquote_strndup(buf, size);
	printf("readlink(\"%s\", \"%s\", %u) = %u\n",
	       hex_fname, hex_buf, size, size);

	if (unlink(fname))
		perror_msg_and_fail("unlink");

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 3
0
int
main(void)
{
	static const char fname[] = "fchmod_test_file";

	int fd = open(fname, O_CREAT|O_RDONLY, 0400);

	if (fd == -1)
		perror_msg_and_fail("open");

	if (unlink(fname) == -1)
		perror_msg_and_fail("unlink");

	if (syscall(__NR_fchmod, fd, 0600) == 0) {
		close(fd);

		printf("fchmod(%d, 0600) = 0\n", fd);

		if (syscall(__NR_fchmod, fd, 0600) != -1)
			perror_msg_and_fail("fchmod");
	}
	printf("fchmod(%d, 0600) = -1 %s (%m)\n", fd, errno2name());

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 4
0
int
main(void)
{
	static const char sample[] = "fchownat_sample";
	uid_t uid = geteuid();
	uid_t gid = getegid();

	if (open(sample, O_RDONLY | O_CREAT, 0400) == -1)
		perror_msg_and_fail("open");

	long rc = syscall(__NR_fchownat, AT_FDCWD, sample, uid, gid, 0);
	printf("fchownat(AT_FDCWD, \"%s\", %d, %d, 0) = %s\n",
	       sample, uid, gid, sprintrc(rc));

	if (unlink(sample))
		perror_msg_and_fail("unlink");

	rc = syscall(__NR_fchownat, AT_FDCWD,
		     sample, -1, -1L, AT_SYMLINK_NOFOLLOW);
	printf("fchownat(AT_FDCWD, \"%s\", -1, -1, AT_SYMLINK_NOFOLLOW) = %s\n",
	       sample, sprintrc(rc));

	puts("+++ exited with 0 +++");
	return 0;
}
int
main(void)
{
	static const char sample[] = "open.sample";
	int fd = syscall(__NR_open, sample, O_RDONLY|O_CREAT, 0400);

	if (fd < 0) {
		if (errno != ENOSYS)
			perror_msg_and_fail("open");
		printf("open(\"%s\", O_RDONLY|O_CREAT, 0400)"
		       " = %d ENOSYS (%m)\n", sample, fd);
	} else {
		printf("open(\"%s\", O_RDONLY|O_CREAT, 0400) = %d\n",
		       sample, fd);
		close(fd);
		if (unlink(sample))
			perror_msg_and_fail("unlink");

		fd = syscall(__NR_open, sample, O_RDONLY);
		if (fd >= 0 || errno != ENOENT)
			perror_msg_and_fail("open");
		printf("open(\"%s\", O_RDONLY) = %d ENOENT (%m)\n",
		       sample, fd);

		fd = syscall(__NR_open, sample, O_WRONLY|O_NONBLOCK|0x80000000);
		if (fd >= 0 || errno != ENOENT)
			perror_msg_and_fail("open");
		printf("open(\"%s\", O_WRONLY|O_NONBLOCK|0x80000000)"
		       " = %d ENOENT (%m)\n", sample, fd);
	}

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 6
0
int
main(void)
{
	static sigset_t set;
	sigemptyset(&set);
	sigaddset(&set, SIGINT);
	sigaddset(&set, SIGUSR2);
	sigaddset(&set, SIGCHLD);
	sigaddset(&set, RT_0 +  3);
	sigaddset(&set, RT_0 +  4);
	sigaddset(&set, RT_0 +  5);
	sigaddset(&set, RT_0 + 26);
	sigaddset(&set, RT_0 + 27);
	if (sigprocmask(SIG_SETMASK, &set, NULL))
		perror_msg_and_fail("sigprocmask");
	sigemptyset(&set);

	static const struct sigaction sa = {
		.sa_sigaction = handler,
		.sa_flags = SA_SIGINFO
	};
	if (sigaction(SIGUSR1, &sa, NULL))
		perror_msg_and_fail("sigaction");

	if (raise(SIGUSR1))
		perror_msg_and_fail("raise");

	static const char *const sigs =
		(SIGUSR2 < SIGCHLD) ? "INT USR2 CHLD" : "INT CHLD USR2";
	static const char *const rt_sigs = "RT_3 RT_4 RT_5 RT_26 RT_27";
	printf("rt_sigreturn({mask=[%s %s]}) = 0\n", sigs, rt_sigs);

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 7
0
static void
write_pidfile(const pid_t pid)
{
	FILE *fp = fopen(pidfile, "w");
	if (!fp)
		perror_msg_and_fail("fopen: %s", pidfile);

	if (fprintf(fp, "%d", pid) < 0)
		perror_msg_and_fail("fprintf: %s", pidfile);

	if (fclose(fp))
		perror_msg_and_fail("fclose: %s", pidfile);
}
Esempio n. 8
0
static void
create_sample(void)
{
	char fname[] = TEST_SYSCALL_STR "_XXXXXX";

	(void) close(0);
	if (mkstemp(fname))
		perror_msg_and_fail("mkstemp: %s", fname);
	if (unlink(fname))
		perror_msg_and_fail("unlink: %s", fname);
	if (ftruncate(0, FILE_LEN))
		perror_msg_and_fail("ftruncate");
}
Esempio n. 9
0
int
main(void)
{
	tprintf("%s", "");

	const unsigned int big_size = 1024 / 8;
	void *k_set = tail_alloc(big_size);
	sigset_t *const libc_set = tail_alloc(sizeof(sigset_t));

	sigemptyset(libc_set);
	if (sigprocmask(SIG_SETMASK, libc_set, NULL))
		perror_msg_and_fail("sigprocmask");

	memset(k_set, 0, big_size);
	unsigned int set_size = big_size;
	for (; set_size; set_size >>= 1, k_set += set_size) {
		if (!k_sigpending(k_set, set_size))
			break;
		tprintf("rt_sigpending(%p, %u) = -1 EINVAL (%m)\n",
			k_set, set_size);
	}
	if (!set_size)
		perror_msg_and_fail("rt_sigpending");
	tprintf("rt_sigpending(%s, %u) = 0\n", "[]", set_size);

	iterate("[]", set_size >> 1, k_set + (set_size >> 1));

	void *const efault = k_set + (set_size >> 1);
	assert(k_sigpending(efault, set_size) == -1);
	tprintf("rt_sigpending(%p, %u) = -1 EFAULT (%m)\n",
		efault, set_size);

	sigaddset(libc_set, SIGHUP);
	if (sigprocmask(SIG_SETMASK, libc_set, NULL))
		perror_msg_and_fail("sigprocmask");
	raise(SIGHUP);

	iterate("[HUP]", set_size, k_set);

	sigaddset(libc_set, SIGINT);
	if (sigprocmask(SIG_SETMASK, libc_set, NULL))
		perror_msg_and_fail("sigprocmask");
	raise(SIGINT);

	iterate("[HUP INT]", set_size, k_set);

	tprintf("+++ exited with 0 +++\n");
	return 0;
}
Esempio n. 10
0
int
main(void)
{
	tprintf("%s", "");

	static char tmp[] = "preadv-pwritev-tmpfile";
	if (open(tmp, O_CREAT|O_RDONLY|O_TRUNC, 0600) != 0)
		perror_msg_and_fail("creat: %s", tmp);
	if (open(tmp, O_WRONLY) != 1)
		perror_msg_and_fail("open: %s", tmp);
	if (unlink(tmp))
		perror_msg_and_fail("unlink: %s", tmp);

	static const char w0_c[] = "012";
	const char *w0_d = hexdump_strdup(w0_c);
	void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));

	const void *efault = w0 + LENGTH_OF(w0_c);

	static const char w1_c[] = "34567";
	const char *w1_d = hexdump_strdup(w1_c);
	void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));

	static const char w2_c[] = "89abcde";
	const char *w2_d = hexdump_strdup(w2_c);
	void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));

	long rc;

	rc = pwritev(1, efault, 42, 0);
	tprintf("pwritev(1, %p, 42, 0) = %ld %s (%m)\n",
		efault, rc, errno2name());

	rc = preadv(0, efault, 42, 0);
	tprintf("preadv(0, %p, 42, 0) = %ld %s (%m)\n",
		efault, rc, errno2name());

	static const char r0_c[] = "01234567";
	const char *r0_d = hexdump_strdup(r0_c);
	static const char r1_c[] = "89abcde";
	const char *r1_d = hexdump_strdup(r1_c);

	const struct iovec w_iov_[] = {
		{
			.iov_base = w0,
			.iov_len = LENGTH_OF(w0_c)
		}, {
			.iov_base = w1,
int
main(void)
{
	tprintf("%s", "");

	int fds[2];
	if (pipe(fds))
		perror_msg_and_fail("pipe");
	assert(0 == fds[0]);
	assert(1 == fds[1]);

	static const char w0_c[] = "012";
	const char *w0_d = hexdump_strdup(w0_c);
	void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));

	static const char w1_c[] = "34567";
	const char *w1_d = hexdump_strdup(w1_c);
	void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));

	static const char w2_c[] = "89abcde";
	const char *w2_d = hexdump_strdup(w2_c);
	void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));

	const struct iovec iov_[] = {
		{
			.iov_base = w0,
			.iov_len = LENGTH_OF(w0_c)
		}, {
			.iov_base = w1,
Esempio n. 12
0
int
main(void)
{
	int sig, pid = getpid(), uid = getuid();
	const struct sigaction act = { .sa_handler = handler };
	sigset_t mask;
	sigemptyset(&mask);

	for (sig = 1; sig <= 31; sig++) {
		if (sig != SIGKILL && sig != SIGSTOP) {
			sigaction(sig, &act, NULL);
			sigaddset(&mask, sig);
		}
	}
	sigprocmask(SIG_UNBLOCK, &mask, NULL);

	for (sig = 1; sig <= 31; sig++) {
		if (sig != SIGKILL && sig != SIGSTOP) {
			if (kill(pid, sig) != 0)
				perror_msg_and_fail("kill: %d", sig);
			sig_print(signal2name(sig), pid, uid);
		}
	}

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 13
0
int
main(int argc, char *argv[])
{
#if DEBUG_PRINT
	if (argc < 3)
		error_msg_and_fail("Not enough arguments. "
				   "Usage: %s STRACE_NAME DEBUG_OUT_FD",
				   argv[0]);

	strace_name = argv[1];

	errno = 0;
	int debug_out_fd = strtol(argv[2], NULL, 0);
	if (errno)
		error_msg_and_fail("Not a number: %s", argv[2]);

	debug_out = fdopen(debug_out_fd, "a");
	if (!debug_out)
		perror_msg_and_fail("fdopen: %d", debug_out_fd);
#endif

	test_syscall(ARRAY_SIZE(syscallent));
	(void) syscallent;	/* workaround for clang bug #33068 */

#ifdef SYS_socket_subcall
	test_syscall(SYS_socket_subcall + 1);
#endif

#ifdef SYS_ipc_subcall
	test_syscall(SYS_ipc_subcall + 1);
#endif

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 14
0
static const char *
si_code_2_name(const int code)
{
	switch (code) {
#ifdef CLD_EXITED
	CASE(CLD_EXITED);
#endif
#ifdef CLD_KILLED
	CASE(CLD_KILLED);
#endif
#ifdef CLD_DUMPED
	CASE(CLD_DUMPED);
#endif
#ifdef CLD_TRAPPED
	CASE(CLD_TRAPPED);
#endif
#ifdef CLD_STOPPED
	CASE(CLD_STOPPED);
#endif
#ifdef CLD_CONTINUED
	CASE(CLD_CONTINUED);
#endif
	default:
		perror_msg_and_fail("unknown si_code %d", code);
	}
}
Esempio n. 15
0
int
main(int ac, char **av)
{
# ifdef PATH_TRACING_FD
	skip_if_unavailable("/proc/self/fd/");
# endif

	tprintf("%s", "");

	assert(syscall(__NR_poll, NULL, 42, 0) == -1);
	if (ENOSYS == errno)
		perror_msg_and_skip("poll");

# ifndef PATH_TRACING_FD
	tprintf("poll(NULL, 42, 0) = -1 EFAULT (%m)\n");
# endif

	int fds[2];
	if (pipe(fds) || pipe(fds))
		perror_msg_and_fail("pipe");

	const unsigned int abbrev = (ac > 1) ? atoi(av[1]) : -1;
	const struct pollfd pfds0[] = {
		{ .fd = 0, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND },
		{ .fd = 1, .events = POLLOUT | POLLWRNORM | POLLWRBAND },
Esempio n. 16
0
int
main(void)
{
	struct mq_attr attr;
	(void) close(0);

	char *name;
	if (asprintf(&name, "/strace-mq-%u.sample", getpid()) < 0)
		perror_msg_and_fail("asprintf");

	if (mq_open(name, O_CREAT, 0700, NULL))
		perror_msg_and_skip("mq_open");
	printf("mq_open(\"%s\", O_RDONLY|O_CREAT, 0700, NULL) = 0\n", name + 1);

	if (mq_getattr(0, &attr))
		perror_msg_and_skip("mq_getattr");
	printf("mq_getsetattr(0, NULL, {mq_flags=0, mq_maxmsg=%lld"
	       ", mq_msgsize=%lld, mq_curmsgs=0}) = 0\n",
	       (long long) attr.mq_maxmsg,
	       (long long) attr.mq_msgsize);

	if (mq_setattr(0, &attr, NULL))
		perror_msg_and_skip("mq_setattr");
	printf("mq_getsetattr(0, {mq_flags=0, mq_maxmsg=%lld"
	       ", mq_msgsize=%lld, mq_curmsgs=0}, NULL) = 0\n",
	       (long long) attr.mq_maxmsg,
	       (long long) attr.mq_msgsize);

	if (mq_unlink(name))
		perror_msg_and_skip("mq_unlink");
	printf("mq_unlink(\"%s\") = 0\n", name + 1);

	puts("+++ exited with 0 +++");
	return 0;
}
int
main(void)
{
	struct statfs stb;
	if (statfs("/proc/self/status", &stb))
		perror_msg_and_fail("statfs");
	return 0;
}
Esempio n. 18
0
static void
wait_for_peer_invocation(void)
{
	/* wait for the lock directory to be created by peer */
	while (rmdir(lockdir)) {
		if (ENOENT != errno)
			perror_msg_and_fail("rmdir: %s", lockdir);
	}
}
Esempio n. 19
0
int
main(void)
{
	const off_t offset = 0xdefaceddeadbeefLL;
	char *buf = tail_alloc(LEN);
	struct iovec *iov = tail_alloc(sizeof(*iov));
	iov->iov_base = buf;
	iov->iov_len = LEN;

	(void) close(0);
	if (open("/dev/zero", O_RDONLY))
		perror_msg_and_fail("open");

	if (preadv(0, iov, 1, offset) != LEN)
		perror_msg_and_fail("preadv");
	printf("preadv(0, ");
	print_iovec(iov, 1);
	printf(", 1, %lld) = %u\n", (long long) offset, LEN);

	if (preadv(0, iov, 1, -1) != -1)
		perror_msg_and_fail("preadv");
	printf("preadv(0, [{iov_base=%p, iov_len=%zu}], 1, -1) = "
	       "-1 EINVAL (%m)\n", iov->iov_base, iov->iov_len);

	if (preadv(0, NULL, 1, -2) != -1)
		perror_msg_and_fail("preadv");
	printf("preadv(0, NULL, 1, -2) = -1 EINVAL (%m)\n");

	if (preadv(0, iov, 0, -3) != -1)
		perror_msg_and_fail("preadv");
	printf("preadv(0, [], 0, -3) = -1 EINVAL (%m)\n");

	static const char tmp[] = "preadv-tmpfile";
	int fd = open(tmp, O_RDWR | O_CREAT | O_TRUNC, 0600);
	if (fd < 0)
		perror_msg_and_fail("open");
	if (unlink(tmp))
		perror_msg_and_fail("unlink");

	static const char w[] = "0123456789abcde";
	if (write(fd, w, LENGTH_OF(w)) != LENGTH_OF(w))
		perror_msg_and_fail("write");

	static const char r0_c[] = "01234567";
	static const char r1_c[] = "89abcde";

	const unsigned int r_len = (LENGTH_OF(w) + 1) / 2;
	void *r0 = tail_alloc(r_len);
	const struct iovec r0_iov_[] = {
		{
			.iov_base = r0,
			.iov_len = r_len
		}
	};
Esempio n. 20
0
int
main(void)
{
	(void) close(0);
	(void) close(1);
	int *const fds = tail_alloc(sizeof(*fds) * 2);
	if (pipe(fds))
		perror_msg_and_fail("pipe");

	return 0;
}
static int
process(void)
{
	int i;
	int fds[2];
	pthread_t t;
	struct timespec ts = { .tv_nsec = 10000000 };

	(void) close(0);
	(void) close(1);
	if (pipe(fds))
		perror_msg_and_fail("pipe");

	for (i = 0; i < T; ++i)
		assert(pthread_create(&t, NULL, thread, NULL) == 0);
	for (i = 0; i < T; ++i)
		assert(read(0, fds, 1) == 1);

	(void) nanosleep(&ts, 0);
	return 0;
}

int
main(void)
{
	int i, s;
	pid_t p;

	for (i = 0; i < P; ++i) {
		p = fork();
		if (p < 0)
			perror_msg_and_fail("fork");
		if (p == 0)
			return process();
		assert(waitpid(p, &s, 0) == p);
		assert(WIFEXITED(s));
		if (WEXITSTATUS(s))
			return WEXITSTATUS(s);
	}
	return 0;
}
Esempio n. 22
0
int
main(void)
{
	unsigned int ugid = GETUGID;
	CHECK_OVERFLOWUGID(ugid);

	const struct {
		const long r, e, s;
	} tests[] = {
		{ ugid, ugid, ugid },
		TRIPLE((unsigned long) 0xffffffff00000000ULL | ugid),
		TRIPLE(-1U),
		TRIPLE(-1L),
		TRIPLE(0xffff0000U | ugid),
		TRIPLE(0xffff),
		TRIPLE(0xc0deffffU)
	};

	unsigned int i;

	for (i = 0; i < ARRAY_SIZE(tests); ++i) {
		const unsigned int rn = ugid2int(tests[i].r);
		const unsigned int en = ugid2int(tests[i].e);
		const unsigned int sn = ugid2int(tests[i].s);

		if (!num_matches_id(rn, ugid) ||
		    !num_matches_id(en, ugid) ||
		    !num_matches_id(sn, ugid))
			continue;

		if (syscall(SYSCALL_NR, tests[i].r, tests[i].e, tests[i].s)) {
			if (!i && ENOSYS == errno) {
				printf("%s(%u, %u, %u) = -1 ENOSYS (%m)\n",
				       SYSCALL_NAME, ugid, ugid, ugid);
				break;
			}
			perror_msg_and_fail("%s(%#lx, %#lx, %#lx)",
					    SYSCALL_NAME,
					    tests[i].r, tests[i].e, tests[i].s);
		}

		printf("%s(", SYSCALL_NAME);
		print_int(rn);
		printf(", ");
		print_int(en);
		printf(", ");
		print_int(sn);
		printf(") = 0\n");
	}

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 23
0
int
main(int ac, char **av)
{
	if (ac < 3)
		error_msg_and_fail("usage: block_reset_raise_run signo path...");

	sigset_t mask;
	sigemptyset(&mask);
	const int signo = atoi(av[1]);
	if (sigaddset(&mask, signo))
		perror_msg_and_fail("sigaddset: %s", av[1]);
	if (sigprocmask(SIG_BLOCK, &mask, NULL))
		perror_msg_and_fail("sigprocmask");
	if (signal(signo, SIG_DFL) == SIG_ERR)
		perror_msg_and_fail("signal: %s", av[1]);
	if (raise(signo))
		perror_msg_and_fail("raise: %s", av[1]);

	execvp(av[2], av + 2);
	perror_msg_and_fail("execvp: %s", av[2]);
}
Esempio n. 24
0
static void
test_sig(int signo, const char *name)
{
	const struct sigaction act = { .sa_handler = handler };

	if (sigaction(signo, &act, NULL))
		perror_msg_and_fail("sigaction: %d", signo);

	sigset_t mask;
	sigemptyset(&mask);
	sigaddset(&mask, signo);
	if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
		perror_msg_and_fail("sigprocmask: %d", signo);

	if (kill(pid, signo))
		perror_msg_and_fail("kill(%d, %d)", pid, signo);

	if (name && *name)
		printf("--- %s {si_signo=%s, si_code=SI_USER"
		       ", si_pid=%d, si_uid=%d} ---\n",
		       name, name, pid, uid);
}
Esempio n. 25
0
File: mmap.c Progetto: glebfm/strace
int
main(void)
{
	const intmax_t pagesize = get_page_size();
	const unsigned long length = pagesize * 3;
	const int fd = -1;
	off_t offset;
	void *addr, *p;

#if ULONG_MAX > 4294967295UL
	offset = 0xcafedeadbeef000 & -pagesize;
	addr = (void *) (uintmax_t) (0xfacefeed000 & -pagesize);
#else
	offset = 0xdeadbeef000 & -pagesize;
	addr = (void *) (unsigned int) (0xfaced000 & -pagesize);
#endif

	p = mmap(addr, length, PROT_READ | PROT_WRITE,
		 MAP_PRIVATE | MAP_ANONYMOUS, fd, offset);
	if (MAP_FAILED == p)
		perror_msg_and_fail("mmap");
	if (mprotect(p, length, PROT_NONE))
		perror_msg_and_fail("mprotect");
	if (munmap(p, length))
		perror_msg_and_fail("munmap");

	if (sizeof(offset) == sizeof(int))
		printf("mmap2?\\(%p, %lu, PROT_READ\\|PROT_WRITE, "
		       "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#x\\) = %p\n",
		       addr, length, fd, (unsigned int) offset, p);
	else
		printf("(mmap2?|old_mmap)\\(%p, %lu, PROT_READ\\|PROT_WRITE, "
		       "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#jx\\) = %p\n",
		       addr, length, fd, (uintmax_t) offset, p);
	printf("mprotect\\(%p, %lu, PROT_NONE\\) += 0\n", p, length);
	printf("munmap\\(%p, %lu\\) += 0\n", p, length);
	return 0;
}
Esempio n. 26
0
static void
dumpio(void)
{
	static char tmp[] = "preadv2-pwritev2-tmpfile";
	if (open(tmp, O_CREAT|O_RDONLY|O_TRUNC, 0600) != 0)
		perror_msg_and_fail("creat: %s", tmp);
	if (open(tmp, O_WRONLY) != 1)
		perror_msg_and_fail("open: %s", tmp);
	if (unlink(tmp))
		perror_msg_and_fail("unlink: %s", tmp);

	static const char w0_c[] = "012";
	const char *w0_d = hexdump_strdup(w0_c);
	void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));

	static const char w1_c[] = "34567";
	const char *w1_d = hexdump_strdup(w1_c);
	void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));

	static const char w2_c[] = "89abcde";
	const char *w2_d = hexdump_strdup(w2_c);
	void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));

	long rc;

	static const char r0_c[] = "01234567";
	const char *r0_d = hexdump_strdup(r0_c);
	static const char r1_c[] = "89abcde";
	const char *r1_d = hexdump_strdup(r1_c);

	const struct iovec w_iov_[] = {
		{
			.iov_base = w0,
			.iov_len = LENGTH_OF(w0_c)
		}, {
			.iov_base = w1,
Esempio n. 27
0
int
main(void)
{
	(void) close(0);
	(void) close(1);
	int fds[2];
	if (pipe(fds))
		perror_msg_and_fail("pipe");

	(void) close(0);
	(void) close(1);
	if (pipe2(fds, O_NONBLOCK))
		perror_msg_and_skip("pipe2");

	return 0;
}
Esempio n. 28
0
int
main(void)
{
	long rc;

	/* check how the first argument is decoded */
	ngroups = syscall(SYSCALL_NR, 0, 0);
	printf("%s(0, NULL) = %ld\n", SYSCALL_NAME, ngroups);
	if (ngroups < 0)
		perror_msg_and_fail(SYSCALL_NAME);

	rc = syscall(SYSCALL_NR, (long) 0xffffffff00000000ULL, 0);
	printf("%s(0, NULL) = %ld\n", SYSCALL_NAME, rc);

	rc = syscall(SYSCALL_NR, -1U, 0);
	printf("%s(%u, NULL) = %s\n", SYSCALL_NAME, -1U, sprintrc(rc));

	rc = syscall(SYSCALL_NR, -1L, 0);
	printf("%s(%u, NULL) = %s\n", SYSCALL_NAME, -1U, sprintrc(rc));

	const unsigned int ngroups_max = sysconf(_SC_NGROUPS_MAX);

	rc = syscall(SYSCALL_NR, ngroups_max, 0);
	printf("%s(%u, NULL) = %s\n", SYSCALL_NAME, ngroups_max, sprintrc(rc));

	rc = syscall(SYSCALL_NR, (long) 0xffffffff00000000ULL | ngroups_max, 0);
	printf("%s(%u, NULL) = %s\n", SYSCALL_NAME, ngroups_max, sprintrc(rc));

	/* check how the second argument is decoded */
	GID_TYPE *const g1 =
		tail_alloc(ngroups ? sizeof(*g1) * ngroups : 1);
	GID_TYPE *const g2 = tail_alloc(sizeof(*g2) * (ngroups + 1));
	void *efault = g2 + ngroups + 1;

	get_groups(ngroups, g1);
	get_groups(ngroups + 1, g1);
	get_groups(ngroups + 1, g2);

	if (ngroups) {
		rc = syscall(SYSCALL_NR, ngroups, efault);
		printf("%s(%u, %p) = %s\n",
		       SYSCALL_NAME, (unsigned) ngroups, efault, sprintrc(rc));
	}

	puts("+++ exited with 0 +++");
	return 0;
}
Esempio n. 29
0
static unsigned int
get_sigset_size(void)
{
	const unsigned int big_size = 1024 / 8;
	unsigned int set_size;

	for (set_size = big_size; set_size; set_size >>= 1) {
		if (!syscall(__NR_rt_sigprocmask, SIG_SETMASK,
			     NULL, NULL, set_size))
			break;
	}

	if (!set_size)
		perror_msg_and_fail("rt_sigprocmask");

	return set_size;
}
Esempio n. 30
0
static void
get_groups(const long size, GID_TYPE *const g)
{
	long i = syscall(SYSCALL_NR, size, g);
	if (i != ngroups)
		perror_msg_and_fail("%s(%#lx, %p)", SYSCALL_NAME, size, g);

	printf("%s(%u, [", SYSCALL_NAME, (unsigned) size);
	for (i = 0; i < ngroups; ++i) {
		if (i)
			printf(", ");
		if (i >= MAX_STRLEN) {
			printf("...");
			break;
		}
		printf("%u", (unsigned int) g[i]);
	}
	printf("]) = %ld\n", ngroups);
}