return table_add_cell(table, NULL, TABLE_STRV, triggered);
}
+static char *format_unit_id(const char *unit, const char *machine) {
+ assert(unit);
+
+ return machine ? strjoin(machine, ":", unit) : strdup(unit);
+}
+
static int output_units_list(const UnitInfo *unit_infos, size_t c) {
_cleanup_(table_unrefp) Table *table = NULL;
size_t job_count = 0;
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (const UnitInfo *u = unit_infos; unit_infos && (size_t) (u - unit_infos) < c; u++) {
- _cleanup_free_ char *j = NULL;
- const char *on_underline = "", *on_loaded = "", *on_active = "";
- const char *on_circle = "", *id;
+ _cleanup_free_ char *id = NULL;
+ const char *on_underline = "", *on_loaded = "", *on_active = "", *on_circle = "";
bool circle = false, underline = false;
if (u + 1 < unit_infos + c &&
on_loaded = on_underline;
}
- if (u->machine) {
- j = strjoin(u->machine, ":", u->id);
- if (!j)
- return log_oom();
-
- id = j;
- } else
- id = u->id;
+ id = format_unit_id(u->id, u->machine);
+ if (!id)
+ return log_oom();
r = table_add_many(table,
TABLE_STRING, circle ? special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE) : " ",
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct timer_info *t = timer_infos; t < timer_infos + n; t++) {
- _cleanup_free_ char *j = NULL;
- const char *unit;
+ _cleanup_free_ char *unit = NULL;
- if (t->machine) {
- j = strjoin(t->machine, ":", t->id);
- if (!j)
- return log_oom();
- unit = j;
- } else
- unit = t->id;
+ unit = format_unit_id(t->id, t->machine);
+ if (!unit)
+ return log_oom();
r = table_add_many(table,
TABLE_TIMESTAMP, t->next_elapse,
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct automount_info *info = infos; info < infos + n_infos; info++) {
- _cleanup_free_ char *j = NULL;
- const char *unit;
+ _cleanup_free_ char *unit = NULL;
- if (info->machine) {
- j = strjoin(info->machine, ":", info->id);
- if (!j)
- return log_oom();
- unit = j;
- } else
- unit = info->id;
+ unit = format_unit_id(info->id, info->machine);
+ if (!unit)
+ return log_oom();
r = table_add_many(table,
TABLE_STRING, info->what,