All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] bug in sensors.d reading: not all
Date: Fri, 05 Jun 2009 13:40:23 +0000	[thread overview]
Message-ID: <20090605154023.607b62bd@hyperion.delvare> (raw)
In-Reply-To: <h09l4i$sdc$1@ger.gmane.org>

Hi Yuriy,

On Fri, 05 Jun 2009 03:25:06 +0400, Yuriy Kaminskiy wrote:
> Hello!
>   Most filesystems (in particular - reiserfs, jfs, xfs, nfs); maybe,
> some legacy installation of ext2/3 too) always return dirent->dt_type > DT_UNKNOWN, so libsensors fails to parse /etc/sensors.d.
>   Also, symlink (DT_LNK) can point to directory, or FIFO/socket/device
> (very bad!) - current check insufficient anyways.
>   I've attached [somewhat hackerish] patch to solve both problem.
> == cut !man 3 readdir => Currently,  only  some  file systems (among them: ext2, etx3, and ext4)
> have full support returning the file type in d_type.  All  applications
> must properly handle a return of DT_UNKNOWN.
> == cut =
Thanks for reporting, I had totally missed the fact that not all
filesystems implemented this interface.

>   Maybe, it would be better to remove dt_type check and use stat() always.

Yes, I think so. I don't much like the complexity of your proposed
solution. The problem is simple, it should have a simple solution.
Performance isn't critical for this part of the code, what matters is
robustness and readability.

What about the simplified version below?

Index: lib/init.c
=================================--- lib/init.c	(révision 5729)
+++ lib/init.c	(copie de travail)
@@ -23,12 +23,14 @@
 #define _BSD_SOURCE
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <locale.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <dirent.h>
+#include <unistd.h>
 #include "sensors.h"
 #include "data.h"
 #include "error.h"
@@ -120,8 +122,7 @@
 
 static int config_file_filter(const struct dirent *entry)
 {
-	return (entry->d_type = DT_REG || entry->d_type = DT_LNK)
-	    && entry->d_name[0] != '.';		/* Skip hidden files */
+	return entry->d_name[0] != '.';		/* Skip hidden files */
 }
 
 static int add_config_from_dir(const char *dir)
@@ -143,6 +144,7 @@
 		int len;
 		char path[PATH_MAX];
 		FILE *input;
+		struct stat st;
 
 		len = snprintf(path, sizeof(path), "%s/%s", dir,
 			       namelist[i]->d_name);
@@ -151,6 +153,10 @@
 			continue;
 		}
 
+		/* Only accept regular files */
+		if (stat(path, &st) < 0 || !S_ISREG(st.st_mode))
+			continue;
+
 		input = fopen(path, "r");
 		if (input) {
 			res = parse_config(input, path);


-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

  reply	other threads:[~2009-06-05 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 23:25 [lm-sensors] [PATCH] bug in sensors.d reading: not all filesystems Yuriy Kaminskiy
2009-06-05 13:40 ` Jean Delvare [this message]
2009-06-05 14:30 ` [lm-sensors] [PATCH] bug in sensors.d reading: not all Yuriy Kaminskiy
2009-06-05 15:19 ` Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090605154023.607b62bd@hyperion.delvare \
    --to=khali@linux-fr.org \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.