linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [udev] more trivial cleanups
@ 2003-11-24 13:08 Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2003-11-24 13:08 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]

Hi Greg,
here are four remaining patches for udev.
You see 007 is in so good shape now, that I have nothing more exciting :)

It's a trivial whitespace/debug text cleanup, a simple format char simplification,
a new test for udev-test.pl and a man page roundup.

I've added the textual id example for udev.permissions back to the man page,
cause it's working now and mentioned klibc as the exception not glibc.
Please have a look if this is fine with you.

thanks,
Kay


01-overall-whitespace+debug-text-conditioning.diff
  o cleanup whitespace
  o clarify a few comments
  o enclose all printed debug string values in ''

02-namedev.c-strcat-tweak.diff
  o cat the substitution to the already known end of the string instead of searching it another time

03-udev-test.pl-add-subdir-test.diff
  o duplicate existing test and change it to explicitely test the subdir handling

04-udev.8-tweak-numeric-id-text.diff
  o change "return value" to "returned string"
  o add textual owner/group example for udev.permissions
  o mention klibc compile as special case for udev.permissions
  o remove duplicated numeric owner clause

[-- Attachment #2: 01-overall-whitespace+debug-text-conditioning.diff --]
[-- Type: text/plain, Size: 11439 bytes --]

diff -Nru a/logging.c b/logging.c
--- a/logging.c	Mon Nov 24 13:52:18 2003
+++ b/logging.c	Mon Nov 24 13:52:18 2003
@@ -32,26 +32,26 @@
 static int logging_init = 0;
 static unsigned char udev_logname[42];
 
-static void init_logging (void)
+static void init_logging(void)
 {
-	snprintf(udev_logname,42,"udev[%d]", getpid());
+	snprintf(udev_logname, 42,"udev[%d]", getpid());
 
-	openlog (udev_logname, 0, LOG_DAEMON);
+	openlog(udev_logname, 0, LOG_DAEMON);
 	logging_init = 1;
 }
 
 /**
  * log_message - sends a message to the logging facility
  */
-int log_message (int level, const char *format, ...)
+int log_message(int level, const char *format, ...)
 {
 	va_list	args;
 
 	if (!logging_init)
 		init_logging();
-	va_start (args, format);
-	vsyslog (level, format, args);
-	va_end (args);
+	va_start(args, format);
+	vsyslog(level, format, args);
+	va_end(args);
 	return 1;
 }
 
diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Mon Nov 24 13:52:18 2003
+++ b/namedev.c	Mon Nov 24 13:52:18 2003
@@ -216,10 +216,10 @@
 	int retval = 0;
 	struct config_device dev;
 
-	dbg("opening %s to read as config", udev_config_filename);
+	dbg("opening '%s' to read as config", udev_config_filename);
 	fd = fopen(udev_config_filename, "r");
 	if (fd == NULL) {
-		dbg("can't open %s", udev_config_filename);
+		dbg("can't open '%s'", udev_config_filename);
 		return -ENODEV;
 	}
 
@@ -232,7 +232,7 @@
 			goto exit;
 		lineno++;
 
-		dbg_parse("read %s", temp);
+		dbg_parse("read '%s'", temp);
 
 		/* eat the whitespace at the beginning of the line */
 		while (isspace(*temp))
@@ -413,10 +413,10 @@
 	int retval = 0;
 	struct config_device dev;
 
-	dbg("opening %s to read as permissions config", udev_config_permission_filename);
+	dbg("opening '%s' to read as permissions config", udev_config_permission_filename);
 	fd = fopen(udev_config_permission_filename, "r");
 	if (fd == NULL) {
-		dbg("can't open %s", udev_config_permission_filename);
+		dbg("can't open '%s'", udev_config_permission_filename);
 		return -ENODEV;
 	}
 
@@ -426,7 +426,7 @@
 		if (temp == NULL)
 			break;
 
-		dbg_parse("read %s", temp);
+		dbg_parse("read '%s'", temp);
 
 		/* eat the whitespace at the beginning of the line */
 		while (isspace(*temp))
@@ -445,21 +445,21 @@
 		/* parse the line */
 		temp2 = strsep(&temp, ":");
 		if (!temp2) {
-			dbg("cannot parse line: %s", line);
+			dbg("cannot parse line '%s'", line);
 			continue;
 		}
 		strncpy(dev.name, temp2, sizeof(dev.name));
 
 		temp2 = strsep(&temp, ":");
 		if (!temp2) {
-			dbg("cannot parse line: %s", line);
+			dbg("cannot parse line '%s'", line);
 			continue;
 		}
 		strncpy(dev.owner, temp2, sizeof(dev.owner));
 
 		temp2 = strsep(&temp, ":");
 		if (!temp2) {
-			dbg("cannot parse line: %s", line);
+			dbg("cannot parse line '%s'", line);
 			continue;
 		}
 		strncpy(dev.group, temp2, sizeof(dev.owner));
@@ -496,7 +496,7 @@
 	while (isdigit(*(dig-1)))
 		dig--;
 	strfieldcpy(udev->kernel_number, dig);
-	dbg("kernel_number = %s", udev->kernel_number);
+	dbg("kernel_number='%s'", udev->kernel_number);
 }
 
 static void apply_format(struct udevice *udev, unsigned char *string)
@@ -608,7 +608,7 @@
 				break;
 			buffer[res] = '\0';
 			if (res > len) {
-				dbg("callout len %d too short\n", len);
+				dbg("callout len %d too short", len);
 				retval = -1;
 			}
 			if (value_set) {
@@ -660,7 +660,7 @@
 			strfieldcpy(udev->group, dev->group);
 		}
 		dbg_parse("callout returned matching value '%s', '%s' becomes '%s'"
-			  " - owner='%s', group='%s', mode =%#o",
+			  " - owner='%s', group='%s', mode=%#o",
 			  dev->id, class_dev->name, udev->name,
 			  dev->owner, dev->group, dev->mode);
 		return 0;
@@ -884,11 +884,11 @@
 		 * up in the kernel...
 		 */
 		if (strstr(class_dev->path, "block")) {
-			dbg_parse("looking at block device...");
+			dbg_parse("looking at block device");
 			if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
 				char path[SYSFS_PATH_MAX];
 
-				dbg_parse("really is a partition...");
+				dbg_parse("really is a partition");
 				strfieldcpy(path, class_dev->path);
 				temp = strrchr(path, '/');
 				*temp = 0x00;
@@ -897,7 +897,7 @@
 				if (class_dev_parent == NULL) {
 					dbg("sysfs_open_class_device at '%s' failed", path);
 				} else {
-					dbg_parse("class_dev_parent->name=%s", class_dev_parent->name);
+					dbg_parse("class_dev_parent->name='%s'", class_dev_parent->name);
 					if (class_dev_parent->sysdevice)
 						sysfs_device = class_dev_parent->sysdevice;
 				}
diff -Nru a/namedev.h b/namedev.h
--- a/namedev.h	Mon Nov 24 13:52:18 2003
+++ b/namedev.h	Mon Nov 24 13:52:18 2003
@@ -50,7 +50,6 @@
 	struct list_head node;
 
 	enum config_type type;
-
 	char bus[BUS_SIZE];
 	char sysfs_file[FILE_SIZE];
 	char sysfs_value[VALUE_SIZE];
@@ -58,7 +57,7 @@
 	char place[PLACE_SIZE];
 	char kernel_name[NAME_SIZE];
 	char exec_program[FILE_SIZE];
-	
+
 	/* what to set the device to */
 	char name[NAME_SIZE];
 	char owner[OWNER_SIZE];
diff -Nru a/udev-add.c b/udev-add.c
--- a/udev-add.c	Mon Nov 24 13:52:18 2003
+++ b/udev-add.c	Mon Nov 24 13:52:18 2003
@@ -60,12 +60,12 @@
 	if (dev == NULL)
 		goto exit;
 
-	dbg("dev = %s", dev);
+	dbg("dev='%s'", dev);
 
 	if (sscanf(dev, "%u:%u", &udev->major, &udev->minor) != 2)
 		goto exit;
 
-	dbg("found major = %d, minor = %d", udev->major, udev->minor);
+	dbg("found major=%d, minor=%d", udev->major, udev->minor);
 
 	retval = 0;
 exit:
@@ -129,7 +129,7 @@
 					    path, strerror(errno));
 					return retval;
 				}
-				dbg("created %s", path);
+				dbg("created '%s'", path);
 			}
 			*pos = '/';
 		}
@@ -155,7 +155,7 @@
 		else {
 			struct passwd *pw = getpwnam(dev->owner);
 			if (!pw)
-				dbg("user unknown: %s", dev->owner);
+				dbg("user unknown '%s'", dev->owner);
 			else
 				uid = pw->pw_uid;
 		}
@@ -169,7 +169,7 @@
 		else {
 			struct group *gr = getgrnam(dev->group);
 			if (!gr)
-				dbg("group unknown: %s", dev->group);
+				dbg("group unknown '%s'", dev->group);
 			else
 				gid = gr->gr_gid;
 		}
@@ -194,7 +194,7 @@
 	strcpy(dev_path, sysfs_path);
 	strcat(dev_path, device_name);
 
-	dbg("looking at %s", dev_path);
+	dbg("looking at '%s'", dev_path);
 
 	/* open up the sysfs class device for this thing... */
 	class_dev = sysfs_open_class_device(dev_path);
@@ -202,7 +202,7 @@
 		dbg ("sysfs_open_class_device failed");
 		goto exit;
 	}
-	dbg("class_dev->name = %s", class_dev->name);
+	dbg("class_dev->name='%s'", class_dev->name);
 
 exit:
 	return class_dev;
@@ -225,13 +225,12 @@
 	while (loop--) {
 		struct stat buf;
 
-		dbg("looking for %s", filename);
+		dbg("looking for '%s'", filename);
 		retval = stat(filename, &buf);
 		if (!retval)
 			goto exit;
 
-		/* sleep for a second or two to give the kernel a chance to
-		 * create the dev file */
+		/* sleep to give the kernel a chance to create the dev file */
 		sleep(1);
 	}
 	retval = -ENODEV;
@@ -276,7 +275,7 @@
 		dbg("udevdb_add_dev failed, but we are going to try to create the node anyway. "
 		    "But remove might not work properly for this device.");
 
-	dbg("name = %s", dev.name);
+	dbg("name='%s'", dev.name);
 	retval = create_node(&dev);
 
 exit:
@@ -285,4 +284,3 @@
 
 	return retval;
 }
-
diff -Nru a/udev-remove.c b/udev-remove.c
--- a/udev-remove.c	Mon Nov 24 13:52:18 2003
+++ b/udev-remove.c	Mon Nov 24 13:52:18 2003
@@ -52,14 +52,14 @@
 		goto exit;
 	}
 
-	dbg("%s not found in database, falling back on default name", path);
+	dbg("'%s' not found in database, falling back on default name", path);
 	temp = strrchr(path, '/');
 	if (temp == NULL)
 		return NULL;
 	strncpy(name, &temp[1], sizeof(name));
 
 exit:
-	dbg("name is %s", name);
+	dbg("name is '%s'", name);
 	return &name[0];
 }
 
@@ -74,7 +74,7 @@
 	strncpy(filename, udev_root, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
 
-	dbg("unlinking %s", filename);
+	dbg("unlinking '%s'", filename);
 	retval = unlink(filename);
 	if (retval) {
 		dbg("unlink(%s) failed with error '%s'",
@@ -104,7 +104,7 @@
 				    filename, strerror(errno));
 				break;
 			}
-			dbg("removed %s", filename);
+			dbg("removed '%s'", filename);
 		}
 	}
 	return retval;
diff -Nru a/udev.c b/udev.c
--- a/udev.c	Mon Nov 24 13:52:18 2003
+++ b/udev.c	Mon Nov 24 13:52:18 2003
@@ -105,7 +105,7 @@
 		if (temp)
 			udev_permission = temp;
 	}
-	dbg("sysfs_path = %s", sysfs_path);
+	dbg("sysfs_path='%s'", sysfs_path);
 
 	strncpy(udev_db_filename, udev_config_dir, sizeof(udev_db_filename));
 	strncat(udev_db_filename, udev_db, sizeof(udev_db_filename));
@@ -141,12 +141,12 @@
 		dbg ("no devpath?");
 		goto exit;
 	}
-	dbg("looking at %s", devpath);
+	dbg("looking at '%s'", devpath);
 
 	/* we only care about class devices and block stuff */
 	if (!strstr(devpath, "class") &&
 	    !strstr(devpath, "block")) {
-		dbg("not block or class");
+		dbg("not a block or class device");
 		goto exit;
 	}
 
@@ -166,7 +166,7 @@
 	get_dirs();
 	retval = udevdb_init(UDEVDB_DEFAULT);
 	if (retval != 0) {
-		dbg("Unable to initialize database.");
+		dbg("unable to initialize database");
 		goto exit;
 	}
 
@@ -180,7 +180,7 @@
 		retval = udev_remove_device(devpath, subsystem);
 
 	else {
-		dbg("Unknown action: %s", action);
+		dbg("unknown action '%s'", action);
 		retval = -EINVAL;
 	}
 	udevdb_exit();
@@ -188,4 +188,3 @@
 exit:	
 	return retval;
 }
-
diff -Nru a/udev.h b/udev.h
--- a/udev.h	Mon Nov 24 13:52:18 2003
+++ b/udev.h	Mon Nov 24 13:52:18 2003
@@ -95,4 +95,3 @@
 extern char udev_config_filename[PATH_MAX+NAME_MAX];
 
 #endif
-
diff -Nru a/udevdb.c b/udevdb.c
--- a/udevdb.c	Mon Nov 24 13:52:18 2003
+++ b/udevdb.c	Mon Nov 24 13:52:18 2003
@@ -54,7 +54,7 @@
 	strcpy(keystr, path);
 	key.dptr = keystr;
 	key.dsize = strlen(keystr) + 1;
-	
+
 	data.dptr = (void *)dev;
 	data.dsize = sizeof(*dev);
 	
@@ -79,7 +79,7 @@
 	dev = malloc(sizeof(*dev));
 	if (dev == NULL)
 		goto exit;
-	
+
 	memcpy(dev, data.dptr, sizeof(*dev));
 exit:
 	free(data.dptr);
@@ -99,7 +99,7 @@
 
 	key.dptr = keystr;
 	key.dsize = strlen(keystr) + 1;
-	
+
 	return tdb_delete(udevdb, key);
 }
 
@@ -116,8 +116,8 @@
 
 /**
  * udevdb_init: initializes database
- * @init_flag: database can either be in memory - UDEVDB_INTERNAL - or
- *	written to a file with UDEVDB_DEFAULT.
+ * @init_flag: UDEVDB_INTERNAL - database stays in memory
+ *	       UDEVDB_DEFAULT - database is written to a file
  */
 int udevdb_init(int init_flag)
 {
@@ -127,9 +127,9 @@
 	udevdb = tdb_open(udev_db_filename, 0, init_flag, O_RDWR | O_CREAT, 0644);
 	if (udevdb == NULL) {
 		if (init_flag == UDEVDB_INTERNAL)
-			dbg("Unable to initialize in-memory database");
+			dbg("unable to initialize in-memory database");
 		else
-			dbg("Unable to initialize database at %s", udev_db_filename);
+			dbg("unable to initialize database at '%s'", udev_db_filename);
 		return -EINVAL;
 	}
 	return 0;
diff -Nru a/udevdb.h b/udevdb.h
--- a/udevdb.h	Mon Nov 24 13:52:18 2003
+++ b/udevdb.h	Mon Nov 24 13:52:18 2003
@@ -5,10 +5,10 @@
 #define _UDEVDB_H_
 
 /* Udevdb initialization flags */
-#define UDEVDB_DEFAULT	0	/* Defaults database to use file */
-#define UDEVDB_INTERNAL	1	/* Don't store db on disk, use in memory */
+#define UDEVDB_DEFAULT	0	/* defaults database to use file */
+#define UDEVDB_INTERNAL	1	/* don't store db on disk, use in memory */
 
-/* Function Prototypes */
+/* function prototypes */
 extern void udevdb_exit(void);
 extern int udevdb_init(int init_flag);
 

[-- Attachment #3: 02-namedev.c-strcat-tweak.diff --]
[-- Type: text/plain, Size: 342 bytes --]

diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Mon Nov 24 12:50:08 2003
+++ b/namedev.c	Mon Nov 24 12:50:08 2003
@@ -514,7 +514,7 @@
 			case 'b':
 				if (strlen(udev->bus_id) == 0)
 					break;
-				strcat(string, udev->bus_id);
+				strcat(pos, udev->bus_id);
 				dbg("substitute bus_id '%s'", udev->bus_id);
 				break;
 			case 'n':

[-- Attachment #4: 03-udev-test.pl-add-subdir-test.diff --]
[-- Type: text/plain, Size: 516 bytes --]

diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl	Mon Nov 24 12:52:01 2003
+++ b/test/udev-test.pl	Mon Nov 24 12:52:01 2003
@@ -60,6 +60,15 @@
 EOF
 	},
 	{
+		desc     => "subdirectory handling",
+		subsys   => "tty",
+		devpath  => "class/tty/ttyUSB0",
+		expected => "sub/direct/ory/visor" ,
+		conf     => <<EOF
+REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
+EOF
+	},
+	{
 		desc     => "place on bus of scsi partition",
 		subsys   => "block",
 		devpath  => "block/sda/sda3",

[-- Attachment #5: 04-udev.8-tweak-numeric-id-text.diff --]
[-- Type: text/plain, Size: 1396 bytes --]

diff -Nru a/udev.8 b/udev.8
--- a/udev.8	Mon Nov 24 12:52:45 2003
+++ b/udev.8	Mon Nov 24 12:52:45 2003
@@ -104,7 +104,8 @@
 the bus id for the device
 .TP
 .B %c
-the CALLOUT program return value (this does not work within the PROGRAM field for the obvious reason.)
+the CALLOUT program returned string
+(this does not work within the PROGRAM field for the obvious reason.)
 .RE
 .P
 A sample \fIudev.conf\fP might look like this:
@@ -134,26 +135,25 @@
 The file consists of a set of lines. All empty lines and
 lines beginning with a '#' will be ignored.
 .br
-Every line lists a device name followed by numeric owner, group and permission
+Every line lists a device name followed by owner, group and permission
 mode. All values are separated by colons. The name field may end with a
 wildcard to apply the values to a whole class of devices.
 .br
-If udev was built using glibc, string owner and group names may be used.
+If
+.B udev
+was built using klibc or is used before the user database is accessible (e.g.
+.B initrd
+), only numeric string owner and group names may be used.
 .sp
 A sample \fIudev.permissions\fP might look like this:
 .sp
 .nf
 #name:user:group:mode
+input/*:root:root:644
 ttyUSB1:0:8:0660
-video*:500:500:0660
+video*:root:video:0660
 dsp1:::0666
 .fi
-.P
-If 
-.B
-udev
-was built using glibc, string owner and group names may be used.
-
 .SH "FILES"
 .nf
 .ft B

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [udev] more trivial cleanups
@ 2003-11-24 22:33 Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2003-11-24 22:33 UTC (permalink / raw)
  To: linux-hotplug

On Mon, Nov 24, 2003 at 02:08:05PM +0100, Kay Sievers wrote:
> Hi Greg,
> here are four remaining patches for udev.
> You see 007 is in so good shape now, that I have nothing more exciting :)
> 
> It's a trivial whitespace/debug text cleanup, a simple format char simplification,
> a new test for udev-test.pl and a man page roundup.
> 
> I've added the textual id example for udev.permissions back to the man page,
> cause it's working now and mentioned klibc as the exception not glibc.
> Please have a look if this is fine with you.

These all look fine.  I've applied them all.

thanks,

greg k-h


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-11-24 22:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-24 22:33 [udev] more trivial cleanups Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2003-11-24 13:08 Kay Sievers

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).