2003-12-03 09:38:30 +07:00
|
|
|
/*
|
|
|
|
* namedev_parse.c
|
|
|
|
*
|
|
|
|
* Userspace devfs
|
|
|
|
*
|
2004-01-27 10:21:58 +07:00
|
|
|
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
|
2003-12-03 09:38:30 +07:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-01-13 14:08:43 +07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* define this to enable parsing debugging also */
|
2003-12-03 09:38:30 +07:00
|
|
|
/* #define DEBUG_PARSER */
|
2004-01-13 14:08:43 +07:00
|
|
|
#endif
|
2003-12-03 09:38:30 +07:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
2004-02-24 10:31:14 +07:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
2003-12-03 09:38:30 +07:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "udev.h"
|
[PATCH] add udev logging to info log
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
> Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
> Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
> Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'
Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.
If you type:
'make' - you will get a binary that prints one or two lines to syslog
if a device node is created or deleted
'make LOG=false' - you get a binary that prints asolutely nothing
'make DEBUG=true' - the same as today, it will print all debug lines
2004-01-16 12:53:20 +07:00
|
|
|
#include "logging.h"
|
2003-12-03 09:38:30 +07:00
|
|
|
#include "namedev.h"
|
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
LIST_HEAD(file_list);
|
|
|
|
|
2003-12-23 13:31:35 +07:00
|
|
|
static int add_config_dev(struct config_device *new_dev)
|
|
|
|
{
|
|
|
|
struct config_device *tmp_dev;
|
|
|
|
|
|
|
|
tmp_dev = malloc(sizeof(*tmp_dev));
|
|
|
|
if (tmp_dev == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
memcpy(tmp_dev, new_dev, sizeof(*tmp_dev));
|
|
|
|
list_add_tail(&tmp_dev->node, &config_device_list);
|
|
|
|
//dump_config_dev(tmp_dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-03 09:38:30 +07:00
|
|
|
void dump_config_dev(struct config_device *dev)
|
|
|
|
{
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
/*FIXME dump all sysfs's */
|
|
|
|
dbg_parse("name='%s', symlink='%s', bus='%s', place='%s', id='%s', "
|
|
|
|
"sysfs_file[0]='%s', sysfs_value[0]='%s', "
|
|
|
|
"kernel='%s', program='%s', result='%s'",
|
|
|
|
dev->name, dev->symlink, dev->bus, dev->place, dev->id,
|
|
|
|
dev->sysfs_pair[0].file, dev->sysfs_pair[0].value,
|
|
|
|
dev->kernel, dev->program, dev->result);
|
2003-12-03 09:38:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void dump_config_dev_list(void)
|
|
|
|
{
|
2004-01-04 23:18:16 +07:00
|
|
|
struct config_device *dev;
|
2003-12-03 09:38:30 +07:00
|
|
|
|
2004-01-04 23:18:16 +07:00
|
|
|
list_for_each_entry(dev, &config_device_list, node)
|
2003-12-03 09:38:30 +07:00
|
|
|
dump_config_dev(dev);
|
|
|
|
}
|
2003-12-04 09:33:58 +07:00
|
|
|
|
|
|
|
void dump_perm_dev(struct perm_device *dev)
|
|
|
|
{
|
|
|
|
dbg_parse("name='%s', owner='%s', group='%s', mode=%#o",
|
|
|
|
dev->name, dev->owner, dev->group, dev->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_perm_dev_list(void)
|
|
|
|
{
|
2004-01-04 23:18:16 +07:00
|
|
|
struct perm_device *dev;
|
2003-12-04 09:33:58 +07:00
|
|
|
|
2004-01-04 23:18:16 +07:00
|
|
|
list_for_each_entry(dev, &perm_device_list, node)
|
2003-12-04 09:33:58 +07:00
|
|
|
dump_perm_dev(dev);
|
|
|
|
}
|
|
|
|
|
2004-02-17 12:39:40 +07:00
|
|
|
/* extract possible KEY{attr} or KEY_attr */
|
|
|
|
static char *get_key_attribute(char *str)
|
|
|
|
{
|
|
|
|
char *pos;
|
|
|
|
char *attr;
|
|
|
|
|
|
|
|
attr = strchr(str, '{');
|
|
|
|
if (attr != NULL) {
|
|
|
|
attr++;
|
|
|
|
pos = strchr(attr, '}');
|
|
|
|
if (pos == NULL) {
|
|
|
|
dbg("missing closing brace for format");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pos[0] = '\0';
|
|
|
|
dbg("attribute='%s'", attr);
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2004-02-17 12:44:28 +07:00
|
|
|
attr = strchr(str, '_');
|
|
|
|
if (attr != NULL) {
|
|
|
|
attr++;
|
|
|
|
dbg("attribute='%s'", attr);
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2004-02-17 12:39:40 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
static int namedev_parse_rules(char *filename)
|
2003-12-03 09:38:30 +07:00
|
|
|
{
|
|
|
|
char line[255];
|
|
|
|
int lineno;
|
|
|
|
char *temp;
|
|
|
|
char *temp2;
|
|
|
|
char *temp3;
|
2004-02-17 12:39:40 +07:00
|
|
|
char *attr;
|
2003-12-03 09:38:30 +07:00
|
|
|
FILE *fd;
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
int program_given = 0;
|
2003-12-03 09:38:30 +07:00
|
|
|
int retval = 0;
|
|
|
|
struct config_device dev;
|
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
fd = fopen(filename, "r");
|
2003-12-03 16:08:46 +07:00
|
|
|
if (fd != NULL) {
|
2004-02-24 10:31:14 +07:00
|
|
|
dbg("reading '%s' as rules file", filename);
|
2003-12-03 16:08:46 +07:00
|
|
|
} else {
|
2004-02-24 10:31:14 +07:00
|
|
|
dbg("can't open '%s' as a rules file", filename);
|
2003-12-03 09:38:30 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop through the whole file */
|
|
|
|
lineno = 0;
|
|
|
|
while (1) {
|
|
|
|
/* get a line */
|
|
|
|
temp = fgets(line, sizeof(line), fd);
|
|
|
|
if (temp == NULL)
|
|
|
|
goto exit;
|
|
|
|
lineno++;
|
|
|
|
dbg_parse("read '%s'", temp);
|
|
|
|
|
2003-12-18 09:24:05 +07:00
|
|
|
/* eat the whitespace */
|
|
|
|
while (isspace(*temp))
|
|
|
|
++temp;
|
|
|
|
|
2003-12-03 09:38:30 +07:00
|
|
|
/* empty line? */
|
2003-12-30 15:54:29 +07:00
|
|
|
if ((*temp == '\0') || (*temp == '\n'))
|
2003-12-03 09:38:30 +07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* see if this is a comment */
|
|
|
|
if (*temp == COMMENT_CHARACTER)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&dev, 0x00, sizeof(struct config_device));
|
|
|
|
|
2003-12-17 14:36:19 +07:00
|
|
|
/* get all known keys */
|
|
|
|
while (1) {
|
2004-01-27 10:21:58 +07:00
|
|
|
retval = parse_get_pair(&temp, &temp2, &temp3);
|
2003-12-03 09:38:30 +07:00
|
|
|
if (retval)
|
|
|
|
break;
|
2003-12-08 00:12:07 +07:00
|
|
|
|
2003-12-17 14:36:19 +07:00
|
|
|
if (strcasecmp(temp2, FIELD_BUS) == 0) {
|
|
|
|
strfieldcpy(dev.bus, temp3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_ID) == 0) {
|
|
|
|
strfieldcpy(dev.id, temp3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_PLACE) == 0) {
|
|
|
|
strfieldcpy(dev.place, temp3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncasecmp(temp2, FIELD_SYSFS, sizeof(FIELD_SYSFS)-1) == 0) {
|
2003-12-23 13:31:35 +07:00
|
|
|
struct sysfs_pair *pair = &dev.sysfs_pair[0];
|
|
|
|
int sysfs_pair_num = 0;
|
|
|
|
|
|
|
|
/* find first unused pair */
|
|
|
|
while (pair->file[0] != '\0') {
|
|
|
|
++sysfs_pair_num;
|
|
|
|
if (sysfs_pair_num >= MAX_SYSFS_PAIRS) {
|
|
|
|
pair = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pair;
|
|
|
|
}
|
|
|
|
if (pair) {
|
2004-02-17 12:39:40 +07:00
|
|
|
attr = get_key_attribute(temp2 + sizeof(FIELD_SYSFS)-1);
|
|
|
|
if (attr == NULL) {
|
|
|
|
dbg("error parsing " FIELD_SYSFS " attribute");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strfieldcpy(pair->file, attr);
|
2003-12-23 13:31:35 +07:00
|
|
|
strfieldcpy(pair->value, temp3);
|
|
|
|
}
|
2003-12-17 14:36:19 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_KERNEL) == 0) {
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
strfieldcpy(dev.kernel, temp3);
|
2003-12-17 14:36:19 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_PROGRAM) == 0) {
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
program_given = 1;
|
|
|
|
strfieldcpy(dev.program, temp3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_RESULT) == 0) {
|
|
|
|
strfieldcpy(dev.result, temp3);
|
2003-12-17 14:36:19 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-02-17 12:44:28 +07:00
|
|
|
if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
|
|
|
|
attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
|
|
|
|
if (attr != NULL)
|
|
|
|
if (strcasecmp(attr, ATTR_PARTITIONS) == 0) {
|
|
|
|
dbg_parse("creation of partition nodes requested");
|
|
|
|
dev.partitions = PARTITIONS_COUNT;
|
|
|
|
}
|
2003-12-17 14:36:19 +07:00
|
|
|
strfieldcpy(dev.name, temp3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(temp2, FIELD_SYMLINK) == 0) {
|
2003-12-08 00:12:07 +07:00
|
|
|
strfieldcpy(dev.symlink, temp3);
|
2003-12-17 14:36:19 +07:00
|
|
|
continue;
|
|
|
|
}
|
2003-12-08 00:12:07 +07:00
|
|
|
|
2004-01-13 14:08:43 +07:00
|
|
|
dbg("unknown type of field '%s'", temp2);
|
|
|
|
dbg("You might be using a rules file in the old format, please fix.");
|
|
|
|
goto error;
|
2003-12-17 14:36:19 +07:00
|
|
|
}
|
|
|
|
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
/* simple plausibility check for given keys */
|
|
|
|
if ((dev.sysfs_pair[0].file[0] == '\0') ^
|
|
|
|
(dev.sysfs_pair[0].value[0] == '\0')) {
|
2004-02-17 12:39:40 +07:00
|
|
|
dbg("inconsistency in " FIELD_SYSFS " key");
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dev.result[0] != '\0') && (program_given == 0)) {
|
2004-02-17 12:39:40 +07:00
|
|
|
dbg(FIELD_RESULT " is only useful when "
|
|
|
|
FIELD_PROGRAM " is called in any rule before");
|
2003-12-17 14:36:19 +07:00
|
|
|
goto error;
|
2003-12-03 09:38:30 +07:00
|
|
|
}
|
|
|
|
|
[PATCH] add udev logging to info log
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
> Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
> Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
> Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'
Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.
If you type:
'make' - you will get a binary that prints one or two lines to syslog
if a device node is created or deleted
'make LOG=false' - you get a binary that prints asolutely nothing
'make DEBUG=true' - the same as today, it will print all debug lines
2004-01-16 12:53:20 +07:00
|
|
|
dev.config_line = lineno;
|
2003-12-03 09:38:30 +07:00
|
|
|
retval = add_config_dev(&dev);
|
|
|
|
if (retval) {
|
|
|
|
dbg("add_config_dev returned with error %d", retval);
|
2003-12-17 14:36:19 +07:00
|
|
|
continue;
|
[PATCH] udev - drop all methods :)
> Hi,
> as promised yesterday, here is a patch that drops the explicit methods
> given in the udev config and implement only one type of rule.
>
> A rule now consists only of a number of keys to match. All known keys
> are valid in any combination. The former configs should work with a few
> changes:
>
> o the "<METHOD>, " at the beginning of the line should be removed
>
> o the result of the externel program is matched with RESULT= instead if ID=
> the PROGRAM= key is only valid if the program exits with zero
> (just exit with nozero in a script if the rule should not match)
>
> o rules are processed in order they appear in the file, no priority
>
> o if NAME="" is given, udev is instructed to ignore this device,
> no node will be created
>
>
> EXAMPLE:
>
> # combined BUS, SYSFS and KERNEL
> BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n"
>
> # exec script only for the first ide drive (hda), all other will be skipped
> BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c"
>
>
> The udev-test.pl and test.block works fine here.
> Please adapt your config and give it a try.
>
Here is a slightly better version of the patch.
After a conversation with Patrick, we are now able to execute the PROGRAM
and also match in all following rules with the RESULT value from this exec.
EXAMPLE:
We have 7 rules with RESULT and 2 with PROGRAM.
Only the 5th rule matches with the callout result from the exec in the 4th rule.
RULES:
PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2"
KERNEL="video*", RESULT="123", NAME="web-no-3"
KERNEL="video*", RESULT="123", NAME="web-no-4"
PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5"
KERNEL="video*", RESULT="123", NAME="web-yes"
RESULT:
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM
Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123'
Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123'
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes ''
Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
2004-01-13 12:39:05 +07:00
|
|
|
error:
|
2004-01-13 14:08:43 +07:00
|
|
|
dbg("%s:%d:%d: parse error, rule skipped",
|
2004-02-24 10:31:14 +07:00
|
|
|
filename, lineno, temp - line);
|
2003-12-03 09:38:30 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
fclose(fd);
|
|
|
|
return retval;
|
2003-12-17 14:36:19 +07:00
|
|
|
}
|
2003-12-03 09:38:30 +07:00
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
static int namedev_parse_permissions(char *filename)
|
2003-12-03 09:38:30 +07:00
|
|
|
{
|
|
|
|
char line[255];
|
|
|
|
char *temp;
|
|
|
|
char *temp2;
|
|
|
|
FILE *fd;
|
|
|
|
int retval = 0;
|
2003-12-04 09:33:58 +07:00
|
|
|
struct perm_device dev;
|
2003-12-03 09:38:30 +07:00
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
fd = fopen(filename, "r");
|
2003-12-03 16:08:46 +07:00
|
|
|
if (fd != NULL) {
|
2004-02-24 10:31:14 +07:00
|
|
|
dbg("reading '%s' as permissions file", filename);
|
2003-12-03 16:08:46 +07:00
|
|
|
} else {
|
2004-02-24 10:31:14 +07:00
|
|
|
dbg("can't open '%s' as permissions file", filename);
|
2003-12-03 09:38:30 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop through the whole file */
|
|
|
|
while (1) {
|
|
|
|
temp = fgets(line, sizeof(line), fd);
|
|
|
|
if (temp == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
dbg_parse("read '%s'", temp);
|
|
|
|
|
|
|
|
/* eat the whitespace at the beginning of the line */
|
|
|
|
while (isspace(*temp))
|
|
|
|
++temp;
|
|
|
|
|
|
|
|
/* empty line? */
|
2003-12-30 15:54:29 +07:00
|
|
|
if ((*temp == '\0') || (*temp == '\n'))
|
2003-12-03 09:38:30 +07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* see if this is a comment */
|
|
|
|
if (*temp == COMMENT_CHARACTER)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&dev, 0x00, sizeof(dev));
|
|
|
|
|
|
|
|
/* parse the line */
|
|
|
|
temp2 = strsep(&temp, ":");
|
|
|
|
if (!temp2) {
|
|
|
|
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);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strncpy(dev.owner, temp2, sizeof(dev.owner));
|
|
|
|
|
|
|
|
temp2 = strsep(&temp, ":");
|
|
|
|
if (!temp2) {
|
|
|
|
dbg("cannot parse line '%s'", line);
|
|
|
|
continue;
|
|
|
|
}
|
2004-01-16 15:22:56 +07:00
|
|
|
strncpy(dev.group, temp2, sizeof(dev.group));
|
2003-12-03 09:38:30 +07:00
|
|
|
|
|
|
|
if (!temp) {
|
|
|
|
dbg("cannot parse line: %s", line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dev.mode = strtol(temp, NULL, 8);
|
|
|
|
|
|
|
|
dbg_parse("name='%s', owner='%s', group='%s', mode=%#o",
|
|
|
|
dev.name, dev.owner, dev.group,
|
|
|
|
dev.mode);
|
2003-12-04 09:33:58 +07:00
|
|
|
retval = add_perm_dev(&dev);
|
2003-12-03 09:38:30 +07:00
|
|
|
if (retval) {
|
2003-12-08 00:12:07 +07:00
|
|
|
dbg("add_perm_dev returned with error %d", retval);
|
2003-12-03 09:38:30 +07:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
fclose(fd);
|
|
|
|
return retval;
|
2004-01-22 15:54:52 +07:00
|
|
|
}
|
2003-12-03 09:38:30 +07:00
|
|
|
|
2004-02-24 10:31:14 +07:00
|
|
|
struct files {
|
|
|
|
struct list_head list;
|
|
|
|
char name[NAME_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* sort files in lexical order */
|
|
|
|
static int file_list_insert(char *filename)
|
|
|
|
{
|
|
|
|
struct files *loop_file;
|
|
|
|
struct files *new_file;
|
|
|
|
|
|
|
|
list_for_each_entry(loop_file, &file_list, list) {
|
|
|
|
if (strcmp(loop_file->name, filename) > 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_file = malloc(sizeof(struct files));
|
|
|
|
if (new_file == NULL) {
|
|
|
|
dbg("error malloc");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
strfieldcpy(new_file->name, filename);
|
|
|
|
list_add_tail(&new_file->list, &loop_file->list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calls function for file or every file found in directory */
|
|
|
|
static int call_foreach_file(int parser (char *f) , char *filename, char *extension)
|
|
|
|
{
|
|
|
|
struct dirent *ent;
|
|
|
|
DIR *dir;
|
|
|
|
char *ext;
|
|
|
|
char file[NAME_SIZE];
|
|
|
|
struct stat stats;
|
|
|
|
struct files *loop_file;
|
|
|
|
struct files *tmp_file;
|
|
|
|
|
|
|
|
/* look if we have a plain file or a directory to scan */
|
|
|
|
stat(filename, &stats);
|
|
|
|
if ((stats.st_mode & S_IFMT) != S_IFDIR)
|
|
|
|
return parser(filename);
|
|
|
|
|
|
|
|
/* sort matching filename into list */
|
|
|
|
dbg("open config as directory '%s'", filename);
|
|
|
|
dir = opendir(filename);
|
|
|
|
while (1) {
|
|
|
|
ent = readdir(dir);
|
|
|
|
if (ent == NULL || ent->d_name[0] == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
dbg("found file '%s'", ent->d_name);
|
|
|
|
ext = strrchr(ent->d_name, '.');
|
|
|
|
if (ext == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(ext, extension) == 0) {
|
|
|
|
dbg("put file in list '%s'", ent->d_name);
|
|
|
|
file_list_insert(ent->d_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse every file in the list */
|
|
|
|
list_for_each_entry_safe(loop_file, tmp_file, &file_list, list) {
|
|
|
|
strfieldcpy(file, filename);
|
|
|
|
strcat(file, loop_file->name);
|
|
|
|
parser(file);
|
|
|
|
list_del(&loop_file->list);
|
|
|
|
free(loop_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int namedev_init_rules()
|
|
|
|
{
|
|
|
|
return call_foreach_file(namedev_parse_rules, udev_rules_filename, RULEFILE_EXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int namedev_init_permissions()
|
|
|
|
{
|
|
|
|
return call_foreach_file(namedev_parse_permissions, udev_permissions_filename, PERMFILE_EXT);
|
|
|
|
}
|