2 * udevrulescompile.c - store already parsed config on disk
4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "udev_libc_wrapper.h"
29 #include "udev_sysfs.h"
31 #include "udev_version.h"
33 #include "udev_rules.h"
34 #include "udev_utils.h"
38 void log_message(int priority, const char *format, ...)
42 if (priority > udev_log_priority)
45 va_start(args, format);
46 vsyslog(priority, format, args);
51 int main(int argc, char *argv[], char *envp[])
53 struct udev_rules rules;
56 char comp_tmp[PATH_SIZE];
59 logging_init("udevrulescompile");
61 dbg("version %s", UDEV_VERSION);
63 strlcpy(comp, udev_rules_filename, sizeof(comp));
64 strlcat(comp, ".compiled", sizeof(comp));
65 strlcpy(comp_tmp, comp, sizeof(comp_tmp));
66 strlcat(comp_tmp, ".tmp", sizeof(comp_tmp));
68 /* remove old version, otherwise we would read it instead of the real rules */
72 udev_rules_init(&rules, 1);
74 f = fopen(comp_tmp, "w");
76 err("unable to create db file '%s'", comp_tmp);
82 dbg("storing compiled rules in '%s' size=%zi", comp_tmp, rules.bufsize);
83 fwrite(rules.buf, rules.bufsize, 1, f);
86 dbg("activating compiled rules in '%s'", comp);
87 if (rename(comp_tmp, comp) != 0) {
88 err("unable to write file");