systemctl: use sizeof() instead of strlen() on literal strings
This commit is contained in:
parent
9b2fcafba4
commit
b036fc0050
|
@ -253,6 +253,7 @@ static int compare_unit_info(const void *a, const void *b) {
|
|||
|
||||
static bool output_show_job(const struct unit_info *u) {
|
||||
const char *dot;
|
||||
|
||||
return (!arg_type || ((dot = strrchr(u->id, '.')) &&
|
||||
streq(dot+1, arg_type))) &&
|
||||
(arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0);
|
||||
|
@ -260,18 +261,21 @@ static bool output_show_job(const struct unit_info *u) {
|
|||
|
||||
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
|
||||
unsigned active_len, sub_len, job_len;
|
||||
const struct unit_info *u;
|
||||
|
||||
active_len = sizeof("ACTIVE")-1;
|
||||
sub_len = sizeof("SUB")-1;
|
||||
job_len = sizeof("JOB")-1;
|
||||
|
||||
for (u = unit_infos; u < unit_infos + c; u++) {
|
||||
if (!output_show_job(u))
|
||||
continue;
|
||||
|
||||
active_len = strlen("ACTIVE");
|
||||
sub_len = strlen("SUB");
|
||||
job_len = strlen("JOB");
|
||||
for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
|
||||
if (output_show_job(u)) {
|
||||
active_len = MAX(active_len, strlen(u->active_state));
|
||||
sub_len = MAX(sub_len, strlen(u->sub_state));
|
||||
if (u->job_id != 0)
|
||||
job_len = MAX(job_len, strlen(u->job_type));
|
||||
}
|
||||
}
|
||||
|
||||
if (on_tty()) {
|
||||
printf("%-25s %-6s %-*s %-*s %-*s", "UNIT", "LOAD",
|
||||
|
@ -282,13 +286,15 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
|
||||
if (output_show_job(u)) {
|
||||
for (u = unit_infos; u < unit_infos + c; u++) {
|
||||
char *e;
|
||||
int a = 0, b = 0;
|
||||
const char *on_loaded, *off_loaded;
|
||||
const char *on_active, *off_active;
|
||||
|
||||
if (!output_show_job(u))
|
||||
continue;
|
||||
|
||||
if (!streq(u->load_state, "loaded")) {
|
||||
on_loaded = ansi_highlight(true);
|
||||
off_loaded = ansi_highlight(false);
|
||||
|
@ -332,7 +338,6 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
|
|||
|
||||
fputs("\n", stdout);
|
||||
}
|
||||
}
|
||||
|
||||
if (on_tty()) {
|
||||
printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
|
||||
|
|
Loading…
Reference in New Issue