* [PATCH] support directory for rules and permissions
@ 2004-02-22 9:45 Andrey Borzenkov
2004-02-22 10:17 ` Marco d'Itri
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Andrey Borzenkov @ 2004-02-22 9:45 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 759 bytes --]
On Mon, Feb 16, 2004 at 02:34:33PM -0800, Greg KH wrote:
> On Sat, Jan 17, 2004 at 11:13:00PM +0300, Andrey Borzenkov wrote:
> > Attached patch adds support for
> >
> > - multiple rules files. You can now do
> >
> > udev_rules="file1 dir2 file3 ..."
>
> Care to fix this patch up for the latest udev release?
>
This is new version that I have been runing for some time. It does not
directly support multiple files; rather you can give either file or
directory; directory is scanned, sorted and all files are read in order.
KLIBC case still supports single file only; I do not think anything more
complicated will be needed for initrd.
The only reason for first patch was to ensure config files order and it
is not done automatically.
regards
-andrey
[-- Attachment #2: udev018_config_dir.patch --]
[-- Type: text/plain, Size: 5329 bytes --]
--- udev-018/namedev.c.multi 2004-02-19 21:38:37.000000000 +0300
+++ udev-018/namedev.c 2004-02-21 21:57:19.350887008 +0300
@@ -807,12 +807,12 @@ int namedev_name_device(struct sysfs_cla
if (match_rule(dev, class_dev, udev, sysfs_device) == 0) {
if (dev->name[0] == '\0') {
info("configured rule in '%s' at line %i applied, '%s' is ignored",
- udev_rules_filename, dev->config_line, udev->kernel_name);
+ dev->config_file, dev->config_line, udev->kernel_name);
return -1;
}
info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
- udev_rules_filename, dev->config_line, udev->kernel_name, dev->name);
+ dev->config_file, dev->config_line, udev->kernel_name, dev->name);
strfieldcpy(udev->name, dev->name);
strfieldcpy(udev->symlink, dev->symlink);
goto found;
--- udev-018/namedev.h.multi 2004-02-19 21:38:35.000000000 +0300
+++ udev-018/namedev.h 2004-02-21 21:54:58.000000000 +0300
@@ -71,6 +71,7 @@ struct config_device {
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
int partitions;
int config_line;
+ char *config_file;
};
struct perm_device {
--- udev-018/namedev_parse.c.multi 2004-02-19 21:38:35.000000000 +0300
+++ udev-018/namedev_parse.c 2004-02-21 21:47:48.000000000 +0300
@@ -34,6 +34,8 @@
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
+#include <dirent.h>
+#include <sys/stat.h>
#include "udev.h"
#include "logging.h"
@@ -114,7 +116,7 @@ static char *get_key_attribute(char *str
return NULL;
}
-int namedev_init_rules(void)
+static int parse_rules_file(const char *file)
{
char line[255];
int lineno;
@@ -126,15 +128,19 @@ int namedev_init_rules(void)
int program_given = 0;
int retval = 0;
struct config_device dev;
+ char *p;
- fd = fopen(udev_rules_filename, "r");
+ fd = fopen(file, "r");
if (fd != NULL) {
- dbg("reading '%s' as rules file", udev_rules_filename);
+ dbg("reading '%s' as rules file", file);
} else {
- dbg("can't open '%s' as a rules file", udev_rules_filename);
+ dbg("can't open '%s' as a rules file", file);
return -ENODEV;
}
+ /* Yes, this is memory leak. It won't be freed */
+ p = strdup(file);
+
/* loop through the whole file */
lineno = 0;
while (1) {
@@ -256,13 +262,14 @@ int namedev_init_rules(void)
}
dev.config_line = lineno;
+ dev.config_file = p;
retval = add_config_dev(&dev);
if (retval) {
dbg("add_config_dev returned with error %d", retval);
continue;
error:
dbg("%s:%d:%d: parse error, rule skipped",
- udev_rules_filename, lineno, temp - line);
+ file, lineno, temp - line);
}
}
exit:
@@ -270,7 +277,7 @@ exit:
return retval;
}
-int namedev_init_permissions(void)
+static int parse_permissions_file(const char *file)
{
char line[255];
char *temp;
@@ -279,11 +286,11 @@ int namedev_init_permissions(void)
int retval = 0;
struct perm_device dev;
- fd = fopen(udev_permissions_filename, "r");
+ fd = fopen(file, "r");
if (fd != NULL) {
- dbg("reading '%s' as permissions file", udev_permissions_filename);
+ dbg("reading '%s' as permissions file", file);
} else {
- dbg("can't open '%s' as permissions file", udev_permissions_filename);
+ dbg("can't open '%s' as permissions file", file);
return -ENODEV;
}
@@ -350,5 +357,108 @@ int namedev_init_permissions(void)
exit:
fclose(fd);
return retval;
+}
+
+static int ends_with(const char *name, const char *suf)
+{
+ char *p = strstr(name, suf);
+
+ if (!p)
+ return 0;
+
+ if (p[strlen(suf)])
+ return 0;
+
+ return 1;
}
+/*
+ * skip
+ * all hidden files
+ * usual backup files from editor or RPM
+ * non-plain files
+ */
+static int filter(const struct dirent *dirent)
+{
+ char *name = dirent->d_name;
+
+ if (name[0] == '.')
+ return 0;
+
+ if (ends_with(name, ".rpmorig") ||
+ ends_with(name, ".rpmsave") ||
+ ends_with(name, ".rpmnew") ||
+ ends_with(name, "~") ||
+ ends_with(name, ".orig"))
+ return 0;
+
+ return 1;
+}
+
+static int parse_rules(char *file, int (*func)(const char *))
+{
+ struct stat buf;
+ int err = 0;
+
+
+ if (stat(file, &buf) == -1) {
+ err = errno;
+ dbg("parse_rules: can't stat %s", file);
+ return errno;
+ }
+
+ if (S_ISREG(buf.st_mode))
+ return (*func)(file);
+
+#ifndef __KLIBC__
+ if (S_ISDIR(buf.st_mode)) {
+ struct dirent **dirents = 0;
+ int nfiles, i;
+
+ if ((nfiles = scandir(file, &dirents, filter, alphasort)) == -1) {
+ err = errno;
+ dbg("parse_rules: scandir '%s' error", file);
+ return err;
+ }
+
+ for (i = 0; i < nfiles; i++) {
+ char temp[PATH_MAX + NAME_MAX];
+
+ snprintf(temp, sizeof(temp), "%s/%s", file, dirents[i]->d_name);
+ free(dirents[i]);
+
+ if (stat(temp, &buf) == -1) {
+ dbg("parse_rules: cannot stat '%s'", temp);
+ continue;
+ }
+
+ if (!S_ISREG(buf.st_mode)) {
+ dbg("parse_rules: not a regular file '%s'", temp);
+ continue;
+ }
+
+ err = (*func)(temp);
+ if (err)
+ return err;
+ }
+
+ free(dirents);
+
+ return 0;
+ }
+#endif
+
+ dbg("parse_rules: '%s' has unknown file type %o", file, buf.st_mode);
+ return -EINVAL;
+
+}
+
+int namedev_init_rules(void)
+{
+ return parse_rules(udev_rules_filename, parse_rules_file);
+}
+
+int namedev_init_permissions(void)
+{
+ return parse_rules(udev_permissions_filename, parse_permissions_file);
+}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
@ 2004-02-22 10:17 ` Marco d'Itri
2004-02-22 15:02 ` Andrey Borzenkov
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2004-02-22 10:17 UTC (permalink / raw)
To: linux-hotplug
On Feb 22, Andrey Borzenkov <arvidjaar@mail.ru> wrote:
>This is new version that I have been runing for some time. It does not
>directly support multiple files; rather you can give either file or
>directory; directory is scanned, sorted and all files are read in order.
Again, I think scanning the directory makes the life of users and
distributions *harder*: I will not be able to ship the package with
different configurations in place, and users will have to be careful to
use file names which will sort in the right order.
--
ciao, |
Marco | [4702 lupwubQmPnBbM]
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
2004-02-22 10:17 ` Marco d'Itri
@ 2004-02-22 15:02 ` Andrey Borzenkov
2004-02-22 15:33 ` Marco d'Itri
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrey Borzenkov @ 2004-02-22 15:02 UTC (permalink / raw)
To: linux-hotplug
On Sun, Feb 22, 2004 at 11:17:07AM +0100, Marco d'Itri wrote:
> On Feb 22, Andrey Borzenkov <arvidjaar@mail.ru> wrote:
>
> >This is new version that I have been runing for some time. It does not
> >directly support multiple files; rather you can give either file or
> >directory; directory is scanned, sorted and all files are read in order.
> Again, I think scanning the directory makes the life of users and
> distributions *harder*: I will not be able to ship the package with
> different configurations in place, and users will have to be careful to
> use file names which will sort in the right order.
>
So, just that I understand - you
- do not want to have multiple files at all?
- do not want support directory but the config_file="file1 file2 ..."?
could you explain what do you mean under "different configurations in
place"?
Users should be careful only if they want to replace kernel names with
something else. But I still fail to see why on earth would they want to?
And if they want to my patch lets them do it.
I fail to see how having conifguration directory may make life harder.
If it was the case, SuSE would not have replaced single file with
configuration directory nor would Debian have invented modules.d to
complement for monolithic file.
regards
-andrey
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
2004-02-22 10:17 ` Marco d'Itri
2004-02-22 15:02 ` Andrey Borzenkov
@ 2004-02-22 15:33 ` Marco d'Itri
2004-02-22 18:20 ` Gioele Barabucci
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2004-02-22 15:33 UTC (permalink / raw)
To: linux-hotplug
On Feb 22, Andrey Borzenkov <arvidjaar@mail.ru> wrote:
>- do not want to have multiple files at all?
I definitely need multiple configuration files.
>- do not want support directory but the config_file="file1 file2 ..."?
I like this syntax a lot more, and in fact it is the one I implemented
in the patch I posted yesterday (loosely based on an older version of
your patch) and which I am using in the debian package.
>could you explain what do you mean under "different configurations in
>place"?
My plan is to distribute with the package files like
/etc/udev/udev.rules (enabled by default, devfs-like names)
/etc/udev/udev-compat.rules (enabled by default, some compatibility links)
/etc/udev/udev-full.rules (more compatibility links)
/etc/udev/udev-traditional.rules (old style names)
and allow users to select the files they need from udev.conf.
I /could/ install these files in /usr/share/doc/, but then users who
choose a non-default configuration would have to manually update them
after each upgrade.
>Users should be careful only if they want to replace kernel names with
>something else. But I still fail to see why on earth would they want to?
Because some users want
The main reason to have a configuration directory like /etc/modprobe.d/
is to allow other packages to put there their own files, but this is not
needed for udev.
--
ciao, |
Marco | [4709 ap7bUU.9AuD62]
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
` (2 preceding siblings ...)
2004-02-22 15:33 ` Marco d'Itri
@ 2004-02-22 18:20 ` Gioele Barabucci
2004-02-22 19:20 ` Marco d'Itri
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Gioele Barabucci @ 2004-02-22 18:20 UTC (permalink / raw)
To: linux-hotplug
On Sunday 22 February 2004 16:33, Marco d'Itri wrote:
> >Users should be careful only if they want to replace kernel names with
> >something else. But I still fail to see why on earth would they want to?
>
> Because some users want
>
> The main reason to have a configuration directory like /etc/modprobe.d/
> is to allow other packages to put there their own files, but this is not
> needed for udev.
What if the same package would like to specify a dev name?
--
Gioele
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
` (3 preceding siblings ...)
2004-02-22 18:20 ` Gioele Barabucci
@ 2004-02-22 19:20 ` Marco d'Itri
2004-02-23 0:15 ` Kay Sievers
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2004-02-22 19:20 UTC (permalink / raw)
To: linux-hotplug
On Feb 22, Gioele Barabucci <gioele@gioelebarabucci.com> wrote:
>> The main reason to have a configuration directory like /etc/modprobe.d/
>> is to allow other packages to put there their own files, but this is not
>> needed for udev.
>What if the same package would like to specify a dev name?
We adopt the same policy of MAKEDEV: the package will depend on a recent
enough version of udev.
--
ciao, |
Marco | [4715 crVYU1cppv4Gc]
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
` (4 preceding siblings ...)
2004-02-22 19:20 ` Marco d'Itri
@ 2004-02-23 0:15 ` Kay Sievers
2004-02-23 8:48 ` Andrey Borzenkov
2004-02-28 15:15 ` Andrey Borzenkov
7 siblings, 0 replies; 9+ messages in thread
From: Kay Sievers @ 2004-02-23 0:15 UTC (permalink / raw)
To: linux-hotplug
On Sun, 2004-02-22 at 16:33, Marco d'Itri wrote:
> On Feb 22, Andrey Borzenkov <arvidjaar@mail.ru> wrote:
>
> >- do not want to have multiple files at all?
> I definitely need multiple configuration files.
>
> >- do not want support directory but the config_file="file1 file2 ..."?
> I like this syntax a lot more, and in fact it is the one I implemented
> in the patch I posted yesterday (loosely based on an older version of
> your patch) and which I am using in the debian package.
I still vote for the directory solution.
Andrey it's not acceptable to have a different config for klibc users,
so I posted a patch on Friday based on your idea which does the sorting
without scandir.
thanks,
Kay
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
` (5 preceding siblings ...)
2004-02-23 0:15 ` Kay Sievers
@ 2004-02-23 8:48 ` Andrey Borzenkov
2004-02-28 15:15 ` Andrey Borzenkov
7 siblings, 0 replies; 9+ messages in thread
From: Andrey Borzenkov @ 2004-02-23 8:48 UTC (permalink / raw)
To: linux-hotplug
On Mon, Feb 23, 2004 at 01:15:25AM +0100, Kay Sievers wrote:
> On Sun, 2004-02-22 at 16:33, Marco d'Itri wrote:
> > On Feb 22, Andrey Borzenkov <arvidjaar@mail.ru> wrote:
> >
> > >- do not want to have multiple files at all?
> > I definitely need multiple configuration files.
> >
> > >- do not want support directory but the config_file="file1 file2 ..."?
> > I like this syntax a lot more, and in fact it is the one I implemented
> > in the patch I posted yesterday (loosely based on an older version of
> > your patch) and which I am using in the debian package.
>
> I still vote for the directory solution.
> Andrey it's not acceptable to have a different config for klibc users,
> so I posted a patch on Friday based on your idea which does the sorting
> without scandir.
>
thank you
> thanks,
> Kay
>
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
* Re: [PATCH] support directory for rules and permissions
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
` (6 preceding siblings ...)
2004-02-23 8:48 ` Andrey Borzenkov
@ 2004-02-28 15:15 ` Andrey Borzenkov
7 siblings, 0 replies; 9+ messages in thread
From: Andrey Borzenkov @ 2004-02-28 15:15 UTC (permalink / raw)
To: linux-hotplug
On Monday 23 February 2004 11:48, wrote:
> On Mon, Feb 23, 2004 at 01:15:25AM +0100, Kay Sievers wrote:
> > I still vote for the directory solution.
> > Andrey it's not acceptable to have a different config for klibc users,
> > so I posted a patch on Friday based on your idea which does the sorting
> > without scandir.
>
your patch does not preserve config file name that was used making debug
output in name_device
info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
udev_rules_filename, dev->config_line, udev->kernel_name, dev->name);
rather out of mark.
regards
-andrey
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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] 9+ messages in thread
end of thread, other threads:[~2004-02-28 15:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-22 9:45 [PATCH] support directory for rules and permissions Andrey Borzenkov
2004-02-22 10:17 ` Marco d'Itri
2004-02-22 15:02 ` Andrey Borzenkov
2004-02-22 15:33 ` Marco d'Itri
2004-02-22 18:20 ` Gioele Barabucci
2004-02-22 19:20 ` Marco d'Itri
2004-02-23 0:15 ` Kay Sievers
2004-02-23 8:48 ` Andrey Borzenkov
2004-02-28 15:15 ` Andrey Borzenkov
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).