Skip to content

Commit 18a9fab

Browse files
authored
Merge pull request #22 from acornard/differentiate-status-return-code
Differentiate gridinit_cmd status return code
2 parents b1f504e + 80dc664 commit 18a9fab

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

main/gridinit_cmd.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,19 @@ 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, struct keyword_set_s *kw)
130130
{
131-
struct keyword_set_s *kw;
132-
133-
kw = flag_color ? &KEYWORDS_COLOR : &KEYWORDS_NORMAL;
134131

135132
if (ci->broken) {
136-
*faulty = TRUE;
137133
return kw->broken;
138134
}
139135
if (!ci->enabled) {
140-
*faulty = FALSE;
141136
return kw->disabled;
142137
}
143138
if (ci->pid <= 0) {
144-
*faulty = TRUE;
145139
return kw->down;
146140
}
147141

148-
*faulty = FALSE;
149142
return kw->up;
150143
}
151144

@@ -421,27 +414,30 @@ command_status(int lvl, int argc, char **args)
421414
break;
422415
}
423416

424-
int count_faulty = 0, count_all = 0, count_misses = 0;
417+
int count_misses = 0, count_broken = 0, count_down = 0;
418+
struct keyword_set_s *kw;
419+
kw = flag_color ? &KEYWORDS_COLOR : & KEYWORDS_NORMAL;
425420

426421
/* iterate on the lines */
427422
for (GList *l=jobs; l ;l=l->next) {
428423
char str_time[20] = "---------- --------";
429424
const char * str_status = "-";
430425
struct child_info_s *ci = NULL;
431-
gboolean faulty = FALSE;
432426

433427
ci = l->data;
434428

435429
/* Prepare some fields */
436430
if (ci->pid > 0)
437431
strftime(str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S",
438432
gmtime(&(ci->last_start_attempt)));
439-
str_status = get_child_status(ci, &faulty);
433+
str_status = get_child_status(ci, kw);
440434

441435
/* Manage counters */
442-
if (faulty)
443-
count_faulty ++;
444-
count_all ++;
436+
437+
if (str_status == kw->down)
438+
count_down ++;
439+
if (str_status == kw->broken)
440+
count_broken ++;
445441

446442
/* Print now! */
447443
switch (lvl) {
@@ -475,7 +471,16 @@ command_status(int lvl, int argc, char **args)
475471
g_list_free_full(all_jobs, (GDestroyNotify)child_info_free);
476472
g_list_free(jobs);
477473

478-
return !(!count_misses && !count_faulty && (!argc || count_all > 0));
474+
int rc = 0;
475+
476+
if (count_down)
477+
rc |= 1;
478+
if (count_misses)
479+
rc |= 2;
480+
if (count_broken)
481+
rc |= 4;
482+
483+
return rc;
479484
}
480485

481486
static int

0 commit comments

Comments
 (0)