basic/main-func: also close the pager automatically
We generally want to close the pager last. This patch closes the pager last, after the static destuctor calls. This means that they can do logging and such like during normal program runtime.
This commit is contained in:
parent
ec5e594831
commit
a34c79d006
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "pager.h"
|
||||||
#include "static-destruct.h"
|
#include "static-destruct.h"
|
||||||
|
|
||||||
#define _DEFINE_MAIN_FUNCTION(impl, ret) \
|
#define _DEFINE_MAIN_FUNCTION(impl, ret) \
|
||||||
|
@ -10,6 +11,7 @@
|
||||||
int r; \
|
int r; \
|
||||||
r = impl(argc, argv); \
|
r = impl(argc, argv); \
|
||||||
static_destruct(); \
|
static_destruct(); \
|
||||||
|
pager_close(); \
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -282,12 +282,10 @@ static int run(int argc, char *argv[]) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to connect to bus: %m");
|
return log_error_errno(r, "Failed to connect to bus: %m");
|
||||||
|
|
||||||
if (arg_action == ACTION_LIST) {
|
if (arg_action == ACTION_LIST)
|
||||||
r = print_inhibitors(bus);
|
return print_inhibitors(bus);
|
||||||
pager_close();
|
|
||||||
return r;
|
|
||||||
|
|
||||||
} else {
|
else {
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
_cleanup_free_ char *w = NULL;
|
_cleanup_free_ char *w = NULL;
|
||||||
|
|
|
@ -266,21 +266,19 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
|
|
||||||
static int run(int argc, char *argv[]) {
|
static int run(int argc, char *argv[]) {
|
||||||
_cleanup_(ordered_hashmap_free_free_freep) OrderedHashmap *sysctl_options = NULL;
|
_cleanup_(ordered_hashmap_free_free_freep) OrderedHashmap *sysctl_options = NULL;
|
||||||
int r = 0, k;
|
int r, k;
|
||||||
|
|
||||||
r = parse_argv(argc, argv);
|
r = parse_argv(argc, argv);
|
||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
goto finish;
|
return r;
|
||||||
|
|
||||||
log_setup_service();
|
log_setup_service();
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
sysctl_options = ordered_hashmap_new(&path_hash_ops);
|
sysctl_options = ordered_hashmap_new(&path_hash_ops);
|
||||||
if (!sysctl_options) {
|
if (!sysctl_options)
|
||||||
r = log_oom();
|
return log_oom();
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
|
@ -297,16 +295,13 @@ static int run(int argc, char *argv[]) {
|
||||||
char **f;
|
char **f;
|
||||||
|
|
||||||
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("sysctl.d"));
|
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("sysctl.d"));
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to enumerate sysctl.d files: %m");
|
return log_error_errno(r, "Failed to enumerate sysctl.d files: %m");
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg_cat_config) {
|
if (arg_cat_config) {
|
||||||
(void) pager_open(arg_pager_flags);
|
(void) pager_open(arg_pager_flags);
|
||||||
|
|
||||||
r = cat_files(NULL, files, 0);
|
return cat_files(NULL, files, 0);
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STRV_FOREACH(f, files) {
|
STRV_FOREACH(f, files) {
|
||||||
|
@ -320,9 +315,6 @@ static int run(int argc, char *argv[]) {
|
||||||
if (k < 0 && r == 0)
|
if (k < 0 && r == 0)
|
||||||
r = k;
|
r = k;
|
||||||
|
|
||||||
finish:
|
|
||||||
pager_close();
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue