[PATCH v1] tests: add fchownat.test
Dmitry V. Levin
ldv at altlinux.org
Mon Mar 14 21:34:50 UTC 2016
On Thu, Mar 10, 2016 at 03:14:22PM +0530, Anchit Jain wrote:
> +#if defined __NR_fchownat
> +
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <errno.h>
> +
> +int
> +main(void)
> +{
> + static const char fname[] = "fchownat_test_file";
> +
> + if (open(fname, O_CREAT|O_RDONLY, 0400) == -1)
> + perror_msg_and_fail("open");
> +
> + uid_t uid = getuid();
> + gid_t gid = getgid();
> +
> + if (syscall(__NR_fchownat, AT_FDCWD, fname, uid, gid, 0) != 0)
> + perror_msg_and_fail("fchownat");
Please explain why do you think a failed fchownat syscall should be
treated as a test error.
> + printf("fchownat(AT_FDCWD, \"%s\", %d, %d, 0) = 0\n", fname, uid, gid);
> +
> + if (unlink(fname) == -1)
> + perror_msg_and_fail("unlink");
> +
> + if (syscall(__NR_fchownat, AT_FDCWD, fname, uid, gid, 0) != -1)
> + perror_msg_and_fail("fchownat");
I'd suggest also to use a non-zero flags argument, e.g.
AT_SYMLINK_NOFOLLOW, in one of fchownat calls.
I think a non-zero flags argument, e.g. AT_SYMLINK_NOFOLLOW, also worths
testing.
Please check that AT_FDCWD and AT_SYMLINK_NOFOLLOW are defined -- older
libcs might not provide them.
> + printf("fchownat(AT_FDCWD, \"%s\", %d, %d, 0) = -1 ENOENT (%m)\n", fname, uid, gid);
Please wrap long lines.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160315/7eeaa3a4/attachment.bin>
More information about the Strace-devel
mailing list