linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@access.unizh.ch>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH RFC] Merge udev_scan_block() and udev_scan_class() in udevstart.c
Date: Sun, 05 Jun 2005 13:00:16 +0000	[thread overview]
Message-ID: <20050605130015.GA4640@access.unizh.ch> (raw)

udev_scan_block() and udev_scan_class() in udevstart.c have a lot of
redundant code and therefor I was thinking about a way to merge them.
My patch might not be the most elegant solution but it reduces the code
about 40 lines (see diffstat).

Comments, Flames etc are welcome.

Cheers, Tobias


 udevstart.c |   71 ++++++++++++------------------------------------------------
 1 files changed, 15 insertions(+), 56 deletions(-)

--- udev-058/udevstart.c	2005-05-20 22:18:28.000000000 +0200
+++ udev-058~tk/udevstart.c	2005-06-05 13:44:28.218251600 +0200
@@ -204,14 +204,14 @@ static int has_devt(const char *director
 	return 0;
 }
 
-static void udev_scan_block(void)
+static void udev_scan_dir(char *type)
 {
 	char base[PATH_SIZE];
 	DIR *dir;
 	struct dirent *dent;
 	LIST_HEAD(device_list);
 
-	snprintf(base, sizeof(base), "%s/block", sysfs_path);
+	snprintf(base, sizeof(base), "%s/%s", sysfs_path, type);
 	base[sizeof(base)-1] = '\0';
 
 	dir = opendir(base);
@@ -227,56 +227,10 @@ static void udev_scan_block(void)
 			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
 			dirname[sizeof(dirname)-1] = '\0';
 			if (has_devt(dirname))
-				device_list_insert(dirname, "block", &device_list);
+				device_list_insert(dirname, type, &device_list);
 			else
 				continue;
 
-			/* look for partitions */
-			dir2 = opendir(dirname);
-			if (dir2 != NULL) {
-				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
-					char dirname2[PATH_SIZE];
-
-					if (dent2->d_name[0] = '.')
-						continue;
-
-					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
-					dirname2[sizeof(dirname2)-1] = '\0';
-
-					if (has_devt(dirname2))
-						device_list_insert(dirname2, "block", &device_list);
-				}
-				closedir(dir2);
-			}
-		}
-		closedir(dir);
-	}
-	exec_list(&device_list);
-}
-
-static void udev_scan_class(void)
-{
-	char base[PATH_SIZE];
-	DIR *dir;
-	struct dirent *dent;
-	LIST_HEAD(device_list);
-
-	snprintf(base, sizeof(base), "%s/class", sysfs_path);
-	base[sizeof(base)-1] = '\0';
-
-	dir = opendir(base);
-	if (dir != NULL) {
-		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-			char dirname[PATH_SIZE];
-			DIR *dir2;
-			struct dirent *dent2;
-
-			if (dent->d_name[0] = '.')
-				continue;
-
-			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
-			dirname[sizeof(dirname)-1] = '\0';
-
 			dir2 = opendir(dirname);
 			if (dir2 != NULL) {
 				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
@@ -288,11 +242,16 @@ static void udev_scan_class(void)
 					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
 					dirname2[sizeof(dirname2)-1] = '\0';
 
-					/* pass the net class as it is */
-					if (strcmp(dent->d_name, "net") = 0)
-						device_list_insert(dirname2, "net", &device_list);
-					else if (has_devt(dirname2))
-						device_list_insert(dirname2, dent->d_name, &device_list);
+					if (strncmp(type, "block", 5) = 0) {
+						if (has_devt(dirname2))
+							device_list_insert(dirname2, type, &device_list);
+					} else if (strncmp(type, "class", 5) = 0) {
+						/* pass the net class as it is */
+						if (strcmp(dent->d_name, "net") = 0)
+							device_list_insert(dirname2, "net", &device_list);
+						else if (has_devt(dirname2))
+							device_list_insert(dirname2, dent->d_name, &device_list);
+					}
 				}
 				closedir(dir2);
 			}
@@ -342,8 +301,8 @@ int main(int argc, char *argv[], char *e
 
 	udev_rules_init();
 
-	udev_scan_block();
-	udev_scan_class();
+	udev_scan_dir("block");
+	udev_scan_dir("class");
 
 	logging_close();
 	return 0;


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r 
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

             reply	other threads:[~2005-06-05 13:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-05 13:00 Tobias Klauser [this message]
2005-06-05 22:01 ` [PATCH RFC] Merge udev_scan_block() and udev_scan_class() in udevstart.c Kay Sievers
2005-06-06 16:24 ` Tobias Klauser

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=20050605130015.GA4640@access.unizh.ch \
    --to=tklauser@access.unizh.ch \
    --cc=linux-hotplug@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).