[PATCH v3] tests: add fchmod.test

Dmitry V. Levin ldv at altlinux.org
Thu Mar 10 01:45:46 UTC 2016


On Thu, Mar 10, 2016 at 01:32:28AM +0000, Fabien Siron wrote:
[...]
> +	int fchmod_res = syscall(__NR_fchmod, fd, 0600);
> +
> +	close(fd);

This call may clobber errno, so I'd rather move it inside fchmod_res == 0
branch.  As the file is already unlinked, it's perfectly OK to "leak" this
descriptor in case of fchmod_res != 0.  BTW, do you really need fchmod_res?

> +	if (fchmod_res == 0) {
> +		printf("fchmod(%d, 0600) = 0\n", fd);
> +
> +		if (syscall(__NR_fchmod, fd, 0600) != -1)
> +			perror_msg_and_fail("fchmod");
> +
> +		printf("fchmod(%d, 0600) = -1 EBADF (Bad file descriptor)\n",
> +		       fd);
> +	} else {
> +		if (errno == ENOSYS) {
> +			printf("fchmod(%d, 0600) = -1 ENOSYS (%m)\n", fd);
> +		} else {
> +			perror_msg_and_fail("fchmod");
> +		}
> +	}


-- 
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/20160310/8c360ff6/attachment.bin>


More information about the Strace-devel mailing list