struct udev *udev;
struct udev_event *event;
struct udev_device *dev;
- struct udev_rules rules;
+ struct udev_rules *rules;
char syspath[UTIL_PATH_SIZE];
const char *devpath;
const char *action;
goto exit;
}
- udev_rules_init(udev, &rules, 0);
+ rules = udev_rules_new(udev, 0);
util_strlcpy(syspath, udev_get_sys_path(udev), sizeof(syspath));
util_strlcat(syspath, devpath, sizeof(syspath));
udev_device_set_action(dev, action);
event = udev_event_new(dev);
- err = udev_event_run(event, &rules);
+ err = udev_event_run(event, rules);
/* rules may change/disable the timeout */
if (udev_device_get_event_timeout(dev) >= 0)
udev_event_unref(event);
udev_device_unref(dev);
fail:
- udev_rules_cleanup(&rules);
+ udev_rules_unref(rules);
exit:
selinux_exit(udev);
udev_unref(udev);
#include "udev.h"
-#define PAIRS_MAX 5
+struct udev_rules {
+ struct udev *udev;
+ char *buf;
+ size_t bufsize;
+ int resolve_names;
+};
+
+struct udev_rules_iter {
+ struct udev_rules *rules;
+ size_t current;
+};
enum key_operation {
KEY_OP_UNSET,
size_t key_name_off;
};
+#define PAIRS_MAX 5
struct key_pairs {
int count;
struct key_pair keys[PAIRS_MAX];
char buf[];
};
-struct udev_rules_iter {
- struct udev_rules *rules;
- size_t current;
-};
-
static void udev_rules_iter_init(struct udev_rules_iter *iter, struct udev_rules *rules)
{
dbg(rules->udev, "bufsize=%zi\n", rules->bufsize);
/* move line to next key */
*line = temp;
-
return 0;
}
char *attr;
size_t padding;
int physdev = 0;
- int retval;
memset(buf, 0x00, sizeof(buf));
rule = (struct udev_rule *) buf;
char *value;
enum key_operation operation = KEY_OP_UNSET;
- retval = get_key(rules, &linepos, &key, &operation, &value);
- if (retval)
+ if (get_key(rules, &linepos, &key, &operation, &value) != 0)
break;
if (strcasecmp(key, "ACTION") == 0) {
return 0;
}
-int udev_rules_init(struct udev *udev, struct udev_rules *rules, int resolve_names)
+struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
{
+ struct udev_rules *rules;
struct stat statbuf;
char filename[PATH_MAX];
struct udev_list_node file_list;
struct udev_list_entry *file_loop, *file_tmp;
- int retval = 0;
+ rules = malloc(sizeof(struct udev_rules));
+ if (rules == NULL)
+ return rules;
memset(rules, 0x00, sizeof(struct udev_rules));
rules->udev = udev;
rules->resolve_names = resolve_names;
info(udev, "can not read '%s'\n", file_name);
udev_list_entry_remove(file_loop);
}
- return retval;
+ return rules;
}
-void udev_rules_cleanup(struct udev_rules *rules)
+void udev_rules_unref(struct udev_rules *rules)
{
+ if (rules == NULL)
+ return;
if (rules->buf) {
free(rules->buf);
rules->buf = NULL;
}
+ free(rules);
}
extern int udev_event_run(struct udev_event *event, struct udev_rules *rules);
/* udev-rules.c */
-struct udev_rules {
- struct udev *udev;
- char *buf;
- size_t bufsize;
- int resolve_names;
-};
-extern int udev_rules_init(struct udev *udev, struct udev_rules *rules, int resolve_names);
-extern void udev_rules_cleanup(struct udev_rules *rules);
+extern struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
+extern void udev_rules_unref(struct udev_rules *rules);
extern int udev_rules_get_name(struct udev_rules *rules, struct udev_event *event);
extern int udev_rules_get_run(struct udev_rules *rules, struct udev_event *event);
extern int udev_rules_run(struct udev_event *event);
const char *syspath = NULL;
struct udev_event *event;
struct udev_device *dev;
- struct udev_rules rules = {};
+ struct udev_rules *rules = NULL;
int err;
int rc = 0;
"some values may be different, or not available at a simulation run.\n"
"\n");
- udev_rules_init(udev, &rules, 0);
+ rules = udev_rules_new(udev, 0);
+ if (rules == NULL) {
+ fprintf(stderr, "error reading rules\n");
+ rc = 1;
+ goto exit;
+ }
/* add /sys if needed */
if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
if (!force)
event->test = 1;
- err = udev_event_run(event, &rules);
+ err = udev_event_run(event, rules);
if (udev_device_get_event_timeout(dev) >= 0)
info(udev, "custom event timeout: %i\n", udev_device_get_event_timeout(dev));
udev_event_unref(event);
udev_device_unref(dev);
exit:
- udev_rules_cleanup(&rules);
+ udev_rules_unref(rules);
return rc;
}
}
static int debug_trace;
-static struct udev_rules rules;
+static struct udev_rules *rules;
static struct udev_ctrl *udev_ctrl;
static struct udev_monitor *kernel_monitor;
static int inotify_fd = -1;
alarm(UDEV_EVENT_TIMEOUT);
/* apply rules, create node, symlinks */
- err = udev_event_run(event, &rules);
+ err = udev_event_run(event, rules);
/* rules may change/disable the timeout */
if (udev_device_get_event_timeout(event->dev) >= 0)
goto exit;
}
+ rules = udev_rules_new(udev, 1);
+ if (rules == NULL) {
+ err(udev, "error reading rules\n");
+ goto exit;
+ }
udev_list_init(&running_list);
udev_list_init(&exec_list);
- udev_rules_init(udev, &rules, 1);
export_initial_seqnum(udev);
if (daemonize) {
/* rules changed, set by inotify or a HUP signal */
if (reload_config) {
+ struct udev_rules *rules_new;
+
reload_config = 0;
- udev_rules_cleanup(&rules);
- udev_rules_init(udev, &rules, 1);
+ rules_new = udev_rules_new(udev, 1);
+ if (rules_new != NULL) {
+ udev_rules_unref(rules);
+ rules = rules_new;
+ }
}
if (sigchilds_waiting) {
rc = 0;
exit:
- udev_rules_cleanup(&rules);
+ udev_rules_unref(rules);
if (signal_pipe[READ_END] >= 0)
close(signal_pipe[READ_END]);