mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
binfmt,sysctl,sysuers,tmpfiles: add auto-paging for --cat-config commands
The output of these commands is really long, and already enriched with color. Let's add auto-paging to make this easier to digest.
This commit is contained in:
parent
ba1dc1a12b
commit
dcd5c891cb
@ -56,6 +56,7 @@
|
||||
<refsect1><title>Options</title>
|
||||
<variablelist>
|
||||
<xi:include href="standard-options.xml" xpointer="cat-config" />
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
</variablelist>
|
||||
|
@ -80,6 +80,7 @@
|
||||
</varlistentry>
|
||||
|
||||
<xi:include href="standard-options.xml" xpointer="cat-config" />
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
|
||||
|
@ -125,6 +125,7 @@
|
||||
</varlistentry>
|
||||
|
||||
<xi:include href="standard-options.xml" xpointer="cat-config" />
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
</variablelist>
|
||||
|
@ -184,6 +184,7 @@
|
||||
</varlistentry>
|
||||
|
||||
<xi:include href="standard-options.xml" xpointer="cat-config" />
|
||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
</variablelist>
|
||||
|
@ -19,12 +19,14 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "pager.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static bool arg_cat_config = false;
|
||||
static bool arg_no_pager = false;
|
||||
|
||||
static int delete_rule(const char *rule) {
|
||||
_cleanup_free_ char *x = NULL, *fn = NULL;
|
||||
@ -104,6 +106,7 @@ static void help(void) {
|
||||
" -h --help Show this help\n"
|
||||
" --version Show package version\n"
|
||||
" --cat-config Show configuration files\n"
|
||||
" --no-pager Do not pipe output into a pager\n"
|
||||
, program_invocation_short_name);
|
||||
}
|
||||
|
||||
@ -112,12 +115,14 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
enum {
|
||||
ARG_VERSION = 0x100,
|
||||
ARG_CAT_CONFIG,
|
||||
ARG_NO_PAGER,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, ARG_VERSION },
|
||||
{ "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, ARG_VERSION },
|
||||
{ "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
|
||||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -141,6 +146,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_cat_config = true;
|
||||
break;
|
||||
|
||||
case ARG_NO_PAGER:
|
||||
arg_no_pager = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
return -EINVAL;
|
||||
|
||||
@ -190,6 +199,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (arg_cat_config) {
|
||||
(void) pager_open(arg_no_pager, false);
|
||||
|
||||
r = cat_files(NULL, files, 0);
|
||||
goto finish;
|
||||
}
|
||||
@ -205,5 +216,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
finish:
|
||||
pager_close();
|
||||
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "fileio.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "pager.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
@ -28,6 +29,7 @@
|
||||
|
||||
static char **arg_prefixes = NULL;
|
||||
static bool arg_cat_config = false;
|
||||
static bool arg_no_pager = false;
|
||||
|
||||
static int apply_all(OrderedHashmap *sysctl_options) {
|
||||
char *property, *value;
|
||||
@ -170,6 +172,7 @@ static void help(void) {
|
||||
" --version Show package version\n"
|
||||
" --cat-config Show configuration files\n"
|
||||
" --prefix=PATH Only apply rules with the specified prefix\n"
|
||||
" --no-pager Do not pipe output into a pager\n"
|
||||
, program_invocation_short_name);
|
||||
}
|
||||
|
||||
@ -179,6 +182,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
ARG_VERSION = 0x100,
|
||||
ARG_CAT_CONFIG,
|
||||
ARG_PREFIX,
|
||||
ARG_NO_PAGER,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
@ -186,6 +190,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{ "version", no_argument, NULL, ARG_VERSION },
|
||||
{ "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
|
||||
{ "prefix", required_argument, NULL, ARG_PREFIX },
|
||||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -231,6 +236,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_NO_PAGER:
|
||||
arg_no_pager = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
return -EINVAL;
|
||||
|
||||
@ -287,6 +296,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (arg_cat_config) {
|
||||
(void) pager_open(arg_no_pager, false);
|
||||
|
||||
r = cat_files(NULL, files, 0);
|
||||
goto finish;
|
||||
}
|
||||
@ -303,6 +314,8 @@ int main(int argc, char *argv[]) {
|
||||
r = k;
|
||||
|
||||
finish:
|
||||
pager_close();
|
||||
|
||||
ordered_hashmap_free_free_free(sysctl_options);
|
||||
strv_free(arg_prefixes);
|
||||
|
||||
|
@ -13,10 +13,11 @@
|
||||
#include "copy.h"
|
||||
#include "def.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "fileio-label.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "pager.h"
|
||||
#include "path-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "smack-util.h"
|
||||
@ -35,6 +36,7 @@ typedef enum ItemType {
|
||||
ADD_MEMBER = 'm',
|
||||
ADD_RANGE = 'r',
|
||||
} ItemType;
|
||||
|
||||
typedef struct Item {
|
||||
ItemType type;
|
||||
|
||||
@ -65,6 +67,7 @@ static char *arg_root = NULL;
|
||||
static bool arg_cat_config = false;
|
||||
static const char *arg_replace = NULL;
|
||||
static bool arg_inline = false;
|
||||
static bool arg_no_pager = false;
|
||||
|
||||
static OrderedHashmap *users = NULL, *groups = NULL;
|
||||
static OrderedHashmap *todo_uids = NULL, *todo_gids = NULL;
|
||||
@ -1764,6 +1767,8 @@ static int cat_config(void) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) pager_open(arg_no_pager, false);
|
||||
|
||||
return cat_files(NULL, files, 0);
|
||||
}
|
||||
|
||||
@ -1776,6 +1781,7 @@ static void help(void) {
|
||||
" --root=PATH Operate on an alternate filesystem root\n"
|
||||
" --replace=PATH Treat arguments as replacement for PATH\n"
|
||||
" --inline Treat arguments as configuration lines\n"
|
||||
" --no-pager Do not pipe output into a pager\n"
|
||||
, program_invocation_short_name);
|
||||
}
|
||||
|
||||
@ -1787,6 +1793,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
ARG_ROOT,
|
||||
ARG_REPLACE,
|
||||
ARG_INLINE,
|
||||
ARG_NO_PAGER,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
@ -1796,6 +1803,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{ "root", required_argument, NULL, ARG_ROOT },
|
||||
{ "replace", required_argument, NULL, ARG_REPLACE },
|
||||
{ "inline", no_argument, NULL, ARG_INLINE },
|
||||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -1839,6 +1847,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_inline = true;
|
||||
break;
|
||||
|
||||
case ARG_NO_PAGER:
|
||||
arg_no_pager = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
return -EINVAL;
|
||||
|
||||
@ -1999,6 +2011,8 @@ int main(int argc, char *argv[]) {
|
||||
log_error_errno(r, "Failed to write files: %m");
|
||||
|
||||
finish:
|
||||
pager_close();
|
||||
|
||||
ordered_hashmap_free_with_destructor(groups, item_free);
|
||||
ordered_hashmap_free_with_destructor(users, item_free);
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount-util.h"
|
||||
#include "pager.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
@ -156,6 +157,7 @@ static bool arg_create = false;
|
||||
static bool arg_clean = false;
|
||||
static bool arg_remove = false;
|
||||
static bool arg_boot = false;
|
||||
static bool arg_no_pager = false;
|
||||
|
||||
static char **arg_include_prefixes = NULL;
|
||||
static char **arg_exclude_prefixes = NULL;
|
||||
@ -2511,6 +2513,7 @@ static void help(void) {
|
||||
" --exclude-prefix=PATH Ignore rules with the specified prefix\n"
|
||||
" --root=PATH Operate on an alternate filesystem root\n"
|
||||
" --replace=PATH Treat arguments as replacement for PATH\n"
|
||||
" --no-pager Do not pipe output into a pager\n"
|
||||
, program_invocation_short_name);
|
||||
}
|
||||
|
||||
@ -2528,6 +2531,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
ARG_EXCLUDE_PREFIX,
|
||||
ARG_ROOT,
|
||||
ARG_REPLACE,
|
||||
ARG_NO_PAGER,
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
@ -2543,6 +2547,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{ "exclude-prefix", required_argument, NULL, ARG_EXCLUDE_PREFIX },
|
||||
{ "root", required_argument, NULL, ARG_ROOT },
|
||||
{ "replace", required_argument, NULL, ARG_REPLACE },
|
||||
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
||||
{}
|
||||
};
|
||||
|
||||
@ -2612,6 +2617,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_replace = optarg;
|
||||
break;
|
||||
|
||||
case ARG_NO_PAGER:
|
||||
arg_no_pager = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
return -EINVAL;
|
||||
|
||||
@ -2801,6 +2810,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (arg_cat_config) {
|
||||
(void) pager_open(arg_no_pager, false);
|
||||
|
||||
r = cat_config(config_dirs, argv + optind);
|
||||
goto finish;
|
||||
}
|
||||
@ -2847,6 +2858,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
finish:
|
||||
pager_close();
|
||||
|
||||
ordered_hashmap_free_with_destructor(items, item_array_free);
|
||||
ordered_hashmap_free_with_destructor(globs, item_array_free);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user