diff options
-rw-r--r-- | coccinelle/isempty.cocci | 10 | ||||
-rw-r--r-- | src/analyze/analyze-fdstore.c | 2 | ||||
-rw-r--r-- | src/analyze/analyze-plot.c | 8 | ||||
-rw-r--r-- | src/creds/creds.c | 2 | ||||
-rw-r--r-- | src/cryptenroll/cryptenroll-list.c | 2 | ||||
-rw-r--r-- | src/home/homectl.c | 10 | ||||
-rw-r--r-- | src/login/inhibit.c | 8 | ||||
-rw-r--r-- | src/login/loginctl.c | 8 | ||||
-rw-r--r-- | src/machine/machinectl.c | 8 | ||||
-rw-r--r-- | src/pcrlock/pcrlock.c | 8 | ||||
-rw-r--r-- | src/portable/portablectl.c | 8 | ||||
-rw-r--r-- | src/shared/format-table.h | 6 | ||||
-rw-r--r-- | src/shared/pkcs11-util.c | 2 | ||||
-rw-r--r-- | src/shared/tpm2-util.c | 2 | ||||
-rw-r--r-- | src/userdb/userdbctl.c | 20 |
15 files changed, 60 insertions, 44 deletions
diff --git a/coccinelle/isempty.cocci b/coccinelle/isempty.cocci index cd912ff18f..2089970886 100644 --- a/coccinelle/isempty.cocci +++ b/coccinelle/isempty.cocci @@ -132,3 +132,13 @@ expression s; - prioq_size(s) != 0 + !prioq_isempty(s) ) +@@ +expression s; +@@ +( +- table_get_rows(s) <= 1 ++ table_isempty(s) +| +- table_get_rows(s) > 1 ++ !table_isempty(s) +) diff --git a/src/analyze/analyze-fdstore.c b/src/analyze/analyze-fdstore.c index e1f88c3552..8ada6d4e73 100644 --- a/src/analyze/analyze-fdstore.c +++ b/src/analyze/analyze-fdstore.c @@ -81,7 +81,7 @@ static int dump_fdstore(sd_bus *bus, const char *arg) { if (r < 0) return r; - if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && table_get_rows(table) <= 1) + if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && table_isempty(table)) log_info("No file descriptors in fdstore of '%s'.", unit); else { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */true); diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c index 81fc25b31e..ccd552a781 100644 --- a/src/analyze/analyze-plot.c +++ b/src/analyze/analyze-plot.c @@ -402,7 +402,7 @@ static int show_table(Table *table, const char *word) { assert(table); assert(word); - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { table_set_header(table, arg_legend); if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) @@ -414,10 +414,10 @@ static int show_table(Table *table, const char *word) { } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); - else + if (table_isempty(table)) printf("No %s.\n", word); + else + printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); } return 0; diff --git a/src/creds/creds.c b/src/creds/creds.c index b53e8d3b36..ed39ffe51e 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -232,7 +232,7 @@ static int verb_list(int argc, char **argv, void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(ENXIO), "No credentials passed. (i.e. $CREDENTIALS_DIRECTORY not set.)"); } - if ((arg_json_format_flags & JSON_FORMAT_OFF) && table_get_rows(t) <= 1) { + if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF) && table_isempty(t)) { log_info("No credentials"); return 0; } diff --git a/src/cryptenroll/cryptenroll-list.c b/src/cryptenroll/cryptenroll-list.c index d21df7123b..00a1a8e637 100644 --- a/src/cryptenroll/cryptenroll-list.c +++ b/src/cryptenroll/cryptenroll-list.c @@ -114,7 +114,7 @@ int list_enrolled(struct crypt_device *cd) { return table_log_add_error(r); } - if (table_get_rows(t) <= 1) { + if (table_isempty(t)) { log_info("No slots found."); return 0; } diff --git a/src/home/homectl.c b/src/home/homectl.c index f2fe90c75b..5a2eb8f31b 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -189,7 +189,7 @@ static int list_homes(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_parse_error(r); - if (table_get_rows(table) > 1 || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { r = table_set_sort(table, (size_t) 0); if (r < 0) return table_log_sort_error(r); @@ -199,11 +199,11 @@ static int list_homes(int argc, char *argv[], void *userdata) { return r; } - if (arg_legend && (arg_json_format_flags & JSON_FORMAT_OFF)) { - if (table_get_rows(table) > 1) - printf("\n%zu home areas listed.\n", table_get_rows(table) - 1); - else + if (arg_legend && !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (table_isempty(table)) printf("No home areas.\n"); + else + printf("\n%zu home areas listed.\n", table_get_rows(table) - 1); } return 0; diff --git a/src/login/inhibit.c b/src/login/inhibit.c index ad73c4bde3..8c65e1582a 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -111,7 +111,7 @@ static int print_inhibitors(sd_bus *bus) { if (r < 0) return bus_log_parse_error(r); - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_set_sort(table, (size_t) 1, (size_t) 0, (size_t) 5, (size_t) 6); if (r < 0) return table_log_sort_error(r); @@ -124,10 +124,10 @@ static int print_inhibitors(sd_bus *bus) { } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu inhibitors listed.\n", table_get_rows(table) - 1); - else + if (table_isempty(table)) printf("No inhibitors.\n"); + else + printf("\n%zu inhibitors listed.\n", table_get_rows(table) - 1); } return 0; diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 7fc6efc9da..9b76a63990 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -119,7 +119,7 @@ static int show_table(Table *table, const char *word) { assert(table); assert(word); - if (table_get_rows(table) > 1 || OUTPUT_MODE_IS_JSON(arg_output)) { + if (!table_isempty(table) || OUTPUT_MODE_IS_JSON(arg_output)) { r = table_set_sort(table, (size_t) 0); if (r < 0) return table_log_sort_error(r); @@ -135,10 +135,10 @@ static int show_table(Table *table, const char *word) { } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); - else + if (table_isempty(table)) printf("No %s.\n", word); + else + printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); } return 0; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 3eadb5f4e7..aa81cf071f 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -235,7 +235,7 @@ static int show_table(Table *table, const char *word) { assert(table); assert(word); - if (table_get_rows(table) > 1 || OUTPUT_MODE_IS_JSON(arg_output)) { + if (!table_isempty(table) || OUTPUT_MODE_IS_JSON(arg_output)) { r = table_set_sort(table, (size_t) 0); if (r < 0) return table_log_sort_error(r); @@ -251,10 +251,10 @@ static int show_table(Table *table, const char *word) { } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); - else + if (table_isempty(table)) printf("No %s.\n", word); + else + printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word); } return 0; diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index 23bdab0bef..d1bab5f59f 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -2570,17 +2570,17 @@ static int verb_list_components(int argc, char *argv[], void *userdata) { } } - if (table_get_rows(table) > 1 || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { + if (!table_isempty(table) || !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ true); if (r < 0) return log_error_errno(r, "Failed to output table: %m"); } if (FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)) { - if (table_get_rows(table) > 1) - printf("\n%zu components listed.\n", table_get_rows(table) - 1); - else + if (table_isempty(table)) printf("No components defined.\n"); + else + printf("\n%zu components listed.\n", table_get_rows(table) - 1); } return 0; diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index 532e8d9345..cf3122e29c 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -1030,7 +1030,7 @@ static int list_images(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_parse_error(r); - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_set_sort(table, (size_t) 0); if (r < 0) return table_log_sort_error(r); @@ -1043,10 +1043,10 @@ static int list_images(int argc, char *argv[], void *userdata) { } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu images listed.\n", table_get_rows(table) - 1); - else + if (table_isempty(table)) printf("No images.\n"); + else + printf("\n%zu images listed.\n", table_get_rows(table) - 1); } return 0; diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 0368447638..36e1f94ca0 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -144,6 +144,12 @@ static inline TableCell* TABLE_HEADER_CELL(size_t i) { } size_t table_get_rows(Table *t); +static inline bool table_isempty(Table *t) { + if (!t) + return true; + + return table_get_rows(t) <= 1; +} size_t table_get_columns(Table *t); size_t table_get_current_column(Table *t); diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index c3d97b80f9..edf4fb01b9 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -1530,7 +1530,7 @@ int pkcs11_list_tokens(void) { if (r < 0 && r != -EAGAIN) return r; - if (table_get_rows(t) <= 1) { + if (table_isempty(t)) { log_info("No suitable PKCS#11 tokens found."); return 0; } diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 5e07b88a89..f2bdae2bec 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -5965,7 +5965,7 @@ int tpm2_list_devices(void) { } } - if (table_get_rows(t) <= 1) { + if (table_isempty(t)) { log_info("No suitable TPM2 devices found."); return 0; } diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index a7db3fb0d5..9ab5d42c4b 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -440,7 +440,7 @@ static int display_user(int argc, char *argv[], void *userdata) { if (uid_map_lines < 0) return uid_map_lines; - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); @@ -743,7 +743,7 @@ static int display_group(int argc, char *argv[], void *userdata) { if (gid_map_lines < 0) return gid_map_lines; - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); @@ -891,17 +891,17 @@ static int display_memberships(int argc, char *argv[], void *userdata) { } if (table) { - if (table_get_rows(table) > 1) { + if (!table_isempty(table)) { r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); } if (arg_legend) { - if (table_get_rows(table) > 1) - printf("\n%zu memberships listed.\n", table_get_rows(table) - 1); - else + if (table_isempty(table)) printf("No memberships.\n"); + else + printf("\n%zu memberships listed.\n", table_get_rows(table) - 1); } } @@ -956,17 +956,17 @@ static int display_services(int argc, char *argv[], void *userdata) { return table_log_add_error(r); } - if (table_get_rows(t) > 1) { + if (!table_isempty(t)) { r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend); if (r < 0) return table_log_print_error(r); } if (arg_legend && arg_output != OUTPUT_JSON) { - if (table_get_rows(t) > 1) - printf("\n%zu services listed.\n", table_get_rows(t) - 1); - else + if (table_isempty(t)) printf("No services.\n"); + else + printf("\n%zu services listed.\n", table_get_rows(t) - 1); } return 0; |