resolvectl: use static destructor and define main through macro
This commit is contained in:
parent
7a83c3aee0
commit
f6aa61909e
|
@ -15,6 +15,7 @@
|
||||||
#include "escape.h"
|
#include "escape.h"
|
||||||
#include "gcrypt-util.h"
|
#include "gcrypt-util.h"
|
||||||
#include "in-addr-util.h"
|
#include "in-addr-util.h"
|
||||||
|
#include "main-func.h"
|
||||||
#include "netlink-util.h"
|
#include "netlink-util.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
|
@ -56,6 +57,11 @@ static const char *arg_set_dns_over_tls = NULL;
|
||||||
static const char *arg_set_dnssec = NULL;
|
static const char *arg_set_dnssec = NULL;
|
||||||
static char **arg_set_nta = NULL;
|
static char **arg_set_nta = NULL;
|
||||||
|
|
||||||
|
STATIC_DESTRUCTOR_REGISTER(arg_ifname, freep);
|
||||||
|
STATIC_DESTRUCTOR_REGISTER(arg_set_dns, strv_freep);
|
||||||
|
STATIC_DESTRUCTOR_REGISTER(arg_set_domain, strv_freep);
|
||||||
|
STATIC_DESTRUCTOR_REGISTER(arg_set_nta, strv_freep);
|
||||||
|
|
||||||
typedef enum StatusMode {
|
typedef enum StatusMode {
|
||||||
STATUS_ALL,
|
STATUS_ALL,
|
||||||
STATUS_DNS,
|
STATUS_DNS,
|
||||||
|
@ -3064,8 +3070,8 @@ static int compat_main(int argc, char *argv[], sd_bus *bus) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
static int run(int argc, char **argv) {
|
||||||
sd_bus *bus = NULL;
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
@ -3079,29 +3085,16 @@ int main(int argc, char **argv) {
|
||||||
else
|
else
|
||||||
r = native_parse_argv(argc, argv);
|
r = native_parse_argv(argc, argv);
|
||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
goto finish;
|
return r;
|
||||||
|
|
||||||
r = sd_bus_open_system(&bus);
|
r = sd_bus_open_system(&bus);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error_errno(r, "sd_bus_open_system: %m");
|
return log_error_errno(r, "sd_bus_open_system: %m");
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (STR_IN_SET(program_invocation_short_name, "systemd-resolve", "resolvconf"))
|
if (STR_IN_SET(program_invocation_short_name, "systemd-resolve", "resolvconf"))
|
||||||
r = compat_main(argc, argv, bus);
|
return compat_main(argc, argv, bus);
|
||||||
else
|
|
||||||
r = native_main(argc, argv, bus);
|
|
||||||
|
|
||||||
finish:
|
return native_main(argc, argv, bus);
|
||||||
/* make sure we terminate the bus connection first, and then close the
|
|
||||||
* pager, see issue #3543 for the details. */
|
|
||||||
sd_bus_flush_close_unref(bus);
|
|
||||||
pager_close();
|
|
||||||
|
|
||||||
free(arg_ifname);
|
|
||||||
strv_free(arg_set_dns);
|
|
||||||
strv_free(arg_set_domain);
|
|
||||||
strv_free(arg_set_nta);
|
|
||||||
|
|
||||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_MAIN_FUNCTION(run);
|
||||||
|
|
Loading…
Reference in a new issue