Skip to content

Commit 87f83c5

Browse files
committed
Differentiate gridinit_cmd status return code
1 parent 6802dac commit 87f83c5

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

main/gridinit_cmd.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,22 @@ compare_child_info(gconstpointer p1, gconstpointer p2)
126126
}
127127

128128
static const char *
129-
get_child_status(struct child_info_s *ci, gboolean *faulty)
129+
get_child_status(struct child_info_s *ci)
130130
{
131131
struct keyword_set_s *kw;
132132

133133
kw = flag_color ? &KEYWORDS_COLOR : &KEYWORDS_NORMAL;
134134

135135
if (ci->broken) {
136-
*faulty = TRUE;
137136
return kw->broken;
138137
}
139138
if (!ci->enabled) {
140-
*faulty = FALSE;
141139
return kw->disabled;
142140
}
143141
if (ci->pid <= 0) {
144-
*faulty = TRUE;
145142
return kw->down;
146143
}
147144

148-
*faulty = FALSE;
149145
return kw->up;
150146
}
151147

@@ -421,27 +417,30 @@ command_status(int lvl, int argc, char **args)
421417
break;
422418
}
423419

424-
int count_faulty = 0, count_all = 0, count_misses = 0;
420+
count_misses = 0, count_broken = 0, count_down = 0;
421+
struct keyword_set_s *kw;
422+
kw = flag_color ? &KEYWORDS_COLOR : & KEYWORDS_NORMAL;
425423

426424
/* iterate on the lines */
427425
for (GList *l=jobs; l ;l=l->next) {
428426
char str_time[20] = "---------- --------";
429427
const char * str_status = "-";
430428
struct child_info_s *ci = NULL;
431-
gboolean faulty = FALSE;
432429

433430
ci = l->data;
434431

435432
/* Prepare some fields */
436433
if (ci->pid > 0)
437434
strftime(str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S",
438435
gmtime(&(ci->last_start_attempt)));
439-
str_status = get_child_status(ci, &faulty);
436+
str_status = get_child_status(ci);
440437

441438
/* Manage counters */
442-
if (faulty)
443-
count_faulty ++;
444-
count_all ++;
439+
440+
if (str_status == kw->down)
441+
count_down ++;
442+
if (str_status == kw->broken)
443+
count_broken ++;
445444

446445
/* Print now! */
447446
switch (lvl) {
@@ -475,7 +474,16 @@ command_status(int lvl, int argc, char **args)
475474
g_list_free_full(all_jobs, (GDestroyNotify)child_info_free);
476475
g_list_free(jobs);
477476

478-
return !(!count_misses && !count_faulty && (!argc || count_all > 0));
477+
int rc = 0;
478+
479+
if (count_down)
480+
rc |= 1;
481+
if (count_misses)
482+
rc |= 2;
483+
if (count_broken)
484+
rc |= 4;
485+
486+
return rc;
479487
}
480488

481489
static int

0 commit comments

Comments
 (0)