1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

udev: drop unused udev struct

This commit is contained in:
Yu Watanabe 2018-08-22 19:57:32 +09:00
parent 187e1d977a
commit 2024ed616e
25 changed files with 158 additions and 232 deletions

View File

@ -52,7 +52,6 @@ static int fake_filesystems(void) {
}
int main(int argc, char *argv[]) {
_cleanup_(udev_unrefp) struct udev *udev = NULL;
_cleanup_(udev_event_unrefp) struct udev_event *event = NULL;
_cleanup_(udev_device_unrefp) struct udev_device *dev = NULL;
_cleanup_(udev_rules_unrefp) struct udev_rules *rules = NULL;
@ -68,10 +67,6 @@ int main(int argc, char *argv[]) {
if (err < 0)
return EXIT_FAILURE;
udev = udev_new();
if (udev == NULL)
return EXIT_FAILURE;
log_debug("version %s", PACKAGE_VERSION);
mac_selinux_init();
@ -87,10 +82,10 @@ int main(int argc, char *argv[]) {
goto out;
}
rules = udev_rules_new(udev, 1);
rules = udev_rules_new(1);
strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL);
dev = udev_device_new_from_synthetic_event(udev, syspath, action);
dev = udev_device_new_from_synthetic_event(NULL, syspath, action);
if (dev == NULL) {
log_debug("unknown device '%s'", devpath);
goto out;

View File

@ -160,7 +160,7 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te
/* read data from another device than the device we will store the data */
if (device) {
srcdev = udev_device_new_from_device_id(udev_device_get_udev(dev), device);
srcdev = udev_device_new_from_device_id(NULL, device);
if (!srcdev)
return EXIT_FAILURE;
}
@ -171,7 +171,7 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te
}
/* called at udev startup and reload */
static int builtin_hwdb_init(struct udev *udev) {
static int builtin_hwdb_init(void) {
int r;
if (hwdb)
@ -185,12 +185,12 @@ static int builtin_hwdb_init(struct udev *udev) {
}
/* called on udev shutdown and reload request */
static void builtin_hwdb_exit(struct udev *udev) {
static void builtin_hwdb_exit(void) {
hwdb = sd_hwdb_unref(hwdb);
}
/* called every couple of seconds during event activity; 'true' if config has changed */
static bool builtin_hwdb_validate(struct udev *udev) {
static bool builtin_hwdb_validate(void) {
return hwdb_validate(hwdb);
}

View File

@ -39,7 +39,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
}
/* called at udev startup and reload */
static int builtin_kmod_init(struct udev *udev) {
static int builtin_kmod_init(void) {
if (ctx)
return 0;
@ -48,19 +48,19 @@ static int builtin_kmod_init(struct udev *udev) {
return -ENOMEM;
log_debug("Load module index");
kmod_set_log_fn(ctx, udev_kmod_log, udev);
kmod_set_log_fn(ctx, udev_kmod_log, NULL);
kmod_load_resources(ctx);
return 0;
}
/* called on udev shutdown and reload request */
static void builtin_kmod_exit(struct udev *udev) {
static void builtin_kmod_exit(void) {
log_debug("Unload module index");
ctx = kmod_unref(ctx);
}
/* called every couple of seconds during event activity; 'true' if config has changed */
static bool builtin_kmod_validate(struct udev *udev) {
static bool builtin_kmod_validate(void) {
log_debug("Validate module index");
if (!ctx)
return false;

View File

@ -153,7 +153,6 @@ static struct udev_device *skip_virtio(struct udev_device *dev) {
}
static int get_virtfn_info(struct udev_device *dev, struct netnames *names, struct virtfn_info *vf_info) {
struct udev *udev;
const char *physfn_link_file;
_cleanup_free_ char *physfn_pci_syspath = NULL;
_cleanup_free_ char *virtfn_pci_syspath = NULL;
@ -162,9 +161,6 @@ static int get_virtfn_info(struct udev_device *dev, struct netnames *names, stru
struct virtfn_info vf_info_local = {};
int r;
udev = udev_device_get_udev(names->pcidev);
if (!udev)
return -ENOENT;
/* Check if this is a virtual function. */
physfn_link_file = strjoina(udev_device_get_syspath(names->pcidev), "/physfn");
r = chase_symlinks(physfn_link_file, NULL, 0, &physfn_pci_syspath);
@ -172,7 +168,7 @@ static int get_virtfn_info(struct udev_device *dev, struct netnames *names, stru
return r;
/* Get physical function's pci device. */
vf_info_local.physfn_pcidev = udev_device_new_from_syspath(udev, physfn_pci_syspath);
vf_info_local.physfn_pcidev = udev_device_new_from_syspath(NULL, physfn_pci_syspath);
if (!vf_info_local.physfn_pcidev)
return -ENOENT;
@ -288,7 +284,6 @@ static bool is_pci_ari_enabled(struct udev_device *dev) {
}
static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
struct udev *udev = udev_device_get_udev(names->pcidev);
unsigned domain, bus, slot, func, dev_port = 0, hotplug_slot = 0;
size_t l;
char *s;
@ -331,7 +326,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
names->pci_path[0] = '\0';
/* ACPI _SUN — slot user number */
pci = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
pci = udev_device_new_from_subsystem_sysname(NULL, "subsystem", "pci");
if (!pci)
return -ENOENT;

View File

@ -46,7 +46,7 @@ static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv
return EXIT_SUCCESS;
}
static int builtin_net_setup_link_init(struct udev *udev) {
static int builtin_net_setup_link_init(void) {
int r;
if (ctx)
@ -64,13 +64,13 @@ static int builtin_net_setup_link_init(struct udev *udev) {
return 0;
}
static void builtin_net_setup_link_exit(struct udev *udev) {
static void builtin_net_setup_link_exit(void) {
link_config_ctx_free(ctx);
ctx = NULL;
log_debug("Unloaded link configuration context.");
}
static bool builtin_net_setup_link_validate(struct udev *udev) {
static bool builtin_net_setup_link_validate(void) {
log_debug("Check if link configuration needs reloading.");
if (!ctx)
return false;

View File

@ -86,7 +86,6 @@ static struct udev_device *skip_subsystem(struct udev_device *dev, const char *s
}
static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, char **path) {
struct udev *udev;
struct udev_device *targetdev;
_cleanup_(udev_device_unrefp) struct udev_device *fcdev = NULL;
const char *port;
@ -95,13 +94,12 @@ static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent,
assert(parent);
assert(path);
udev = udev_device_get_udev(parent);
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
if (!targetdev)
return NULL;
fcdev = udev_device_new_from_subsystem_sysname(udev, "fc_transport", udev_device_get_sysname(targetdev));
fcdev = udev_device_new_from_subsystem_sysname(NULL, "fc_transport", udev_device_get_sysname(targetdev));
if (!fcdev)
return NULL;
@ -115,7 +113,6 @@ static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent,
}
static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent, char **path) {
struct udev *udev;
struct udev_device *targetdev, *target_parent;
_cleanup_(udev_device_unrefp) struct udev_device *sasdev = NULL;
const char *sas_address;
@ -124,7 +121,6 @@ static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent,
assert(parent);
assert(path);
udev = udev_device_get_udev(parent);
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
if (!targetdev)
@ -134,7 +130,7 @@ static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent,
if (!target_parent)
return NULL;
sasdev = udev_device_new_from_subsystem_sysname(udev, "sas_device",
sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device",
udev_device_get_sysname(target_parent));
if (!sasdev)
return NULL;
@ -150,7 +146,6 @@ static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent,
static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
{
struct udev *udev;
struct udev_device *targetdev, *target_parent, *port, *expander;
_cleanup_(udev_device_unrefp) struct udev_device
*target_sasdev = NULL, *expander_sasdev = NULL, *port_sasdev = NULL;
@ -162,7 +157,6 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
assert(parent);
assert(path);
udev = udev_device_get_udev(parent);
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
if (!targetdev)
@ -173,8 +167,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
return NULL;
/* Get sas device */
target_sasdev = udev_device_new_from_subsystem_sysname(
udev, "sas_device", udev_device_get_sysname(target_parent));
target_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device", udev_device_get_sysname(target_parent));
if (!target_sasdev)
return NULL;
@ -184,8 +177,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
return NULL;
/* Get port device */
port_sasdev = udev_device_new_from_subsystem_sysname(
udev, "sas_port", udev_device_get_sysname(port));
port_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_port", udev_device_get_sysname(port));
phy_count = udev_device_get_sysattr_value(port_sasdev, "num_phys");
if (!phy_count)
@ -206,12 +198,10 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
return NULL;
/* Get expander device */
expander_sasdev = udev_device_new_from_subsystem_sysname(
udev, "sas_device", udev_device_get_sysname(expander));
expander_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device", udev_device_get_sysname(expander));
if (expander_sasdev) {
/* Get expander's address */
sas_address = udev_device_get_sysattr_value(expander_sasdev,
"sas_address");
sas_address = udev_device_get_sysattr_value(expander_sasdev, "sas_address");
if (!sas_address)
return NULL;
}
@ -226,7 +216,6 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
}
static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path) {
struct udev *udev;
struct udev_device *transportdev;
_cleanup_(udev_device_unrefp) struct udev_device
*sessiondev = NULL, *conndev = NULL;
@ -236,7 +225,6 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
assert(parent);
assert(path);
udev = udev_device_get_udev(parent);
/* find iscsi session */
transportdev = parent;
@ -249,7 +237,7 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
}
/* find iscsi session device */
sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev));
sessiondev = udev_device_new_from_subsystem_sysname(NULL, "iscsi_session", udev_device_get_sysname(transportdev));
if (!sessiondev)
return NULL;
@ -258,7 +246,7 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
return NULL;
connname = strjoina("connection", udev_device_get_sysnum(transportdev), ":0");
conndev = udev_device_new_from_subsystem_sysname(udev, "iscsi_connection", connname);
conndev = udev_device_new_from_subsystem_sysname(NULL, "iscsi_connection", connname);
if (!conndev)
return NULL;
@ -273,7 +261,6 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
}
static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **path) {
struct udev *udev;
struct udev_device *targetdev, *target_parent;
_cleanup_(udev_device_unrefp) struct udev_device *atadev = NULL;
const char *port_no;
@ -281,7 +268,6 @@ static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **pa
assert(parent);
assert(path);
udev = udev_device_get_udev(parent);
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
if (!targetdev)
@ -291,7 +277,7 @@ static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **pa
if (!target_parent)
return NULL;
atadev = udev_device_new_from_subsystem_sysname(udev, "ata_port", udev_device_get_sysname(target_parent));
atadev = udev_device_new_from_subsystem_sysname(NULL, "ata_port", udev_device_get_sysname(target_parent));
if (!atadev)
return NULL;

View File

@ -29,7 +29,7 @@ static const struct udev_builtin *builtins[] = {
#endif
};
void udev_builtin_init(struct udev *udev) {
void udev_builtin_init(void) {
unsigned int i;
if (initialized)
@ -37,12 +37,12 @@ void udev_builtin_init(struct udev *udev) {
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i] && builtins[i]->init)
builtins[i]->init(udev);
builtins[i]->init();
initialized = true;
}
void udev_builtin_exit(struct udev *udev) {
void udev_builtin_exit(void) {
unsigned int i;
if (!initialized)
@ -50,21 +50,21 @@ void udev_builtin_exit(struct udev *udev) {
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i] && builtins[i]->exit)
builtins[i]->exit(udev);
builtins[i]->exit();
initialized = false;
}
bool udev_builtin_validate(struct udev *udev) {
bool udev_builtin_validate(void) {
unsigned int i;
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i] && builtins[i]->validate && builtins[i]->validate(udev))
if (builtins[i] && builtins[i]->validate && builtins[i]->validate())
return true;
return false;
}
void udev_builtin_list(struct udev *udev) {
void udev_builtin_list(void) {
unsigned int i;
for (i = 0; i < ELEMENTSOF(builtins); i++)
@ -112,7 +112,7 @@ int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const c
/* we need '0' here to reset the internal state */
optind = 0;
strscpy(arg, sizeof(arg), command);
udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
udev_build_argv(arg, &argc, argv);
return builtins[cmd]->cmd(dev, argc, argv, test);
}

View File

@ -56,7 +56,6 @@ struct udev_ctrl_msg {
struct udev_ctrl {
int refcount;
struct udev *udev;
int sock;
union sockaddr_union saddr;
socklen_t addrlen;
@ -71,7 +70,7 @@ struct udev_ctrl_connection {
int sock;
};
struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) {
struct udev_ctrl *udev_ctrl_new_from_fd(int fd) {
struct udev_ctrl *uctrl;
const int on = 1;
int r;
@ -80,7 +79,6 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) {
if (uctrl == NULL)
return NULL;
uctrl->refcount = 1;
uctrl->udev = udev;
if (fd < 0) {
uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
@ -108,8 +106,8 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) {
return uctrl;
}
struct udev_ctrl *udev_ctrl_new(struct udev *udev) {
return udev_ctrl_new_from_fd(udev, -1);
struct udev_ctrl *udev_ctrl_new(void) {
return udev_ctrl_new_from_fd(-1);
}
int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) {
@ -135,10 +133,6 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) {
return 0;
}
struct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl) {
return uctrl->udev;
}
static struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl) {
if (uctrl)
uctrl->refcount++;

View File

@ -33,16 +33,14 @@ typedef struct Spawn {
} Spawn;
struct udev_event *udev_event_new(struct udev_device *dev) {
struct udev *udev = udev_device_get_udev(dev);
struct udev_event *event;
event = new0(struct udev_event, 1);
if (event == NULL)
return NULL;
event->dev = dev;
event->udev = udev;
udev_list_init(udev, &event->run_list, false);
udev_list_init(udev, &event->seclabel_list, false);
udev_list_init(NULL, &event->run_list, false);
udev_list_init(NULL, &event->seclabel_list, false);
event->birth_usec = now(CLOCK_MONOTONIC);
return event;
}
@ -698,7 +696,7 @@ static int spawn_wait(struct udev_event *event,
return ret;
}
int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]) {
int udev_build_argv(char *cmd, int *argc, char *argv[]) {
int i = 0;
char *pos;
@ -771,7 +769,7 @@ int udev_event_spawn(struct udev_event *event,
errpipe[READ_END] = safe_close(errpipe[READ_END]);
strscpy(arg, sizeof(arg), cmd);
udev_build_argv(event->udev, arg, NULL, argv);
udev_build_argv(arg, NULL, argv);
/* allow programs in /usr/lib/udev/ to be called without the path */
if (argv[0][0] != '/') {
@ -845,7 +843,7 @@ void udev_event_execute_rules(struct udev_event *event,
udev_device_delete_db(dev);
if (major(udev_device_get_devnum(dev)) != 0)
udev_watch_end(event->udev, dev);
udev_watch_end(dev);
udev_rules_apply_to_event(rules, event,
timeout_usec, timeout_warn_usec,
@ -858,7 +856,7 @@ void udev_event_execute_rules(struct udev_event *event,
if (event->dev_db != NULL) {
/* disable watch during event processing */
if (major(udev_device_get_devnum(dev)) != 0)
udev_watch_end(event->udev, event->dev_db);
udev_watch_end(event->dev_db);
if (major(udev_device_get_devnum(dev)) == 0 &&
streq(udev_device_get_action(dev), "move"))

View File

@ -113,7 +113,6 @@ exit:
/* find device node of device with highest priority */
static const char *link_find_prioritized(struct udev_device *dev, bool add, const char *stackdir, char *buf, size_t bufsize) {
struct udev *udev = udev_device_get_udev(dev);
DIR *dir;
struct dirent *dent;
int priority = 0;
@ -142,7 +141,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
if (streq(dent->d_name, udev_device_get_id_filename(dev)))
continue;
dev_db = udev_device_new_from_device_id(udev, dent->d_name);
dev_db = udev_device_new_from_device_id(NULL, dent->d_name);
if (dev_db != NULL) {
const char *devnode;

View File

@ -50,7 +50,6 @@ static const char* const rules_dirs[] = {
};
struct udev_rules {
struct udev *udev;
usec_t dirs_ts_usec;
int resolve_names;
@ -700,7 +699,7 @@ static void attr_subst_subdir(char *attr, size_t len) {
}
}
static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value) {
static int get_key(char **line, char **key, enum operation_type *op, char **value) {
char *linepos;
char *temp;
unsigned i, j;
@ -802,7 +801,7 @@ static int get_key(struct udev *udev, char **line, char **key, enum operation_ty
}
/* extract possible KEY{attr} */
static const char *get_key_attribute(struct udev *udev, char *str) {
static const char *get_key_attribute(char *str) {
char *pos;
char *attr;
@ -1019,7 +1018,7 @@ static void add_rule(struct udev_rules *rules, char *line,
char *value;
enum operation_type op;
if (get_key(rules->udev, &linepos, &key, &op, &value) != 0) {
if (get_key(&linepos, &key, &op, &value) != 0) {
/* Avoid erroring on trailing whitespace. This is probably rare
* so save the work for the error case instead of always trying
* to strip the trailing whitespace with strstrip(). */
@ -1082,8 +1081,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_M_DRIVER, op, value, NULL);
} else if (startswith(key, "ATTR{")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("ATTR"));
attr = get_key_attribute(key + STRLEN("ATTR"));
if (attr == NULL)
LOG_AND_RETURN("error parsing %s attribute", "ATTR");
@ -1096,8 +1094,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_A_ATTR, op, value, attr);
} else if (startswith(key, "SYSCTL{")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("SYSCTL"));
attr = get_key_attribute(key + STRLEN("SYSCTL"));
if (attr == NULL)
LOG_AND_RETURN("error parsing %s attribute", "ATTR");
@ -1110,8 +1107,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_A_SYSCTL, op, value, attr);
} else if (startswith(key, "SECLABEL{")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("SECLABEL"));
attr = get_key_attribute(key + STRLEN("SECLABEL"));
if (attr == NULL)
LOG_AND_RETURN("error parsing %s attribute", "SECLABEL");
@ -1142,8 +1138,7 @@ static void add_rule(struct udev_rules *rules, char *line,
if (op > OP_MATCH_MAX)
LOG_AND_RETURN("invalid %s operation", "ATTRS");
attr = get_key_attribute(rules->udev,
key + STRLEN("ATTRS"));
attr = get_key_attribute(key + STRLEN("ATTRS"));
if (attr == NULL)
LOG_AND_RETURN("error parsing %s attribute", "ATTRS");
@ -1160,8 +1155,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_M_TAGS, op, value, NULL);
} else if (startswith(key, "ENV{")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("ENV"));
attr = get_key_attribute(key + STRLEN("ENV"));
if (attr == NULL)
LOG_AND_RETURN("error parsing %s attribute", "ENV");
@ -1207,8 +1201,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_M_RESULT, op, value, NULL);
} else if (startswith(key, "IMPORT")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("IMPORT"));
attr = get_key_attribute(key + STRLEN("IMPORT"));
if (attr == NULL) {
LOG_RULE_WARNING("ignoring IMPORT{} with missing type");
continue;
@ -1252,8 +1245,7 @@ static void add_rule(struct udev_rules *rules, char *line,
if (op > OP_MATCH_MAX)
LOG_AND_RETURN("invalid %s operation", "TEST");
attr = get_key_attribute(rules->udev,
key + STRLEN("TEST"));
attr = get_key_attribute(key + STRLEN("TEST"));
if (attr != NULL) {
mode = strtol(attr, NULL, 8);
rule_add_key(&rule_tmp, TK_M_TEST, op, value, &mode);
@ -1261,8 +1253,7 @@ static void add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_M_TEST, op, value, NULL);
} else if (startswith(key, "RUN")) {
attr = get_key_attribute(rules->udev,
key + STRLEN("RUN"));
attr = get_key_attribute(key + STRLEN("RUN"));
if (attr == NULL)
attr = "program";
if (op == OP_REMOVE)
@ -1513,7 +1504,7 @@ static int parse_file(struct udev_rules *rules, const char *filename) {
return 0;
}
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
struct udev_rules *udev_rules_new(int resolve_names) {
struct udev_rules *rules;
struct udev_list file_list;
struct token end_token;
@ -1523,9 +1514,8 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
rules = new0(struct udev_rules, 1);
if (rules == NULL)
return NULL;
rules->udev = udev;
rules->resolve_names = resolve_names;
udev_list_init(udev, &file_list, true);
udev_list_init(NULL, &file_list, true);
/* init token array and string buffer */
rules->tokens = malloc_multiply(PREALLOC_TOKEN, sizeof(struct token));

View File

@ -20,7 +20,7 @@ static int inotify_fd = -1;
* set to cloexec since we need our children to be able to add
* watches for us
*/
int udev_watch_init(struct udev *udev) {
int udev_watch_init(void) {
inotify_fd = inotify_init1(IN_CLOEXEC);
if (inotify_fd < 0)
log_error_errno(errno, "inotify_init failed: %m");
@ -30,7 +30,7 @@ int udev_watch_init(struct udev *udev) {
/* move any old watches directory out of the way, and then restore
* the watches
*/
void udev_watch_restore(struct udev *udev) {
void udev_watch_restore(void) {
if (inotify_fd < 0)
return;
@ -57,12 +57,12 @@ void udev_watch_restore(struct udev *udev) {
goto unlink;
device[len] = '\0';
dev = udev_device_new_from_device_id(udev, device);
dev = udev_device_new_from_device_id(NULL, device);
if (dev == NULL)
goto unlink;
log_debug("restoring old watch on '%s'", udev_device_get_devnode(dev));
udev_watch_begin(udev, dev);
udev_watch_begin(dev);
udev_device_unref(dev);
unlink:
(void) unlinkat(dirfd(dir), ent->d_name, 0);
@ -75,7 +75,7 @@ unlink:
log_error_errno(errno, "unable to move watches dir /run/udev/watch; old watches will not be restored: %m");
}
void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
void udev_watch_begin(struct udev_device *dev) {
char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
int wd;
int r;
@ -101,7 +101,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
udev_device_set_watch_handle(dev, wd);
}
void udev_watch_end(struct udev *udev, struct udev_device *dev) {
void udev_watch_end(struct udev_device *dev) {
int wd;
char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
@ -121,7 +121,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) {
udev_device_set_watch_handle(dev, -1);
}
struct udev_device *udev_watch_lookup(struct udev *udev, int wd) {
struct udev_device *udev_watch_lookup(int wd) {
char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
char device[UTIL_NAME_SIZE];
ssize_t len;
@ -135,5 +135,5 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd) {
return NULL;
device[len] = '\0';
return udev_device_new_from_device_id(udev, device);
return udev_device_new_from_device_id(NULL, device);
}

View File

@ -19,7 +19,6 @@
#include "util.h"
struct udev_event {
struct udev *udev;
struct udev_device *dev;
struct udev_device *dev_parent;
struct udev_device *dev_db;
@ -50,7 +49,7 @@ struct udev_event {
/* udev-rules.c */
struct udev_rules;
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
struct udev_rules *udev_rules_new(int resolve_names);
struct udev_rules *udev_rules_unref(struct udev_rules *rules);
bool udev_rules_check_timestamp(struct udev_rules *rules);
void udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event,
@ -76,14 +75,14 @@ void udev_event_execute_rules(struct udev_event *event,
struct udev_list *properties_list,
struct udev_rules *rules);
void udev_event_execute_run(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec);
int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]);
int udev_build_argv(char *cmd, int *argc, char *argv[]);
/* udev-watch.c */
int udev_watch_init(struct udev *udev);
void udev_watch_restore(struct udev *udev);
void udev_watch_begin(struct udev *udev, struct udev_device *dev);
void udev_watch_end(struct udev *udev, struct udev_device *dev);
struct udev_device *udev_watch_lookup(struct udev *udev, int wd);
int udev_watch_init(void);
void udev_watch_restore(void);
void udev_watch_begin(struct udev_device *dev);
void udev_watch_end(struct udev_device *dev);
struct udev_device *udev_watch_lookup(int wd);
/* udev-node.c */
void udev_node_add(struct udev_device *dev, bool apply,
@ -94,12 +93,11 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
/* udev-ctrl.c */
struct udev_ctrl;
struct udev_ctrl *udev_ctrl_new(struct udev *udev);
struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd);
struct udev_ctrl *udev_ctrl_new(void);
struct udev_ctrl *udev_ctrl_new_from_fd(int fd);
int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl);
struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
int udev_ctrl_cleanup(struct udev_ctrl *uctrl);
struct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl);
int udev_ctrl_get_fd(struct udev_ctrl *uctrl);
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout);
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout);
@ -150,9 +148,9 @@ struct udev_builtin {
const char *name;
int (*cmd)(struct udev_device *dev, int argc, char *argv[], bool test);
const char *help;
int (*init)(struct udev *udev);
void (*exit)(struct udev *udev);
bool (*validate)(struct udev *udev);
int (*init)(void);
void (*exit)(void);
bool (*validate)(void);
bool run_once;
};
#if HAVE_BLKID
@ -170,14 +168,14 @@ extern const struct udev_builtin udev_builtin_net_setup_link;
extern const struct udev_builtin udev_builtin_path_id;
extern const struct udev_builtin udev_builtin_usb_id;
extern const struct udev_builtin udev_builtin_uaccess;
void udev_builtin_init(struct udev *udev);
void udev_builtin_exit(struct udev *udev);
void udev_builtin_init(void);
void udev_builtin_exit(void);
enum udev_builtin_cmd udev_builtin_lookup(const char *command);
const char *udev_builtin_name(enum udev_builtin_cmd cmd);
bool udev_builtin_run_once(enum udev_builtin_cmd cmd);
int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test);
void udev_builtin_list(struct udev *udev);
bool udev_builtin_validate(struct udev *udev);
void udev_builtin_list(void);
bool udev_builtin_validate(void);
int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val);
int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *prefix, const char *modalias,
const char *filter, bool test);
@ -192,7 +190,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref);
/* udevadm commands */
struct udevadm_cmd {
const char *name;
int (*cmd)(struct udev *udev, int argc, char *argv[]);
int (*cmd)(int argc, char *argv[]);
const char *help;
int debug;
};

View File

@ -40,7 +40,7 @@ static void print_help(void) {
, program_invocation_short_name);
}
static int adm_control(struct udev *udev, int argc, char *argv[]) {
static int adm_control(int argc, char *argv[]) {
_cleanup_(udev_ctrl_unrefp) struct udev_ctrl *uctrl = NULL;
int timeout = 60;
int rc = 1, c;
@ -64,7 +64,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
if (must_be_root() < 0)
return 1;
uctrl = udev_ctrl_new(udev);
uctrl = udev_ctrl_new();
if (uctrl == NULL)
return 2;

View File

@ -436,7 +436,7 @@ static int insert_data(struct trie *trie, struct udev_list *match_list,
return 0;
}
static int import_file(struct udev *udev, struct trie *trie, const char *filename) {
static int import_file(struct trie *trie, const char *filename) {
enum {
HW_MATCH,
HW_DATA,
@ -447,7 +447,7 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam
struct udev_list match_list;
int r = 0, err;
udev_list_init(udev, &match_list, false);
udev_list_init(NULL, &match_list, false);
f = fopen(filename, "re");
if (f == NULL)
@ -553,7 +553,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
static int adm_hwdb(int argc, char *argv[]) {
enum {
ARG_USR = 0x100,
};
@ -644,7 +644,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
}
STRV_FOREACH(f, files) {
log_debug("reading file '%s'", *f);
if (import_file(udev, trie, *f) < 0 && strict)
if (import_file(trie, *f) < 0 && strict)
rc = EXIT_FAILURE;
}
strv_free(files);

View File

@ -155,11 +155,11 @@ static int stat_device(const char *name, bool export, const char *prefix) {
return 0;
}
static int export_devices(struct udev *udev) {
static int export_devices(void) {
_cleanup_(udev_enumerate_unrefp) struct udev_enumerate *udev_enumerate;
struct udev_list_entry *list_entry;
udev_enumerate = udev_enumerate_new(udev);
udev_enumerate = udev_enumerate_new(NULL);
if (udev_enumerate == NULL)
return -ENOMEM;
@ -167,7 +167,7 @@ static int export_devices(struct udev *udev) {
udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) {
_cleanup_(udev_device_unrefp) struct udev_device *device;
device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry));
device = udev_device_new_from_syspath(NULL, udev_list_entry_get_name(list_entry));
if (device != NULL)
print_record(device);
}
@ -203,7 +203,7 @@ static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
}
}
static void cleanup_db(struct udev *udev) {
static void cleanup_db(void) {
_cleanup_closedir_ DIR *dir1 = NULL, *dir2 = NULL, *dir3 = NULL, *dir4 = NULL, *dir5 = NULL;
(void) unlink("/run/udev/queue.bin");
@ -254,7 +254,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int uinfo(struct udev *udev, int argc, char *argv[]) {
static int uinfo(int argc, char *argv[]) {
_cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
bool root = 0;
bool export = 0;
@ -301,7 +301,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
return 2;
}
device = find_device(udev, optarg, "/dev/");
device = find_device(optarg, "/dev/");
if (device == NULL) {
fprintf(stderr, "device node not found\n");
return 2;
@ -314,7 +314,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
return 2;
}
device = find_device(udev, optarg, "/sys");
device = find_device(optarg, "/sys");
if (device == NULL) {
fprintf(stderr, "syspath not found\n");
return 2;
@ -348,11 +348,11 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
action = ACTION_ATTRIBUTE_WALK;
break;
case 'e':
if (export_devices(udev) < 0)
if (export_devices() < 0)
return 1;
return 0;
case 'c':
cleanup_db(udev);
cleanup_db();
return 0;
case 'x':
export = true;
@ -377,7 +377,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
help();
return 2;
}
device = find_device(udev, argv[optind], NULL);
device = find_device(argv[optind], NULL);
if (!device) {
fprintf(stderr, "Unknown device, --name=, --path=, or absolute path in /dev/ or /sys expected.\n");
return 4;
@ -439,7 +439,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
break;
case ACTION_ATTRIBUTE_WALK:
if (!device && argv[optind]) {
device = find_device(udev, argv[optind], NULL);
device = find_device(argv[optind], NULL);
if (!device) {
fprintf(stderr, "Unknown device, absolute path in /dev/ or /sys expected.\n");
return 4;

View File

@ -56,7 +56,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
static int adm_monitor(int argc, char *argv[]) {
struct sigaction act = {};
sigset_t mask;
bool prop = false;
@ -83,8 +83,8 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
{}
};
udev_list_init(udev, &subsystem_match_list, true);
udev_list_init(udev, &tag_match_list, true);
udev_list_init(NULL, &subsystem_match_list, true);
udev_list_init(NULL, &tag_match_list, true);
while ((c = getopt_long(argc, argv, "pekus:t:Vh", options, NULL)) >= 0)
switch (c) {
@ -153,7 +153,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
if (print_udev) {
struct udev_list_entry *entry;
udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
udev_monitor = udev_monitor_new_from_netlink(NULL, "udev");
if (udev_monitor == NULL) {
fprintf(stderr, "error: unable to create netlink socket\n");
return 1;
@ -195,7 +195,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
if (print_kernel) {
struct udev_list_entry *entry;
kernel_monitor = udev_monitor_new_from_netlink(udev, "kernel");
kernel_monitor = udev_monitor_new_from_netlink(NULL, "kernel");
if (kernel_monitor == NULL) {
fprintf(stderr, "error: unable to create netlink socket\n");
return 3;

View File

@ -28,7 +28,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int adm_settle(struct udev *udev, int argc, char *argv[]) {
static int adm_settle(int argc, char *argv[]) {
static const struct option options[] = {
{ "timeout", required_argument, NULL, 't' },
{ "exit-if-exists", required_argument, NULL, 'E' },
@ -98,7 +98,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
if (getuid() == 0) {
struct udev_ctrl *uctrl;
uctrl = udev_ctrl_new(udev);
uctrl = udev_ctrl_new();
if (uctrl != NULL) {
if (udev_ctrl_send_ping(uctrl, MAX(5U, timeout)) < 0) {
log_debug("no connection to daemon");
@ -109,7 +109,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
}
}
queue = udev_queue_new(udev);
queue = udev_queue_new(NULL);
if (!queue) {
log_error("unable to get udev queue");
return EXIT_FAILURE;

View File

@ -11,7 +11,7 @@
#include "udev.h"
#include "udevadm-util.h"
static void help(struct udev *udev) {
static void help(void) {
printf("%s test-builtin [OPTIONS] COMMAND DEVPATH\n\n"
"Test a built-in command.\n\n"
" -h --help Print this message\n"
@ -19,10 +19,10 @@ static void help(struct udev *udev) {
"Commands:\n"
, program_invocation_short_name);
udev_builtin_list(udev);
udev_builtin_list();
}
static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
static int adm_builtin(int argc, char *argv[]) {
static const struct option options[] = {
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
@ -41,14 +41,14 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
print_version();
goto out;
case 'h':
help(udev);
help();
goto out;
}
command = argv[optind++];
if (command == NULL) {
fprintf(stderr, "command missing\n");
help(udev);
help();
rc = 2;
goto out;
}
@ -60,12 +60,12 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
goto out;
}
udev_builtin_init(udev);
udev_builtin_init();
cmd = udev_builtin_lookup(command);
if (cmd >= UDEV_BUILTIN_MAX) {
fprintf(stderr, "unknown command '%s'\n", command);
help(udev);
help();
rc = 5;
goto out;
}
@ -77,7 +77,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
strscpy(filename, sizeof(filename), syspath);
delete_trailing_chars(filename, "/");
dev = udev_device_new_from_syspath(udev, filename);
dev = udev_device_new_from_syspath(NULL, filename);
if (dev == NULL) {
fprintf(stderr, "unable to open device '%s'\n\n", filename);
rc = 4;
@ -91,7 +91,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
}
out:
udev_device_unref(dev);
udev_builtin_exit(udev);
udev_builtin_exit();
return rc;
}

View File

@ -27,7 +27,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int adm_test(struct udev *udev, int argc, char *argv[]) {
static int adm_test(int argc, char *argv[]) {
int resolve_names = 1;
char filename[UTIL_PATH_SIZE];
const char *action = "add";
@ -93,9 +93,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
udev_builtin_init(udev);
udev_builtin_init();
rules = udev_rules_new(udev, resolve_names);
rules = udev_rules_new(resolve_names);
if (rules == NULL) {
fprintf(stderr, "error reading rules\n");
rc = 3;
@ -109,7 +109,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
strscpy(filename, sizeof(filename), syspath);
delete_trailing_chars(filename, "/");
dev = udev_device_new_from_synthetic_event(udev, filename, action);
dev = udev_device_new_from_synthetic_event(NULL, filename, action);
if (dev == NULL) {
fprintf(stderr, "unable to open device '%s'\n", filename);
rc = 4;
@ -139,7 +139,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
printf("run: '%s'\n", program);
}
out:
udev_builtin_exit(udev);
udev_builtin_exit();
return rc;
}

View File

@ -88,7 +88,7 @@ static void help(void) {
, program_invocation_short_name);
}
static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
static int adm_trigger(int argc, char *argv[]) {
enum {
ARG_NAME = 0x100,
};
@ -126,7 +126,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
_cleanup_set_free_free_ Set *settle_set = NULL;
int c, r;
udev_enumerate = udev_enumerate_new(udev);
udev_enumerate = udev_enumerate_new(NULL);
if (!udev_enumerate)
return 1;
@ -215,7 +215,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
case 'b': {
_cleanup_(udev_device_unrefp) struct udev_device *dev;
dev = find_device(udev, optarg, "/sys");
dev = find_device(optarg, "/sys");
if (!dev) {
log_error("unable to open the device '%s'", optarg);
return 2;
@ -235,7 +235,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
case ARG_NAME: {
_cleanup_(udev_device_unrefp) struct udev_device *dev;
dev = find_device(udev, optarg, "/dev/");
dev = find_device(optarg, "/dev/");
if (!dev) {
log_error("unable to open the device '%s'", optarg);
return 2;
@ -265,7 +265,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
for (; optind < argc; optind++) {
_cleanup_(udev_device_unrefp) struct udev_device *dev;
dev = find_device(udev, argv[optind], NULL);
dev = find_device(argv[optind], NULL);
if (!dev) {
log_error("unable to open the device '%s'", argv[optind]);
return 2;
@ -285,7 +285,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
return 1;
}
udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
udev_monitor = udev_monitor_new_from_netlink(NULL, "udev");
if (!udev_monitor) {
log_error("error: unable to create netlink socket");
return 3;

View File

@ -4,8 +4,7 @@
#include "string-util.h"
#include "udevadm-util.h"
struct udev_device *find_device(struct udev *udev,
const char *id,
struct udev_device *find_device(const char *id,
const char *prefix) {
assert(id);
@ -27,9 +26,9 @@ struct udev_device *find_device(struct udev *udev,
else
return NULL;
return udev_device_new_from_devnum(udev, type, statbuf.st_rdev);
return udev_device_new_from_devnum(NULL, type, statbuf.st_rdev);
} else if (path_startswith(id, "/sys/"))
return udev_device_new_from_syspath(udev, id);
return udev_device_new_from_syspath(NULL, id);
else
return NULL;
}

View File

@ -3,8 +3,7 @@
#include "udev.h"
struct udev_device *find_device(struct udev *udev,
const char *id,
struct udev_device *find_device(const char *id,
const char *prefix);
static inline void print_version(void) {

View File

@ -11,7 +11,7 @@
#include "udev-util.h"
#include "udev.h"
static int adm_version(struct udev *udev, int argc, char *argv[]) {
static int adm_version(int argc, char *argv[]) {
printf("%s\n", PACKAGE_VERSION);
return 0;
}
@ -21,7 +21,7 @@ static const struct udevadm_cmd udevadm_version = {
.cmd = adm_version,
};
static int adm_help(struct udev *udev, int argc, char *argv[]);
static int adm_help(int argc, char *argv[]);
static const struct udevadm_cmd udevadm_help = {
.name = "help",
@ -41,7 +41,7 @@ static const struct udevadm_cmd *udevadm_cmds[] = {
&udevadm_help,
};
static int adm_help(struct udev *udev, int argc, char *argv[]) {
static int adm_help(int argc, char *argv[]) {
_cleanup_free_ char *link = NULL;
size_t i;
int r;
@ -63,15 +63,14 @@ static int adm_help(struct udev *udev, int argc, char *argv[]) {
return 0;
}
static int run_command(struct udev *udev, const struct udevadm_cmd *cmd, int argc, char *argv[]) {
static int run_command(const struct udevadm_cmd *cmd, int argc, char *argv[]) {
if (cmd->debug)
log_set_max_level(LOG_DEBUG);
log_debug("calling: %s", cmd->name);
return cmd->cmd(udev, argc, argv);
return cmd->cmd(argc, argv);
}
int main(int argc, char *argv[]) {
struct udev *udev;
static const struct option options[] = {
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
@ -88,10 +87,6 @@ int main(int argc, char *argv[]) {
mac_selinux_init();
udev = udev_new();
if (udev == NULL)
goto out;
while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
switch (c) {
@ -100,11 +95,11 @@ int main(int argc, char *argv[]) {
break;
case 'h':
rc = adm_help(udev, argc, argv);
rc = adm_help(argc, argv);
goto out;
case 'V':
rc = adm_version(udev, argc, argv);
rc = adm_version(argc, argv);
goto out;
default:
@ -120,7 +115,7 @@ int main(int argc, char *argv[]) {
argv += optind;
/* we need '0' here to reset the internal state */
optind = 0;
rc = run_command(udev, udevadm_cmds[i], argc, argv);
rc = run_command(udevadm_cmds[i], argc, argv);
goto out;
}
@ -128,7 +123,6 @@ int main(int argc, char *argv[]) {
rc = 2;
out:
mac_selinux_finish();
udev_unref(udev);
log_close();
return rc;
}

View File

@ -63,7 +63,6 @@ static usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
static usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
typedef struct Manager {
struct udev *udev;
sd_event *event;
Hashmap *workers;
LIST_HEAD(struct event, events);
@ -98,7 +97,6 @@ enum event_state {
struct event {
LIST_FIELDS(struct event, event);
Manager *manager;
struct udev *udev;
struct udev_device *dev;
struct udev_device *dev_kernel;
struct worker *worker;
@ -278,13 +276,12 @@ static void manager_free(Manager *manager) {
if (!manager)
return;
udev_builtin_exit(manager->udev);
udev_builtin_exit();
sd_event_source_unref(manager->ctrl_event);
sd_event_source_unref(manager->uevent_event);
sd_event_source_unref(manager->inotify_event);
udev_unref(manager->udev);
sd_event_unref(manager->event);
manager_workers_free(manager);
event_queue_cleanup(manager, EVENT_UNDEF);
@ -323,13 +320,12 @@ static bool shall_lock_device(struct udev_device *dev) {
}
static void worker_spawn(Manager *manager, struct event *event) {
struct udev *udev = event->udev;
_cleanup_(udev_monitor_unrefp) struct udev_monitor *worker_monitor = NULL;
pid_t pid;
int r = 0;
/* listen for new events */
worker_monitor = udev_monitor_new_from_netlink(udev, NULL);
worker_monitor = udev_monitor_new_from_netlink(NULL, NULL);
if (worker_monitor == NULL)
return;
/* allow the main daemon netlink address to send devices to the worker */
@ -457,7 +453,7 @@ static void worker_spawn(Manager *manager, struct event *event) {
/* apply/restore inotify watch */
if (udev_event->inotify_watch) {
udev_watch_begin(udev, dev);
udev_watch_begin(dev);
udev_device_update_db(dev);
}
@ -591,7 +587,6 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
if (!event)
return -ENOMEM;
event->udev = udev_device_get_udev(dev);
event->manager = manager;
event->dev = dev;
event->dev_kernel = udev_device_shallow_clone(dev);
@ -762,7 +757,7 @@ static void manager_reload(Manager *manager) {
manager_kill_workers(manager);
manager->rules = udev_rules_unref(manager->rules);
udev_builtin_exit(manager->udev);
udev_builtin_exit();
sd_notifyf(false,
"READY=1\n"
@ -784,16 +779,16 @@ static void event_queue_start(Manager *manager) {
if (manager->last_usec == 0 ||
(usec - manager->last_usec) > 3 * USEC_PER_SEC) {
if (udev_rules_check_timestamp(manager->rules) ||
udev_builtin_validate(manager->udev))
udev_builtin_validate())
manager_reload(manager);
manager->last_usec = usec;
}
udev_builtin_init(manager->udev);
udev_builtin_init();
if (!manager->rules) {
manager->rules = udev_rules_new(manager->udev, arg_resolve_names);
manager->rules = udev_rules_new(arg_resolve_names);
if (!manager->rules)
return;
}
@ -1014,7 +1009,6 @@ static int synthesize_change(struct udev_device *dev) {
bool part_table_read = false;
bool has_partitions = false;
int fd;
struct udev *udev = udev_device_get_udev(dev);
_cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL;
struct udev_list_entry *item;
@ -1036,7 +1030,7 @@ static int synthesize_change(struct udev_device *dev) {
}
/* search for partitions */
e = udev_enumerate_new(udev);
e = udev_enumerate_new(NULL);
if (!e)
return -ENOMEM;
@ -1055,7 +1049,7 @@ static int synthesize_change(struct udev_device *dev) {
udev_list_entry_foreach(item, udev_enumerate_get_list_entry(e)) {
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
d = udev_device_new_from_syspath(NULL, udev_list_entry_get_name(item));
if (!d)
continue;
@ -1085,7 +1079,7 @@ static int synthesize_change(struct udev_device *dev) {
udev_list_entry_foreach(item, udev_enumerate_get_list_entry(e)) {
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
d = udev_device_new_from_syspath(NULL, udev_list_entry_get_name(item));
if (!d)
continue;
@ -1127,7 +1121,7 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda
FOREACH_INOTIFY_EVENT(e, buffer, l) {
_cleanup_(udev_device_unrefp) struct udev_device *dev = NULL;
dev = udev_watch_lookup(manager->udev, e->wd);
dev = udev_watch_lookup(e->wd);
if (!dev)
continue;
@ -1142,7 +1136,7 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda
*/
on_uevent(NULL, -1, 0, manager);
} else if (e->mask & IN_IGNORED)
udev_watch_end(manager->udev, dev);
udev_watch_end(dev);
}
return 1;
@ -1252,7 +1246,6 @@ static int on_post(sd_event_source *s, void *userdata) {
}
static int listen_fds(int *rctrl, int *rnetlink) {
_cleanup_(udev_unrefp) struct udev *udev = NULL;
int ctrl_fd = -1, netlink_fd = -1;
int fd, n, r;
@ -1284,11 +1277,7 @@ static int listen_fds(int *rctrl, int *rnetlink) {
if (ctrl_fd < 0) {
_cleanup_(udev_ctrl_unrefp) struct udev_ctrl *ctrl = NULL;
udev = udev_new();
if (!udev)
return -ENOMEM;
ctrl = udev_ctrl_new(udev);
ctrl = udev_ctrl_new();
if (!ctrl)
return log_error_errno(EINVAL, "error initializing udev control socket");
@ -1308,13 +1297,7 @@ static int listen_fds(int *rctrl, int *rnetlink) {
if (netlink_fd < 0) {
_cleanup_(udev_monitor_unrefp) struct udev_monitor *monitor = NULL;
if (!udev) {
udev = udev_new();
if (!udev)
return -ENOMEM;
}
monitor = udev_monitor_new_from_netlink(udev, "kernel");
monitor = udev_monitor_new_from_netlink(NULL, "kernel");
if (!monitor)
return log_error_errno(EINVAL, "error initializing netlink socket");
@ -1516,26 +1499,22 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
manager->worker_watch[WRITE_END] = -1;
manager->worker_watch[READ_END] = -1;
manager->udev = udev_new();
if (!manager->udev)
return log_error_errno(errno, "could not allocate udev context: %m");
udev_builtin_init();
udev_builtin_init(manager->udev);
manager->rules = udev_rules_new(manager->udev, arg_resolve_names);
manager->rules = udev_rules_new(arg_resolve_names);
if (!manager->rules)
return log_error_errno(ENOMEM, "error reading rules");
LIST_HEAD_INIT(manager->events);
udev_list_init(manager->udev, &manager->properties, true);
udev_list_init(NULL, &manager->properties, true);
manager->cgroup = cgroup;
manager->ctrl = udev_ctrl_new_from_fd(manager->udev, fd_ctrl);
manager->ctrl = udev_ctrl_new_from_fd(fd_ctrl);
if (!manager->ctrl)
return log_error_errno(EINVAL, "error taking over udev control socket");
manager->monitor = udev_monitor_new_from_netlink_fd(manager->udev, "kernel", fd_uevent);
manager->monitor = udev_monitor_new_from_netlink_fd(NULL, "kernel", fd_uevent);
if (!manager->monitor)
return log_error_errno(EINVAL, "error taking over netlink socket");
@ -1550,11 +1529,11 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
if (r < 0)
return log_error_errno(errno, "could not enable SO_PASSCRED: %m");
manager->fd_inotify = udev_watch_init(manager->udev);
manager->fd_inotify = udev_watch_init();
if (manager->fd_inotify < 0)
return log_error_errno(ENOMEM, "error initializing inotify");
udev_watch_restore(manager->udev);
udev_watch_restore();
/* block and listen to all signals on signalfd */
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, SIGHUP, SIGCHLD, -1) >= 0);