Re: [PATCH] rfim: add new test for verifying RFIM sysfs interface

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Hi!
> > +static void check_read_only(const char *path)
> > +{
> > +	tst_res(TDEBUG, "Checking whether %s is read-only", path);
> > +
> > +	if (access(path, F_OK)) {
> > +		tst_res(TFAIL | TERRNO, "%s does not exist", path);
> > +		return;
> > +	}
> > +
> > +	int fd = open(path, O_RDONLY);
> > +
> > +	if (fd == -1) {
> > +		tst_res(TFAIL | TERRNO, "%s can't be read", path);
> > +		return;
> > +	}
> > +	close(fd);
> > +
> > +	fd = open(path, O_WRONLY);
> > +	if (fd != -1) {
> > +		close(fd);
> > +		tst_res(TFAIL, "%s is writable", path);
> > +		return;
> > +	}
> > +
> > +	tst_res(TPASS, "%s is read-only", path);
> > +}
> 
> This function can be easily replaced by access().
> 
> TST_EXP_PASS(access(path, R_OK));
> TST_EXP_FAIL(access(path, W_OK), ..);

This depends on where the error from kernel is supposed to be returned
from. For files that are generated by kernel such as /sys/ and /proc/
the permission bits can be all enabled but you may still get EPERM when
you actually open the file and kernel decides that this file shouldn't
be readable in the open() syscall handler for the particular file.

-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.