ifupdown: consistently update the state file when exiting
This commit is contained in:
parent
6999a125c8
commit
885126174d
1 changed files with 26 additions and 11 deletions
|
@ -186,6 +186,27 @@ change_auto_interfaces(struct lif_dict *collection, struct lif_dict *state, stru
|
|||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
update_state_file_and_exit(int rc, struct lif_dict *state)
|
||||
{
|
||||
if (exec_opts.mock)
|
||||
{
|
||||
exit(rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!lif_state_write_path(state, exec_opts.state_file))
|
||||
{
|
||||
fprintf(stderr, "%s: could not update %s\n", argv0, exec_opts.state_file);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
exit(rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
ifupdown_main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -217,9 +238,9 @@ ifupdown_main(int argc, char *argv[])
|
|||
if (match_opts.is_auto)
|
||||
{
|
||||
if (!change_auto_interfaces(&collection, &state, &match_opts))
|
||||
return EXIT_FAILURE;
|
||||
return update_state_file_and_exit(EXIT_FAILURE, &state);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return update_state_file_and_exit(EXIT_SUCCESS, &state);
|
||||
}
|
||||
else if (optind >= argc)
|
||||
generic_usage(self_applet, EXIT_FAILURE);
|
||||
|
@ -248,23 +269,17 @@ ifupdown_main(int argc, char *argv[])
|
|||
if (entry == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: unknown interface %s\n", argv0, argv[idx]);
|
||||
return EXIT_FAILURE;
|
||||
return update_state_file_and_exit(EXIT_FAILURE, &state);
|
||||
}
|
||||
|
||||
iface = entry->data;
|
||||
}
|
||||
|
||||
if (!change_interface(iface, &collection, &state, ifname))
|
||||
return EXIT_FAILURE;
|
||||
return update_state_file_and_exit(EXIT_FAILURE, &state);
|
||||
}
|
||||
|
||||
if (!exec_opts.mock && !lif_state_write_path(&state, exec_opts.state_file))
|
||||
{
|
||||
fprintf(stderr, "%s: could not update %s\n", argv0, exec_opts.state_file);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return update_state_file_and_exit(EXIT_SUCCESS, &state);
|
||||
}
|
||||
|
||||
struct if_applet ifup_applet = {
|
||||
|
|
Loading…
Reference in a new issue