mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
make struct udev_rules opaque
This commit is contained in:
parent
c7521974a3
commit
d7ddce186c
@ -46,7 +46,7 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
@ -81,7 +81,7 @@ int main(int argc, char *argv[])
|
||||
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));
|
||||
@ -97,7 +97,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
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)
|
||||
@ -109,7 +109,7 @@ int main(int argc, char *argv[])
|
||||
udev_event_unref(event);
|
||||
udev_device_unref(dev);
|
||||
fail:
|
||||
udev_rules_cleanup(&rules);
|
||||
udev_rules_unref(rules);
|
||||
exit:
|
||||
selinux_exit(udev);
|
||||
udev_unref(udev);
|
||||
|
@ -34,7 +34,17 @@
|
||||
|
||||
#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,
|
||||
@ -55,6 +65,7 @@ struct key_pair {
|
||||
size_t key_name_off;
|
||||
};
|
||||
|
||||
#define PAIRS_MAX 5
|
||||
struct key_pairs {
|
||||
int count;
|
||||
struct key_pair keys[PAIRS_MAX];
|
||||
@ -119,11 +130,6 @@ struct udev_rule {
|
||||
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);
|
||||
@ -1860,7 +1866,6 @@ static int get_key(struct udev_rules *rules, char **line, char **key, enum key_o
|
||||
|
||||
/* move line to next key */
|
||||
*line = temp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1932,7 +1937,6 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
|
||||
char *attr;
|
||||
size_t padding;
|
||||
int physdev = 0;
|
||||
int retval;
|
||||
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
rule = (struct udev_rule *) buf;
|
||||
@ -1946,8 +1950,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
|
||||
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) {
|
||||
@ -2462,14 +2465,17 @@ static int add_matching_files(struct udev *udev, struct udev_list_node *file_lis
|
||||
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;
|
||||
@ -2539,13 +2545,16 @@ int udev_rules_init(struct udev *udev, struct udev_rules *rules, int resolve_nam
|
||||
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);
|
||||
}
|
||||
|
10
udev/udev.h
10
udev/udev.h
@ -92,14 +92,8 @@ extern void udev_event_unref(struct udev_event *event);
|
||||
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);
|
||||
|
@ -38,7 +38,7 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
|
||||
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;
|
||||
|
||||
@ -89,7 +89,12 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
|
||||
"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) {
|
||||
@ -116,7 +121,7 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
|
||||
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));
|
||||
@ -135,6 +140,6 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
|
||||
udev_event_unref(event);
|
||||
udev_device_unref(dev);
|
||||
exit:
|
||||
udev_rules_cleanup(&rules);
|
||||
udev_rules_unref(rules);
|
||||
return rc;
|
||||
}
|
||||
|
21
udev/udevd.c
21
udev/udevd.c
@ -58,7 +58,7 @@ static void log_fn(struct udev *udev, int priority,
|
||||
}
|
||||
|
||||
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;
|
||||
@ -208,7 +208,7 @@ static void event_fork(struct udev_event *event)
|
||||
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)
|
||||
@ -748,9 +748,13 @@ int main(int argc, char *argv[])
|
||||
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) {
|
||||
@ -934,9 +938,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* 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) {
|
||||
@ -953,7 +962,7 @@ int main(int argc, char *argv[])
|
||||
rc = 0;
|
||||
|
||||
exit:
|
||||
udev_rules_cleanup(&rules);
|
||||
udev_rules_unref(rules);
|
||||
|
||||
if (signal_pipe[READ_END] >= 0)
|
||||
close(signal_pipe[READ_END]);
|
||||
|
Loading…
Reference in New Issue
Block a user