diff mbox

[3/5] read_config: don't try to open file beginning with '.'

Message ID aa79e6cff5121994d60fb10315ce54e5a2dc63af.1301562707.git.ydroneaud@opteya.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yann Droneaud March 31, 2011, 9:29 a.m. UTC
None

Comments

Roland Dreier May 31, 2011, 6:42 p.m. UTC | #1
On Thu, Mar 31, 2011 at 2:29 AM, Yann Droneaud <ydroneaud@opteya.com> wrote:
> Files beginning with a dot are mostly current and parent directories or,
> by convention, hidden files.
>
> Those path are skipped in find_sysfs_dev().

Not sure we want to do this. We already skip non-regular files, and
I'm not sure we want to exclude certain file names.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yann Droneaud May 31, 2011, 9:23 p.m. UTC | #2
Hi,

Le mardi 31 mai 2011 à 11:42 -0700, Roland Dreier a écrit :
> On Thu, Mar 31, 2011 at 2:29 AM, Yann Droneaud <ydroneaud@opteya.com> wrote:
> > Files beginning with a dot are mostly current and parent directories or,
> > by convention, hidden files.
> >
> > Those path are skipped in find_sysfs_dev().
> 
> Not sure we want to do this. We already skip non-regular files, and
> I'm not sure we want to exclude certain file names.

For example, while testing libibverbs config parsing, I've used emacs to
edit drivers file. And, when emacs open a buffer, it create a lock file
with a leading dot.

So running a libibverbs program prints
libibverbs: Warning: couldn't stat config file
'/tmp/ib/etc/libibverbs.d/.#test'.

Here's a strace output:

open("/tmp/ib/etc/libibverbs.d", O_RDONLY|O_NONBLOCK|O_DIRECTORY|
O_CLOEXEC) = 3
getdents(3, /* 3 entries */, 32768)     = 80
stat("/tmp/ib/etc/libibverbs.d/.#test", 0x7fffe11e8c60) = -1 ENOENT (No
such file or directory)
write(2, "libibverbs: Warning: couldn't st"..., 82) = 82
stat("/tmp/ib/etc/libibverbs.d/.", {st_mode=S_IFDIR|0775,
st_size=4096, ...}) = 0
stat("/tmp/ib/etc/libibverbs.d/..", {st_mode=S_IFDIR|0775,
st_size=4096, ...}) = 0
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0


Skipping that "normally" hidden file seems a good behavior. Same thing
for those backup files with ~ suffix.

It's mostly harmless, but code which load dynamic modules makes me a
little angry :)

For example, directory libibverbs.d should be owned by root with write
limited write permission, likewise for the driver files.

Regards.
diff mbox

Patch

diff --git a/src/init.c b/src/init.c
index bdc1634..46ff24c 100644
--- a/src/init.c
+++ b/src/init.c
@@ -308,6 +308,9 @@  static void read_config(void)
 	while ((dent = readdir(conf_dir))) {
 		struct stat buf;
 
+		if (dent->d_name[0] == '.')
+			continue;
+
 		if (asprintf(&path, "%s/%s", IBV_CONFIG_DIR, dent->d_name) < 0) {
 			fprintf(stderr, PFX "Warning: couldn't read config file %s/%s.\n",
 				IBV_CONFIG_DIR, dent->d_name);