Order the results by port

This commit is contained in:
Přemysl Eric Janouch 2014-09-24 18:59:55 +02:00
parent 734931d84f
commit 50e27cf3d8
1 changed files with 5 additions and 3 deletions

View File

@ -1405,12 +1405,14 @@ target_dump_terminal (struct target *self, struct target_dump_data *data)
} }
static int static int
unit_cmp_by_group (const void *ax, const void *bx) unit_cmp_by_order (const void *ax, const void *bx)
{ {
const struct unit **ay = (void *) ax, **by = (void *) bx; const struct unit **ay = (void *) ax, **by = (void *) bx;
const struct unit *a = *ay, *b = *by; const struct unit *a = *ay, *b = *by;
int x = strcmp (a->service->name, b->service->name); int x = strcmp (a->service->name, b->service->name);
return x ? x : strcmp (a->transport->name, b->transport->name); if (!x) x = strcmp (a->transport->name, b->transport->name);
if (!x) x = (int) a->port - (int) b->port;
return x;
} }
static void static void
@ -1431,7 +1433,7 @@ target_dump_results (struct target *self)
sorted[--len] = iter; sorted[--len] = iter;
// Sort them by service name so that they can be grouped // Sort them by service name so that they can be grouped
qsort (sorted, N_ELEMENTS (sorted), sizeof *sorted, unit_cmp_by_group); qsort (sorted, N_ELEMENTS (sorted), sizeof *sorted, unit_cmp_by_order);
if (ctx->json_results) if (ctx->json_results)
target_dump_json (self, &data); target_dump_json (self, &data);