05.03.2016, 03:12, "Dmitry V. Levin" <l...@altlinux.org>: > On Fri, Mar 04, 2016 at 08:45:48PM +0000, Anchit Jain wrote: > [...] >> +#include "tests.h" >> +#include <assert.h> > > As you no longer use assert, no need to include <assert.h>. > >> +#include <fcntl.h> >> +#include <stdio.h> >> +#include <unistd.h> >> +#include <errno.h> >> +#include <sys/syscall.h> >> + >> +#if defined __NR_chmod > > The only two headers that have to be included before __NR_chmod test > are "tests.h" and <sys/syscall.h>. > > In case you are in pedantic mood, all the rest could be included > after __NR_chmod test, like in tests/alarm.c and many similar tests. > >> + >> +int >> +main(void) >> +{ >> + static const char fname[] = "chmod_test_file"; >> + int fd = open(fname, O_CREAT|O_RDONLY, 0400); >> + >> + if (fd == -1) >> + perror_msg_and_fail("open"); >> + >> + if (syscall(__NR_chmod, fname, 0600) != 0) >> + { > > The opening brace should be placed on "if" line. > >> + if (errno == ENOSYS) >> + perror_msg_and_fail("chmod ENOSYS"); > > If chmod has failed with ENOSYS, it might be a normal condition > on some architectures, so it shouldn't be treated as a test error. > Just print it using > > printf("chmod(\"%s\", 0600) = -1 ENOENT (%m)\n", fname);
But the test should not continue after this, so if I replace "perror_msg_and_fail" with "printf" test would eventually get failed by "perror_msg_and_fail" in the next line. So how should I exit/skip the test here without printing to stderr? > >> + perror_msg_and_fail("chmod"); >> + } >> + printf("chmod(\"%s\", 0600) = 0\n", fname); >> + int ret = unlink(fname); >> + if (ret == -1) >> + perror_msg_and_fail("unlink"); > > No need to save return value if there are no plans to use it. > The idiom for this kind of checks is > > if (unlink(fname)) > perror_msg_and_fail("unlink"); > > -- > ldv > , > > ------------------------------------------------------------------------------ > , > > _______________________________________________ > Strace-devel mailing list > Strace-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/strace-devel -- Sincerely, Anchit Jain mailingl...@anchitja.in ------------------------------------------------------------------------------ _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel