summaryrefslogtreecommitdiff
path: root/src/analyze/analyze-security.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-01-10 18:23:21 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-01-10 18:28:09 +0900
commit9c46b437fcb13a1bfff0d992f106231b3ce59120 (patch)
treecfecb84fd0771aad0b05eba01c3ad5a442d769ce /src/analyze/analyze-security.c
parentd8aedafb57df925ebd97bf45b1bf3feba6161d9c (diff)
downloadsystemd-9c46b437fcb13a1bfff0d992f106231b3ce59120.tar.gz
analyze: optimize table creation by using table_add_many()
Diffstat (limited to 'src/analyze/analyze-security.c')
-rw-r--r--src/analyze/analyze-security.c43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c
index 20c1401390..7fa17c99f5 100644
--- a/src/analyze/analyze-security.c
+++ b/src/analyze/analyze-security.c
@@ -1484,7 +1484,6 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (details_table) {
const char *checkmark, *description, *color = NULL;
- TableCell *cell;
if (badness == UINT64_MAX) {
checkmark = " ";
@@ -1507,13 +1506,12 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (d)
description = d;
- r = table_add_cell_full(details_table, &cell, TABLE_STRING, checkmark, 1, 1, 0, 0, 0);
- if (r < 0)
- return log_error_errno(r, "Failed to add cell to table: %m");
- if (color)
- (void) table_set_color(details_table, cell, color);
-
r = table_add_many(details_table,
+ TABLE_STRING, checkmark,
+ TABLE_SET_MINIMUM_WIDTH, 1,
+ TABLE_SET_MAXIMUM_WIDTH, 1,
+ TABLE_SET_ELLIPSIZE_PERCENT, 0,
+ TABLE_SET_COLOR, color,
TABLE_STRING, a->id, TABLE_SET_URL, a->url,
TABLE_STRING, description,
TABLE_UINT64, a->weight, TABLE_SET_ALIGN_PERCENT, 100,
@@ -1521,7 +1519,7 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
TABLE_UINT64, a->range, TABLE_SET_ALIGN_PERCENT, 100,
TABLE_EMPTY, TABLE_SET_ALIGN_PERCENT, 100);
if (r < 0)
- return log_error_errno(r, "Failed to add cells to table: %m");
+ return table_log_add_error(r);
}
}
@@ -1597,35 +1595,26 @@ static int assess(const struct security_info *info, Table *overview_table, Analy
if (overview_table) {
char buf[DECIMAL_STR_MAX(uint64_t) + 1 + DECIMAL_STR_MAX(uint64_t) + 1];
- TableCell *cell;
+ _cleanup_free_ char *url = NULL;
- r = table_add_cell(overview_table, &cell, TABLE_STRING, info->id);
- if (r < 0)
- return log_error_errno(r, "Failed to add cell to table: %m");
if (info->fragment_path) {
- _cleanup_free_ char *url = NULL;
-
r = file_url_from_path(info->fragment_path, &url);
if (r < 0)
return log_error_errno(r, "Failed to generate URL from path: %m");
-
- (void) table_set_url(overview_table, cell, url);
}
xsprintf(buf, "%" PRIu64 ".%" PRIu64, exposure / 10, exposure % 10);
- r = table_add_cell(overview_table, &cell, TABLE_STRING, buf);
- if (r < 0)
- return log_error_errno(r, "Failed to add cell to table: %m");
- (void) table_set_align_percent(overview_table, cell, 100);
-
- r = table_add_cell(overview_table, &cell, TABLE_STRING, badness_table[i].name);
- if (r < 0)
- return log_error_errno(r, "Failed to add cell to table: %m");
- (void) table_set_color(overview_table, cell, strempty(badness_table[i].color));
- r = table_add_cell(overview_table, NULL, TABLE_STRING, special_glyph(badness_table[i].smiley));
+ r = table_add_many(overview_table,
+ TABLE_STRING, info->id,
+ TABLE_SET_URL, url,
+ TABLE_STRING, buf,
+ TABLE_SET_ALIGN_PERCENT, 100,
+ TABLE_STRING, badness_table[i].name,
+ TABLE_SET_COLOR, strempty(badness_table[i].color),
+ TABLE_STRING, special_glyph(badness_table[i].smiley));
if (r < 0)
- return log_error_errno(r, "Failed to add cell to table: %m");
+ return table_log_add_error(r);
}
return 0;