mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
core: always set output arg in unit_status_string()
As requested in https://github.com/systemd/systemd/pull/20058#pullrequestreview-696942153.
This commit is contained in:
parent
a7b73cc867
commit
e6a16a821c
@ -1340,27 +1340,35 @@ const char* unit_description(Unit *u) {
|
||||
return strna(u->id);
|
||||
}
|
||||
|
||||
const char* unit_status_string(Unit *u, char **combined) {
|
||||
const char* unit_status_string(Unit *u, char **ret_combined_buffer) {
|
||||
assert(u);
|
||||
assert(u->id);
|
||||
|
||||
/* Return u->id, u->description, or "{u->id} - {u->description}".
|
||||
* Versions with u->description are only used if it is set.
|
||||
* The last option is used if configured and the caller provided 'combined' pointer. */
|
||||
* The last option is used if configured and the caller provided the 'ret_combined_buffer'
|
||||
* pointer.
|
||||
*
|
||||
* Note that *ret_combined_buffer may be set to NULL. */
|
||||
|
||||
if (!u->description ||
|
||||
streq(u->description, u->id) ||
|
||||
u->manager->status_unit_format == STATUS_UNIT_FORMAT_NAME ||
|
||||
(u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && !combined))
|
||||
return u->id;
|
||||
(u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && !ret_combined_buffer) ||
|
||||
streq(u->description, u->id)) {
|
||||
|
||||
if (u->description && u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && combined) {
|
||||
char *t = strjoin(u->id, " - ", u->description);
|
||||
if (t) {
|
||||
*combined = t;
|
||||
return t;
|
||||
if (ret_combined_buffer)
|
||||
*ret_combined_buffer = NULL;
|
||||
return u->id;
|
||||
}
|
||||
|
||||
if (ret_combined_buffer) {
|
||||
if (u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED) {
|
||||
*ret_combined_buffer = strjoin(u->id, " - ", u->description);
|
||||
if (*ret_combined_buffer)
|
||||
return *ret_combined_buffer;
|
||||
log_oom(); /* Fall back to ->description */
|
||||
} else
|
||||
log_oom();
|
||||
*ret_combined_buffer = NULL;
|
||||
}
|
||||
|
||||
return u->description;
|
||||
|
Loading…
Reference in New Issue
Block a user