Also put positive condition first.
(void) table_hide_column_from_display(table, (size_t) 0);
- if (strv_isempty(strv_skip(argv, 1)))
- for (Architecture a = 0; a < _ARCHITECTURE_MAX; a++) {
- r = add_arch(table, a);
- if (r < 0)
- return r;
- }
- else {
- STRV_FOREACH(as, strv_skip(argv, 1)) {
+ char **args = strv_skip(argv, 1);
+ if (args) {
+ STRV_FOREACH(arg, args) {
Architecture a;
- if (streq(*as, "native"))
+ if (streq(*arg, "native"))
a = native_architecture();
- else if (streq(*as, "uname"))
+ else if (streq(*arg, "uname"))
a = uname_architecture();
- else if (streq(*as, "secondary")) {
+ else if (streq(*arg, "secondary")) {
#ifdef ARCHITECTURE_SECONDARY
a = ARCHITECTURE_SECONDARY;
#else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No secondary architecture.");
#endif
} else
- a = architecture_from_string(*as);
+ a = architecture_from_string(*arg);
if (a < 0)
- return log_error_errno(a, "Architecture \"%s\" not known.", *as);
+ return log_error_errno(a, "Architecture \"%s\" not known.", *arg);
r = add_arch(table, a);
if (r < 0)
}
(void) table_set_sort(table, (size_t) 0);
- }
+ } else
+ for (Architecture a = 0; a < _ARCHITECTURE_MAX; a++) {
+ r = add_arch(table, a);
+ if (r < 0)
+ return r;
+ }
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
if (r < 0)
#include "strv.h"
int verb_cat_config(int argc, char *argv[], void *userdata) {
- char **list;
int r;
pager_open(arg_pager_flags);
- list = strv_skip(argv, 1);
+ char **list = strv_skip(argv, 1);
STRV_FOREACH(arg, list) {
const char *t = NULL;
if (r < 0)
return log_error_errno(r, "Failed to right-align status: %m");
- if (strv_isempty(strv_skip(argv, 1)))
- for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) {
- if (!exit_status_mappings[i].name)
- continue;
-
- r = table_add_many(table,
- TABLE_STRING, exit_status_mappings[i].name,
- TABLE_INT, (int) i,
- TABLE_STRING, exit_status_class(i));
- if (r < 0)
- return table_log_add_error(r);
- }
- else
- for (int i = 1; i < argc; i++) {
+ char **args = strv_skip(argv, 1);
+ if (args)
+ STRV_FOREACH(arg, args) {
int status;
- status = exit_status_from_string(argv[i]);
+ status = exit_status_from_string(*arg);
if (status < 0)
- return log_error_errno(status, "Invalid exit status \"%s\".", argv[i]);
+ return log_error_errno(status, "Invalid exit status \"%s\".", *arg);
assert(status >= 0 && (size_t) status < ELEMENTSOF(exit_status_mappings));
r = table_add_many(table,
if (r < 0)
return table_log_add_error(r);
}
+ else
+ for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++) {
+ if (!exit_status_mappings[i].name)
+ continue;
+
+ r = table_add_many(table,
+ TABLE_STRING, exit_status_mappings[i].name,
+ TABLE_INT, (int) i,
+ TABLE_STRING, exit_status_class(i));
+ if (r < 0)
+ return table_log_add_error(r);
+ }
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
if (r < 0)
}
int verb_filesystems(int argc, char *argv[], void *userdata) {
- bool first = true;
-
#if ! HAVE_LIBBPF
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not compiled with libbpf support, sorry.");
#endif
pager_open(arg_pager_flags);
- if (strv_isempty(strv_skip(argv, 1))) {
+ char **args = strv_skip(argv, 1);
+ if (args)
+ STRV_FOREACH(name, args) {
+ if (name != args)
+ puts("");
+
+ const FilesystemSet *set = filesystem_set_find(*name);
+ if (!set) {
+ /* make sure the error appears below normal output */
+ fflush(stdout);
+
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "Filesystem set \"%s\" not found.", *name);
+ }
+
+ dump_filesystem_set(set);
+ }
+ else {
_cleanup_set_free_ Set *kernel = NULL, *known = NULL;
int k;
for (FilesystemGroups i = 0; i < _FILESYSTEM_SET_MAX; i++) {
const FilesystemSet *set = filesystem_sets + i;
- if (!first)
+ if (i > 0)
puts("");
dump_filesystem_set(set);
filesystem_set_remove(kernel, set);
if (i != FILESYSTEM_SET_KNOWN)
filesystem_set_remove(known, set);
- first = false;
}
if (arg_quiet) /* Let's not show the extra stuff in quiet mode */
return 0;
if (!set_isempty(known)) {
- _cleanup_free_ char **l = NULL;
-
printf("\n"
"# %sUngrouped filesystems%s (known but not included in any of the groups except @known):\n",
ansi_highlight(), ansi_normal());
- l = set_get_strv(known);
+ _cleanup_free_ char **l = set_get_strv(known);
if (!l)
return log_oom();
STRV_FOREACH(filesystem, l)
printf("# %s\n", *filesystem);
}
- } else
- STRV_FOREACH(name, strv_skip(argv, 1)) {
- const FilesystemSet *set;
-
- if (!first)
- puts("");
-
- set = filesystem_set_find(*name);
- if (!set) {
- /* make sure the error appears below normal output */
- fflush(stdout);
-
- return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
- "Filesystem set \"%s\" not found.", *name);
- }
-
- dump_filesystem_set(set);
- first = false;
- }
+ }
return EXIT_SUCCESS;
}
char **services = STRV_MAKE("org.freedesktop.systemd1");
int r;
- if (!strv_isempty(strv_skip(argv, 1))) {
- services = strv_skip(argv, 1);
- STRV_FOREACH(service, services)
+ char **args = strv_skip(argv, 1);
+ if (args) {
+ STRV_FOREACH(service, args)
if (!service_name_is_valid(*service))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "D-Bus service name '%s' is not valid.", *service);
+ services = args;
}
r = acquire_bus(&bus, NULL);
if (!alg) /* hide hash column if we couldn't acquire it */
(void) table_set_display(table, 0, 1);
- if (strv_isempty(strv_skip(argv, 1)))
- for (uint32_t pi = 0; pi < _TPM2_PCR_INDEX_MAX_DEFINED; pi++) {
- r = add_pcr_to_table(table, alg, pi);
- if (r < 0)
- return r;
- }
- else {
- for (int i = 1; i < argc; i++) {
+ char **args = strv_skip(argv, 1);
+ if (args) {
+ STRV_FOREACH(arg, args) {
int pi;
- pi = tpm2_pcr_index_from_string(argv[i]);
+ pi = tpm2_pcr_index_from_string(*arg);
if (pi < 0)
- return log_error_errno(pi, "PCR index \"%s\" not known.", argv[i]);
+ return log_error_errno(pi, "PCR index \"%s\" not known.", *arg);
r = add_pcr_to_table(table, alg, pi);
if (r < 0)
}
(void) table_set_sort(table, (size_t) 0);
- }
+ } else
+ for (uint32_t pi = 0; pi < _TPM2_PCR_INDEX_MAX_DEFINED; pi++) {
+ r = add_pcr_to_table(table, alg, pi);
+ if (r < 0)
+ return r;
+ }
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */true);
if (r < 0)
}
int verb_syscall_filters(int argc, char *argv[], void *userdata) {
- bool first = true;
int r;
pager_open(arg_pager_flags);
- if (strv_isempty(strv_skip(argv, 1))) {
+ char **args = strv_skip(argv, 1);
+ if (args)
+ STRV_FOREACH(name, args) {
+ const SyscallFilterSet *set;
+
+ if (name != args)
+ puts("");
+
+ set = syscall_filter_set_find(*name);
+ if (!set) {
+ /* make sure the error appears below normal output */
+ fflush(stdout);
+
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "Filter set \"%s\" not found.", *name);
+ }
+
+ dump_syscall_filter(set);
+ }
+ else {
_cleanup_set_free_ Set *kernel = NULL, *known = NULL;
int k = 0; /* explicit initialization to appease gcc */
for (int i = 0; i < _SYSCALL_FILTER_SET_MAX; i++) {
const SyscallFilterSet *set = syscall_filter_sets + i;
- if (!first)
+ if (i > 0)
puts("");
dump_syscall_filter(set);
syscall_set_remove(kernel, set);
if (i != SYSCALL_FILTER_SET_KNOWN)
syscall_set_remove(known, set);
- first = false;
}
if (arg_quiet) /* Let's not show the extra stuff in quiet mode */
return 0;
if (!set_isempty(known)) {
- _cleanup_free_ char **l = NULL;
-
printf("\n"
"# %sUngrouped System Calls%s (known but not included in any of the groups except @known):\n",
ansi_highlight(), ansi_normal());
- l = set_get_strv(known);
+ _cleanup_free_ char **l = set_get_strv(known);
if (!l)
return log_oom();
if (!arg_quiet)
log_notice_errno(k, "# Not showing unlisted system calls, couldn't retrieve kernel system call list: %m");
} else if (!set_isempty(kernel)) {
- _cleanup_free_ char **l = NULL;
-
printf("\n"
"# %sUnlisted System Calls%s (supported by the local kernel, but not included in any of the groups listed above):\n",
ansi_highlight(), ansi_normal());
- l = set_get_strv(kernel);
+ _cleanup_free_ char **l = set_get_strv(kernel);
if (!l)
return log_oom();
STRV_FOREACH(syscall, l)
printf("# %s\n", *syscall);
}
- } else
- STRV_FOREACH(name, strv_skip(argv, 1)) {
- const SyscallFilterSet *set;
-
- if (!first)
- puts("");
-
- set = syscall_filter_set_find(*name);
- if (!set) {
- /* make sure the error appears below normal output */
- fflush(stdout);
-
- return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
- "Filter set \"%s\" not found.", *name);
- }
-
- dump_syscall_filter(set);
- first = false;
- }
+ }
return EXIT_SUCCESS;
}
int verb_timestamp(int argc, char *argv[], void *userdata) {
int r = 0;
- STRV_FOREACH(p, strv_skip(argv, 1)) {
- RET_GATHER(r, test_timestamp_one(*p));
+ char **args = strv_skip(argv, 1);
+ STRV_FOREACH(arg, args) {
+ if (arg != args)
+ puts("");
- if (p[1])
- putchar('\n');
+ RET_GATHER(r, test_timestamp_one(*arg));
}
return r;