summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2005-08-08 17:43:42 +0200
committerKay Sievers <kay.sievers@suse.de>2005-08-08 17:43:42 +0200
commitbfd12948927b84b3ce990403969c1d10081c1fed (patch)
tree538e0547d743e633eba85151acd8283215276206
parent63cc8f049100c9b76ca4e37fc5c8976b6e92a207 (diff)
add flag for reading of precompiled rules
Rules can be precompiled and stored on disk for initramfs, to avoid parsing the rules with every event again and again. Also the OWNER and GROUP names are already resolved to numerical values in the compiled rules. This flag is used for the upcoming move of the rules parsing into udevd: If the real root is mounted udevd is started and parses the rules only once. The event processes will inherit the already parsed rules from the daemon, so we want to ignore any precompiled rules and use the real rules files and watch the filesystem for changes to reload the rules automatically. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
-rw-r--r--udev.c2
-rw-r--r--udev_rules.h2
-rw-r--r--udev_rules_parse.c17
-rw-r--r--udevrulescompile.c2
-rw-r--r--udevstart.c2
-rw-r--r--udevtest.c2
6 files changed, 15 insertions, 12 deletions
diff --git a/udev.c b/udev.c
index 6a0beda1c2..ecfd5644ec 100644
--- a/udev.c
+++ b/udev.c
@@ -115,7 +115,7 @@ int main(int argc, char *argv[], char *envp[])
}
udev_init_device(&udev, devpath, subsystem, action);
- udev_rules_init(&rules, 0);
+ udev_rules_init(&rules, 1, 0);
retval = udev_process_event(&rules, &udev);
diff --git a/udev_rules.h b/udev_rules.h
index 9e3931129f..be13378e4e 100644
--- a/udev_rules.h
+++ b/udev_rules.h
@@ -104,7 +104,7 @@ struct udev_rules {
int resolve_names;
};
-extern int udev_rules_init(struct udev_rules *rules, int resolve_names);
+extern int udev_rules_init(struct udev_rules *rules, int read_compiled, int resolve_names);
extern void udev_rules_close(struct udev_rules *rules);
extern void udev_apply_format(struct udevice *udev, char *string, size_t maxsize,
diff --git a/udev_rules_parse.c b/udev_rules_parse.c
index cededf002d..488b7a7ff0 100644
--- a/udev_rules_parse.c
+++ b/udev_rules_parse.c
@@ -607,7 +607,7 @@ static int rules_map(struct udev_rules *rules, const char *filename)
return 0;
}
-int udev_rules_init(struct udev_rules *rules, int resolve_names)
+int udev_rules_init(struct udev_rules *rules, int read_compiled, int resolve_names)
{
char comp[PATH_SIZE];
struct stat stats;
@@ -617,14 +617,17 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names)
rules->resolve_names = resolve_names;
/* check for precompiled rules */
- strlcpy(comp, udev_rules_filename, sizeof(comp));
- strlcat(comp, ".compiled", sizeof(comp));
- if (stat(comp, &stats) == 0) {
- dbg("map compiled rules '%s'", comp);
- if (rules_map(rules, comp) == 0)
- return 0;
+ if (read_compiled) {
+ strlcpy(comp, udev_rules_filename, sizeof(comp));
+ strlcat(comp, ".compiled", sizeof(comp));
+ if (stat(comp, &stats) == 0) {
+ dbg("map compiled rules '%s'", comp);
+ if (rules_map(rules, comp) == 0)
+ return 0;
+ }
}
+ /* parse rules file or all matching files in directory */
if (stat(udev_rules_filename, &stats) != 0)
return -1;
diff --git a/udevrulescompile.c b/udevrulescompile.c
index a71286abe7..a2c5f2e9fc 100644
--- a/udevrulescompile.c
+++ b/udevrulescompile.c
@@ -69,7 +69,7 @@ int main(int argc, char *argv[], char *envp[])
unlink(comp);
unlink(comp_tmp);
- udev_rules_init(&rules, 1);
+ udev_rules_init(&rules, 0, 1);
f = fopen(comp_tmp, "w");
if (f == NULL) {
diff --git a/udevstart.c b/udevstart.c
index 5f3ba711f0..4288db9d38 100644
--- a/udevstart.c
+++ b/udevstart.c
@@ -367,7 +367,7 @@ int main(int argc, char *argv[], char *envp[])
/* trigger timeout to prevent hanging processes */
alarm(UDEV_ALARM_TIMEOUT);
- udev_rules_init(&rules, 1);
+ udev_rules_init(&rules, 0, 1);
udev_scan_block();
udev_scan_class();
diff --git a/udevtest.c b/udevtest.c
index 4890b6837c..6e973e31e6 100644
--- a/udevtest.c
+++ b/udevtest.c
@@ -92,7 +92,7 @@ int main(int argc, char *argv[], char *envp[])
info("looking at device '%s' from subsystem '%s'", devpath, subsystem);
/* initialize the naming deamon */
- udev_rules_init(&rules, 0);
+ udev_rules_init(&rules, 0, 0);
/* fill in values and test_run flag*/
udev_init_device(&udev, devpath, subsystem, "add");