more trivial cleanups
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
logging.c +7 -7
@@ -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 ; }
namedev.c +15 -15
@@ -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; }
namedev.h +1 -2
@@ -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 ];
udev-add.c +10 -12
@@ -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; } -
udev-remove.c +4 -4
@@ -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;
udev.c +5 -6
@@ -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; } -
udev.h +0 -1
@@ -95,4 +95,3 @@extern char udev_config_filename[PATH_MAX +NAME_MAX ];#endif -
udevdb.c +7 -7
@@ -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 ;
udevdb.h +3 -3
@@ -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);
namedev.c +1 -1
@@ -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' :
test/udev-test.pl +9 -0
@@ -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",
udev.8 +10 -10
@@ -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