tree-wide: merge pager_open_if_enabled() to the pager_open()

Many subsystems define own pager_open_if_enabled() function which
checks '--no-pager' command line argument and open pager depends
on its value. All implementations of pager_open_if_enabled() are
the same. Let's merger this function with pager_open() from the
shared/pager.c and remove pager_open_if_enabled() from all subsytems
to prevent code duplication.
This commit is contained in:
Alexander Kuleshov 2016-02-20 00:25:13 +06:00
parent 16fe5e8b1d
commit ea4b98e657
15 changed files with 60 additions and 151 deletions

View file

@ -123,14 +123,6 @@ struct host_info {
char *architecture; char *architecture;
}; };
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) { static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
_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;
int r; int r;
@ -965,7 +957,7 @@ static int analyze_critical_chain(sd_bus *bus, char *names[]) {
} }
unit_times_hashmap = h; unit_times_hashmap = h;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
puts("The time after the unit is active or started is printed after the \"@\" character.\n" puts("The time after the unit is active or started is printed after the \"@\" character.\n"
"The time the unit takes to start is printed after the \"+\" character.\n"); "The time the unit takes to start is printed after the \"+\" character.\n");
@ -993,7 +985,7 @@ static int analyze_blame(sd_bus *bus) {
qsort(times, n, sizeof(struct unit_times), compare_unit_time); qsort(times, n, sizeof(struct unit_times), compare_unit_time);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
for (i = 0; i < (unsigned) n; i++) { for (i = 0; i < (unsigned) n; i++) {
char ts[FORMAT_TIMESPAN_MAX]; char ts[FORMAT_TIMESPAN_MAX];
@ -1206,7 +1198,7 @@ static int dump(sd_bus *bus, char **args) {
return -E2BIG; return -E2BIG;
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -1284,7 +1276,7 @@ static int set_log_target(sd_bus *bus, char **args) {
static void help(void) { static void help(void) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
printf("%s [OPTIONS...] {COMMAND} ...\n\n" printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Profile systemd, show unit dependencies, check unit files.\n\n" "Profile systemd, show unit dependencies, check unit files.\n\n"

View file

@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
goto finish; goto finish;
if (!arg_no_pager) { if (!arg_no_pager) {
r = pager_open(false); r = pager_open(arg_no_pager, false);
if (r > 0 && arg_full < 0) if (r > 0 && arg_full < 0)
arg_full = true; arg_full = true;
} }

View file

@ -102,7 +102,7 @@ static bool arg_crash_reboot = false;
static bool arg_confirm_spawn = false; static bool arg_confirm_spawn = false;
static ShowStatus arg_show_status = _SHOW_STATUS_UNSET; static ShowStatus arg_show_status = _SHOW_STATUS_UNSET;
static bool arg_switched_root = false; static bool arg_switched_root = false;
static int arg_no_pager = -1; static bool arg_no_pager = false;
static char ***arg_join_controllers = NULL; static char ***arg_join_controllers = NULL;
static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL; static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT; static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
@ -127,14 +127,6 @@ static bool arg_default_tasks_accounting = true;
static uint64_t arg_default_tasks_max = UINT64_C(512); static uint64_t arg_default_tasks_max = UINT64_C(512);
static sd_id128_t arg_machine_id = {}; static sd_id128_t arg_machine_id = {};
static void pager_open_if_enabled(void) {
if (arg_no_pager <= 0)
return;
pager_open(false);
}
noreturn static void freeze_or_reboot(void) { noreturn static void freeze_or_reboot(void) {
if (arg_crash_reboot) { if (arg_crash_reboot) {
@ -883,8 +875,6 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_TEST: case ARG_TEST:
arg_action = ACTION_TEST; arg_action = ACTION_TEST;
if (arg_no_pager < 0)
arg_no_pager = true;
break; break;
case ARG_NO_PAGER: case ARG_NO_PAGER:
@ -994,8 +984,6 @@ static int parse_argv(int argc, char *argv[]) {
case 'h': case 'h':
arg_action = ACTION_HELP; arg_action = ACTION_HELP;
if (arg_no_pager < 0)
arg_no_pager = true;
break; break;
case 'D': case 'D':
@ -1548,7 +1536,8 @@ int main(int argc, char *argv[]) {
if (arg_action == ACTION_TEST) if (arg_action == ACTION_TEST)
skip_setup = true; skip_setup = true;
pager_open_if_enabled(); if (arg_action == ACTION_TEST || arg_action == ACTION_HELP)
pager_open(arg_no_pager, false);
if (arg_action == ACTION_HELP) { if (arg_action == ACTION_HELP) {
retval = help(); retval = help();

View file

@ -54,7 +54,7 @@ static enum {
} arg_action = ACTION_LIST; } arg_action = ACTION_LIST;
static const char* arg_field = NULL; static const char* arg_field = NULL;
static const char *arg_directory = NULL; static const char *arg_directory = NULL;
static int arg_no_pager = false; static bool arg_no_pager = false;
static int arg_no_legend = false; static int arg_no_legend = false;
static int arg_one = false; static int arg_one = false;
static FILE* arg_output = NULL; static FILE* arg_output = NULL;
@ -852,9 +852,7 @@ int main(int argc, char *argv[]) {
case ACTION_LIST: case ACTION_LIST:
case ACTION_INFO: case ACTION_INFO:
if (!arg_no_pager) pager_open(arg_no_pager, false);
pager_open(false);
r = dump_list(j); r = dump_list(j);
break; break;

View file

@ -85,14 +85,6 @@ static enum {
(SHOW_MASKED | SHOW_EQUIVALENT | SHOW_REDIRECTED | SHOW_OVERRIDDEN | SHOW_EXTENDED) (SHOW_MASKED | SHOW_EQUIVALENT | SHOW_REDIRECTED | SHOW_OVERRIDDEN | SHOW_EXTENDED)
} arg_flags = 0; } arg_flags = 0;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static int equivalent(const char *a, const char *b) { static int equivalent(const char *a, const char *b) {
_cleanup_free_ char *x = NULL, *y = NULL; _cleanup_free_ char *x = NULL, *y = NULL;
@ -610,7 +602,7 @@ int main(int argc, char *argv[]) {
else if (arg_diff) else if (arg_diff)
arg_flags |= SHOW_OVERRIDDEN; arg_flags |= SHOW_OVERRIDDEN;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (optind < argc) { if (optind < argc) {
int i; int i;

View file

@ -225,14 +225,6 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
return 0; return 0;
} }
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(arg_pager_end);
}
static char *format_timestamp_maybe_utc(char *buf, size_t l, usec_t t) { static char *format_timestamp_maybe_utc(char *buf, size_t l, usec_t t) {
if (arg_utc) if (arg_utc)
@ -278,7 +270,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset
static void help(void) { static void help(void) {
pager_open_if_enabled(); pager_open(arg_no_pager, arg_pager_end);
printf("%s [OPTIONS...] [MATCHES...]\n\n" printf("%s [OPTIONS...] [MATCHES...]\n\n"
"Query the journal.\n\n" "Query the journal.\n\n"
@ -1183,7 +1175,7 @@ static int list_boots(sd_journal *j) {
if (count == 0) if (count == 0)
return count; return count;
pager_open_if_enabled(); pager_open(arg_no_pager, arg_pager_end);
/* numbers are one less, but we need an extra char for the sign */ /* numbers are one less, but we need an extra char for the sign */
w = DECIMAL_STR_WIDTH(count - 1) + 1; w = DECIMAL_STR_WIDTH(count - 1) + 1;
@ -2061,7 +2053,7 @@ int main(int argc, char *argv[]) {
} else { } else {
bool oneline = arg_action == ACTION_LIST_CATALOG; bool oneline = arg_action == ACTION_LIST_CATALOG;
pager_open_if_enabled(); pager_open(arg_no_pager, arg_pager_end);
if (optind < argc) if (optind < argc)
r = catalog_list_items(stdout, database, oneline, argv + optind); r = catalog_list_items(stdout, database, oneline, argv + optind);
@ -2368,7 +2360,7 @@ int main(int argc, char *argv[]) {
} }
if (!arg_follow) if (!arg_follow)
pager_open_if_enabled(); pager_open(arg_no_pager, arg_pager_end);
if (!arg_quiet) { if (!arg_quiet) {
usec_t start, end; usec_t start, end;

View file

@ -62,15 +62,6 @@ static bool arg_allow_interactive_authorization = true;
static bool arg_augment_creds = true; static bool arg_augment_creds = true;
static usec_t arg_timeout = 0; static usec_t arg_timeout = 0;
static void pager_open_if_enabled(void) {
/* Cache result before we open the pager */
if (arg_no_pager)
return;
pager_open(false);
}
#define NAME_IS_ACQUIRED INT_TO_PTR(1) #define NAME_IS_ACQUIRED INT_TO_PTR(1)
#define NAME_IS_ACTIVATABLE INT_TO_PTR(2) #define NAME_IS_ACTIVATABLE INT_TO_PTR(2)
@ -95,7 +86,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to list names: %m"); return log_error_errno(r, "Failed to list names: %m");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
names = hashmap_new(&string_hash_ops); names = hashmap_new(&string_hash_ops);
if (!names) if (!names)
@ -289,7 +280,7 @@ static void print_subtree(const char *prefix, const char *path, char **l) {
static void print_tree(const char *prefix, char **l) { static void print_tree(const char *prefix, char **l) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
prefix = strempty(prefix); prefix = strempty(prefix);
@ -409,7 +400,7 @@ static int tree_one(sd_bus *bus, const char *service, const char *prefix, bool m
p = NULL; p = NULL;
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
l = set_get_strv(done); l = set_get_strv(done);
if (!l) if (!l)
@ -438,7 +429,7 @@ static int tree(sd_bus *bus, char **argv) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to get name list: %m"); return log_error_errno(r, "Failed to get name list: %m");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
STRV_FOREACH(i, names) { STRV_FOREACH(i, names) {
int q; int q;
@ -468,7 +459,7 @@ static int tree(sd_bus *bus, char **argv) {
printf("\n"); printf("\n");
if (argv[2]) { if (argv[2]) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal()); printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
} }
@ -992,7 +983,7 @@ static int introspect(sd_bus *bus, char **argv) {
return bus_log_parse_error(r); return bus_log_parse_error(r);
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
name_width = strlen("NAME"); name_width = strlen("NAME");
type_width = strlen("TYPE"); type_width = strlen("TYPE");
@ -1559,7 +1550,7 @@ static int call(sd_bus *bus, char *argv[]) {
if (r == 0 && !arg_quiet) { if (r == 0 && !arg_quiet) {
if (arg_verbose) { if (arg_verbose) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = bus_message_dump(reply, stdout, 0); r = bus_message_dump(reply, stdout, 0);
if (r < 0) if (r < 0)
@ -1614,7 +1605,7 @@ static int get_property(sd_bus *bus, char *argv[]) {
return bus_log_parse_error(r); return bus_log_parse_error(r);
if (arg_verbose) { if (arg_verbose) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_SUBTREE_ONLY); r = bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_SUBTREE_ONLY);
if (r < 0) if (r < 0)

View file

@ -46,14 +46,6 @@ static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static char *arg_host = NULL; static char *arg_host = NULL;
static bool arg_convert = true; static bool arg_convert = true;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static void polkit_agent_open_if_enabled(void) { static void polkit_agent_open_if_enabled(void) {
/* Open the polkit agent as a child process if necessary */ /* Open the polkit agent as a child process if necessary */
@ -239,7 +231,7 @@ static int list_locales(sd_bus *bus, char **args, unsigned n) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read list of locales: %m"); return log_error_errno(r, "Failed to read list of locales: %m");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
strv_print(l); strv_print(l);
return 0; return 0;
@ -341,7 +333,7 @@ static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
strv_sort(l); strv_sort(l);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
strv_print(l); strv_print(l);
@ -479,7 +471,7 @@ static int list_x11_keymaps(sd_bus *bus, char **args, unsigned n) {
strv_sort(list); strv_sort(list);
strv_uniq(list); strv_uniq(list);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
strv_print(list); strv_print(list);
return 0; return 0;

View file

@ -59,14 +59,6 @@ static bool arg_ask_password = true;
static unsigned arg_lines = 10; static unsigned arg_lines = 10;
static OutputMode arg_output = OUTPUT_SHORT; static OutputMode arg_output = OUTPUT_SHORT;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static void polkit_agent_open_if_enabled(void) { static void polkit_agent_open_if_enabled(void) {
/* Open the polkit agent as a child process if necessary */ /* Open the polkit agent as a child process if necessary */
@ -101,7 +93,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
assert(argv); assert(argv);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -148,7 +140,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
assert(argv); assert(argv);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -194,7 +186,7 @@ static int list_seats(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
assert(argv); assert(argv);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -858,7 +850,7 @@ static int show_session(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status"); properties = !strstr(argv[0], "status");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (argc <= 1) { if (argc <= 1) {
/* If not argument is specified inspect the manager /* If not argument is specified inspect the manager
@ -914,7 +906,7 @@ static int show_user(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status"); properties = !strstr(argv[0], "status");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (argc <= 1) { if (argc <= 1) {
/* If not argument is specified inspect the manager /* If not argument is specified inspect the manager
@ -974,7 +966,7 @@ static int show_seat(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status"); properties = !strstr(argv[0], "status");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (argc <= 1) { if (argc <= 1) {
/* If not argument is specified inspect the manager /* If not argument is specified inspect the manager

View file

@ -80,14 +80,6 @@ static const char* arg_format = NULL;
static const char *arg_uid = NULL; static const char *arg_uid = NULL;
static char **arg_setenv = NULL; static char **arg_setenv = NULL;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static void polkit_agent_open_if_enabled(void) { static void polkit_agent_open_if_enabled(void) {
/* Open the polkit agent as a child process if necessary */ /* Open the polkit agent as a child process if necessary */
@ -135,7 +127,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -238,7 +230,7 @@ static int list_images(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -707,7 +699,7 @@ static int show_machine(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status"); properties = !strstr(argv[0], "status");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (properties && argc <= 1) { if (properties && argc <= 1) {
@ -956,7 +948,7 @@ static int show_image(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status"); properties = !strstr(argv[0], "status");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (argc <= 1) { if (argc <= 1) {
@ -2189,7 +2181,7 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
double progress; double progress;
int r; int r;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,

View file

@ -53,14 +53,6 @@ static bool arg_no_pager = false;
static bool arg_legend = true; static bool arg_legend = true;
static bool arg_all = false; static bool arg_all = false;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static int link_get_type_string(unsigned short iftype, sd_device *d, char **ret) { static int link_get_type_string(unsigned short iftype, sd_device *d, char **ret) {
const char *t; const char *t;
char *p; char *p;
@ -300,7 +292,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
if (c < 0) if (c < 0)
return c; return c;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (arg_legend) if (arg_legend)
printf("%3s %-16s %-18s %-11s %-10s\n", printf("%3s %-16s %-18s %-11s %-10s\n",
@ -854,7 +846,7 @@ static int link_status(int argc, char *argv[], void *userdata) {
_cleanup_free_ LinkInfo *links = NULL; _cleanup_free_ LinkInfo *links = NULL;
int r, c, i; int r, c, i;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = sd_netlink_open(&rtnl); r = sd_netlink_open(&rtnl);
if (r < 0) if (r < 0)
@ -917,7 +909,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
if (c < 0) if (c < 0)
return c; return c;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (arg_legend) if (arg_legend)
printf("%-16s %-17s %-16s %-11s %-17s %-16s\n", printf("%-16s %-17s %-16s %-11s %-17s %-16s\n",

View file

@ -52,11 +52,14 @@ noreturn static void pager_fallback(void) {
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
int pager_open(bool jump_to_end) { int pager_open(bool no_pager, bool jump_to_end) {
_cleanup_close_pair_ int fd[2] = { -1, -1 }; _cleanup_close_pair_ int fd[2] = { -1, -1 };
const char *pager; const char *pager;
pid_t parent_pid; pid_t parent_pid;
if (no_pager)
return 0;
if (pager_pid > 0) if (pager_pid > 0)
return 1; return 1;

View file

@ -23,7 +23,7 @@
#include "macro.h" #include "macro.h"
int pager_open(bool jump_to_end); int pager_open(bool no_pager, bool jump_to_end);
void pager_close(void); void pager_close(void);
bool pager_have(void) _pure_; bool pager_have(void) _pure_;

View file

@ -200,14 +200,6 @@ static void release_busses(void) {
busses[w] = sd_bus_flush_close_unref(busses[w]); busses[w] = sd_bus_flush_close_unref(busses[w]);
} }
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static void ask_password_agent_open_if_enabled(void) { static void ask_password_agent_open_if_enabled(void) {
/* Open the password agent as a child process if necessary */ /* Open the password agent as a child process if necessary */
@ -678,7 +670,7 @@ static int list_units(int argc, char *argv[], void *userdata) {
sd_bus *bus; sd_bus *bus;
int r; int r;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -890,7 +882,7 @@ static int list_sockets(int argc, char *argv[], void *userdata) {
int r = 0, n; int r = 0, n;
sd_bus *bus; sd_bus *bus;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -1197,7 +1189,7 @@ static int list_timers(int argc, char *argv[], void *userdata) {
sd_bus *bus; sd_bus *bus;
int r = 0; int r = 0;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -1365,7 +1357,7 @@ static int list_unit_files(int argc, char *argv[], void *userdata) {
char *path; char *path;
int r; int r;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (install_client_side()) { if (install_client_side()) {
Hashmap *h; Hashmap *h;
@ -1679,7 +1671,7 @@ static int list_dependencies(int argc, char *argv[], void *userdata) {
} else } else
u = SPECIAL_DEFAULT_TARGET; u = SPECIAL_DEFAULT_TARGET;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -1910,7 +1902,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
return -EPERM; return -EPERM;
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -2067,7 +2059,7 @@ static void output_jobs_list(const struct job_info* jobs, unsigned n, bool skipp
return; return;
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
id_len = strlen("JOB"); id_len = strlen("JOB");
unit_len = strlen("UNIT"); unit_len = strlen("UNIT");
@ -2137,7 +2129,7 @@ static int list_jobs(int argc, char *argv[], void *userdata) {
int r; int r;
bool skipped = false; bool skipped = false;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -4559,7 +4551,7 @@ static int show_all(
if (r < 0) if (r < 0)
return r; return r;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
c = (unsigned) r; c = (unsigned) r;
@ -4654,7 +4646,7 @@ static int show(int argc, char *argv[], void *userdata) {
return -EINVAL; return -EINVAL;
} }
pager_open_if_enabled(); pager_open(arg_no_pager, false);
if (show_status) if (show_status)
/* Increase max number of open files to 16K if we can, we /* Increase max number of open files to 16K if we can, we
@ -4672,7 +4664,7 @@ static int show(int argc, char *argv[], void *userdata) {
if (show_status && argc <= 1) { if (show_status && argc <= 1) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
show_system_status(bus); show_system_status(bus);
new_line = true; new_line = true;
@ -4813,7 +4805,7 @@ static int cat(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to expand names: %m"); return log_error_errno(r, "Failed to expand names: %m");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
STRV_FOREACH(name, names) { STRV_FOREACH(name, names) {
_cleanup_free_ char *fragment_path = NULL; _cleanup_free_ char *fragment_path = NULL;
@ -5003,7 +4995,7 @@ static int show_environment(int argc, char *argv[], void *userdata) {
sd_bus *bus; sd_bus *bus;
int r; int r;
pager_open_if_enabled(); pager_open(arg_no_pager, false);
r = acquire_bus(BUS_MANAGER, &bus); r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0) if (r < 0)
@ -6178,7 +6170,7 @@ end:
static void systemctl_help(void) { static void systemctl_help(void) {
pager_open_if_enabled(); pager_open(arg_no_pager, false);
printf("%s [OPTIONS...] {COMMAND} ...\n\n" printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Query or send control commands to the systemd manager.\n\n" "Query or send control commands to the systemd manager.\n\n"

View file

@ -40,14 +40,6 @@ static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static char *arg_host = NULL; static char *arg_host = NULL;
static bool arg_adjust_system_clock = false; static bool arg_adjust_system_clock = false;
static void pager_open_if_enabled(void) {
if (arg_no_pager)
return;
pager_open(false);
}
static void polkit_agent_open_if_enabled(void) { static void polkit_agent_open_if_enabled(void) {
/* Open the polkit agent as a child process if necessary */ /* Open the polkit agent as a child process if necessary */
@ -313,7 +305,7 @@ static int list_timezones(sd_bus *bus, char **args, unsigned n) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read list of time zones: %m"); return log_error_errno(r, "Failed to read list of time zones: %m");
pager_open_if_enabled(); pager_open(arg_no_pager, false);
strv_print(zones); strv_print(zones);
return 0; return 0;