udev: do not skip the execution of RUN when renaming a network device fails

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
This commit is contained in:
Kay Sievers 2014-05-15 17:25:25 -04:00 committed by Anthony G. Basile
parent 47ef6b2c66
commit db992ba3a7
5 changed files with 25 additions and 31 deletions

View File

@ -835,13 +835,12 @@ static int rename_netif(struct udev_event *event)
return rename_netif_dev_fromname_toname(event->dev,udev_device_get_sysname(event->dev),event->name);
}
int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigmask)
void udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigmask)
{
struct udev_device *dev = event->dev;
int err = 0;
if (udev_device_get_subsystem(dev) == NULL)
return -1;
return;
if (streq(udev_device_get_action(dev), "remove")) {
udev_device_read_db(dev, NULL);
@ -889,9 +888,10 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
* the current name IS used AND the target name != the current name
*/
int r;
if (udev_device_get_ifindex(dev) > 0 && streq(udev_device_get_action(dev), "add") &&
#ifdef ENABLE_RULE_GENERATOR
(event->name == NULL && (err=udev_rules_assigning_name_to(rules,udev_device_get_sysname(dev))) > 0 ||
(event->name == NULL && (r=udev_rules_assigning_name_to(rules,udev_device_get_sysname(dev))) > 0 ||
event->name != NULL && !streq(event->name, udev_device_get_sysname(dev)))) {
#else
event->name != NULL && !streq(event->name, udev_device_get_sysname(dev))) {
@ -902,8 +902,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
#ifdef ENABLE_RULE_GENERATOR
char newifname[IFNAMSIZ];
/* err is the number of rules that assign a device with NAME= this sysname */
if (err > 0 || (err=udev_rules_assigning_name_to(rules,udev_device_get_sysname(dev))) > 0) {
/* r is the number of rules that assign a device with NAME= this sysname */
if (r > 0 || (r=udev_rules_assigning_name_to(rules,udev_device_get_sysname(dev))) > 0) {
/* have a conflict, rename to a temp name */
char *newpos;
int ifidnum;
@ -917,12 +917,12 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
/* use udev_device_get_ifindex(dev) as it is unique to every iface */
snprintf(pos,IFNAMSIZ+(newifname-pos), "%d", 128 - udev_device_get_ifindex(dev));
/* note, err > 0, which will skip the post-rename stuff if no rename occurs */
/* note, r > 0, which will skip the post-rename stuff if no rename occurs */
/* if sysname isn't already the tmpname (ie there is no numeric component), do the rename */
if (!streq(newifname,udev_device_get_sysname(dev))) {
err = rename_netif_dev_fromname_toname(dev,udev_device_get_sysname(dev),newifname);
if (err == 0) {
r = rename_netif_dev_fromname_toname(dev,udev_device_get_sysname(dev),newifname);
if (r == 0) {
finalifname = newifname;
log_debug("renamed netif to '%s' for collision avoidance\n", newifname);
} else {
@ -931,22 +931,22 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
}
/* rename it now to its final target if its not already there */
if (event->name != NULL && !streq(event->name, newifname)) {
err = rename_netif_dev_fromname_toname(dev,newifname,event->name);
if (err == 0)
r = rename_netif_dev_fromname_toname(dev,newifname,event->name);
if (r == 0)
finalifname = event->name;
}
} else { /* no need to rename to a tempname first, do a regular direct rename to event->name */
err = 1; /* skip the post-rename stuff if no rename occurs */
r = 1; /* skip the post-rename stuff if no rename occurs */
if (!streq(event->name, udev_device_get_sysname(dev)))
err = rename_netif(event);
r = rename_netif(event);
}
#else
err = rename_netif(event);
r = rename_netif(event);
#endif
if (err == 0) {
if (r >= 0) {
log_debug("renamed netif to '%s'", finalifname);
/* remember old name */
@ -1009,7 +1009,6 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
udev_device_unref(event->dev_db);
event->dev_db = NULL;
}
return err;
}
void udev_event_execute_run(struct udev_event *event, const sigset_t *sigmask)

View File

@ -84,7 +84,7 @@ int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string,
int udev_event_spawn(struct udev_event *event,
const char *cmd, char **envp, const sigset_t *sigmask,
char *result, size_t ressize);
int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigset);
void udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigset);
void udev_event_execute_run(struct udev_event *event, const sigset_t *sigset);
int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]);

View File

@ -43,7 +43,6 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
_cleanup_udev_device_unref_ struct udev_device *dev = NULL;
_cleanup_udev_event_unref_ struct udev_event *event = NULL;
sigset_t mask, sigmask_orig;
int err;
int rc = 0, c;
static const struct option options[] = {
@ -139,18 +138,16 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
goto out;
}
err = udev_event_execute_rules(event, rules, &sigmask_orig);
udev_event_execute_rules(event, rules, &sigmask_orig);
udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev))
printf("%s=%s\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
if (err == 0) {
udev_list_entry_foreach(entry, udev_list_get_entry(&event->run_list)) {
char program[UTIL_PATH_SIZE];
udev_list_entry_foreach(entry, udev_list_get_entry(&event->run_list)) {
char program[UTIL_PATH_SIZE];
udev_event_apply_format(event, udev_list_entry_get_name(entry), program, sizeof(program));
printf("run: '%s'\n", program);
}
udev_event_apply_format(event, udev_list_entry_get_name(entry), program, sizeof(program));
printf("run: '%s'\n", program);
}
out:
if (event != NULL && event->fd_signal >= 0)

View File

@ -307,10 +307,9 @@ static void worker_new(struct event *event)
}
/* apply rules, create node, symlinks */
err = udev_event_execute_rules(udev_event, rules, &sigmask_orig);
udev_event_execute_rules(udev_event, rules, &sigmask_orig);
if (err == 0)
udev_event_execute_run(udev_event, &sigmask_orig);
udev_event_execute_run(udev_event, &sigmask_orig);
/* apply/restore inotify watch */
if (err == 0 && udev_event->inotify_watch) {

View File

@ -165,9 +165,8 @@ int main(int argc, char *argv[]) {
}
}
err = udev_event_execute_rules(event, rules, &sigmask_orig);
if (err == 0)
udev_event_execute_run(event, NULL);
udev_event_execute_rules(event, rules, &sigmask_orig);
udev_event_execute_run(event, NULL);
out:
if (event != NULL && event->fd_signal >= 0)
close(event->fd_signal);