mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
remove precompiled rules option
It was a workaround for speed up udev "coldplug", where ~800 events happened a second time during bootup. No need for it with the rules aleady parsed in the daemon. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
parent
3904a75817
commit
287814b23c
1
Makefile
1
Makefile
@ -50,7 +50,6 @@ PROGRAMS = \
|
||||
udev \
|
||||
udevd \
|
||||
udevsend \
|
||||
udevrulescompile \
|
||||
udevinitsend \
|
||||
udeveventrecorder \
|
||||
udevcontrol \
|
||||
|
2
udev.c
2
udev.c
@ -132,7 +132,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
}
|
||||
|
||||
udev_init_device(&udev, devpath, subsystem, action);
|
||||
udev_rules_init(&rules, 1, 0);
|
||||
udev_rules_init(&rules, 0);
|
||||
|
||||
retval = udev_process_event(&rules, &udev);
|
||||
|
||||
|
@ -100,11 +100,10 @@ struct udev_rules {
|
||||
char *buf;
|
||||
size_t bufsize;
|
||||
size_t current;
|
||||
int mapped;
|
||||
int resolve_names;
|
||||
};
|
||||
|
||||
extern int udev_rules_init(struct udev_rules *rules, int read_compiled, int resolve_names);
|
||||
extern int udev_rules_init(struct udev_rules *rules, 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,
|
||||
|
@ -591,42 +591,14 @@ static int parse_file(struct udev_rules *rules, const char *filename)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int rules_map(struct udev_rules *rules, const char *filename)
|
||||
int udev_rules_init(struct udev_rules *rules, int resolve_names)
|
||||
{
|
||||
if (file_map(filename, &rules->buf, &rules->bufsize)) {
|
||||
rules->buf = NULL;
|
||||
return -1;
|
||||
}
|
||||
if (rules->bufsize == 0) {
|
||||
file_unmap(rules->buf, rules->bufsize);
|
||||
rules->buf = NULL;
|
||||
return -1;
|
||||
}
|
||||
rules->mapped = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_rules_init(struct udev_rules *rules, int read_compiled, int resolve_names)
|
||||
{
|
||||
char comp[PATH_SIZE];
|
||||
struct stat stats;
|
||||
int retval;
|
||||
|
||||
memset(rules, 0x00, sizeof(struct udev_rules));
|
||||
rules->resolve_names = resolve_names;
|
||||
|
||||
/* check for precompiled rules */
|
||||
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;
|
||||
@ -660,11 +632,7 @@ int udev_rules_init(struct udev_rules *rules, int read_compiled, int resolve_nam
|
||||
void udev_rules_close(struct udev_rules *rules)
|
||||
{
|
||||
if (rules->buf) {
|
||||
if (rules->mapped) {
|
||||
rules->mapped = 0;
|
||||
file_unmap(rules->buf, rules->bufsize);
|
||||
} else
|
||||
free(rules->buf);
|
||||
free(rules->buf);
|
||||
rules->buf = NULL;
|
||||
}
|
||||
}
|
||||
|
4
udevd.c
4
udevd.c
@ -880,7 +880,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
}
|
||||
|
||||
/* parse the rules and keep it in memory */
|
||||
udev_rules_init(&rules, 0, 1);
|
||||
udev_rules_init(&rules, 1);
|
||||
|
||||
if (daemonize) {
|
||||
pid_t pid;
|
||||
@ -1065,7 +1065,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
if (reload_config) {
|
||||
reload_config = 0;
|
||||
udev_rules_close(&rules);
|
||||
udev_rules_init(&rules, 0, 1);
|
||||
udev_rules_init(&rules, 1);
|
||||
}
|
||||
|
||||
/* forked child have returned */
|
||||
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* udevrulescompile.c - store already parsed config on disk
|
||||
*
|
||||
* Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "udev_libc_wrapper.h"
|
||||
#include "udev_sysfs.h"
|
||||
#include "udev.h"
|
||||
#include "udev_version.h"
|
||||
#include "logging.h"
|
||||
#include "udev_rules.h"
|
||||
#include "udev_utils.h"
|
||||
#include "list.h"
|
||||
|
||||
#ifdef USE_LOG
|
||||
void log_message(int priority, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (priority > udev_log_priority)
|
||||
return;
|
||||
|
||||
va_start(args, format);
|
||||
vsyslog(priority, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
struct udev_rules rules;
|
||||
FILE *f;
|
||||
char comp[PATH_SIZE];
|
||||
char comp_tmp[PATH_SIZE];
|
||||
int retval = 0;
|
||||
|
||||
logging_init("udevrulescompile");
|
||||
udev_init_config();
|
||||
dbg("version %s", UDEV_VERSION);
|
||||
|
||||
strlcpy(comp, udev_rules_filename, sizeof(comp));
|
||||
strlcat(comp, ".compiled", sizeof(comp));
|
||||
strlcpy(comp_tmp, comp, sizeof(comp_tmp));
|
||||
strlcat(comp_tmp, ".tmp", sizeof(comp_tmp));
|
||||
|
||||
/* remove old version, otherwise we would read it instead of the real rules */
|
||||
unlink(comp);
|
||||
unlink(comp_tmp);
|
||||
|
||||
udev_rules_init(&rules, 0, 1);
|
||||
|
||||
f = fopen(comp_tmp, "w");
|
||||
if (f == NULL) {
|
||||
err("unable to create db file '%s'", comp_tmp);
|
||||
unlink(comp_tmp);
|
||||
retval = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbg("storing compiled rules in '%s' size=%zi", comp_tmp, rules.bufsize);
|
||||
fwrite(rules.buf, rules.bufsize, 1, f);
|
||||
fclose(f);
|
||||
|
||||
dbg("activating compiled rules in '%s'", comp);
|
||||
if (rename(comp_tmp, comp) != 0) {
|
||||
err("unable to write file");
|
||||
unlink(comp);
|
||||
unlink(comp_tmp);
|
||||
retval = 2;
|
||||
}
|
||||
|
||||
exit:
|
||||
logging_close();
|
||||
return retval;
|
||||
}
|
@ -364,7 +364,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
/* trigger timeout to prevent hanging processes */
|
||||
alarm(UDEV_ALARM_TIMEOUT);
|
||||
|
||||
udev_rules_init(&rules, 0, 1);
|
||||
udev_rules_init(&rules, 1);
|
||||
|
||||
udev_scan_class(&device_list);
|
||||
udev_scan_block(&device_list);
|
||||
|
@ -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, 0);
|
||||
udev_rules_init(&rules, 0);
|
||||
|
||||
/* fill in values and test_run flag*/
|
||||
udev_init_device(&udev, devpath, subsystem, "add");
|
||||
|
Loading…
Reference in New Issue
Block a user