Skip to content

Commit 86a6b3a

Browse files
REORG/MINOR: mworker/cli: extract shared worker row printer for "show proc"
Introduce cli_append_worker_row() to centralize formatting of a single worker row. Replace duplicated row-printing code in both current and old workers loops with the helper. Motivation: Reduces LOC and improves readability by removing duplication.
1 parent d985fcf commit 86a6b3a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/mworker.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,18 @@ struct cli_showproc_ctx {
810810
int next_uptime; /* uptime must be greater than this value */
811811
};
812812

813+
/* Append a single worker row to trash (shared between current/old sections) */
814+
static void cli_append_worker_row(struct cli_showproc_ctx *ctx, struct mworker_proc *child, int up)
815+
{
816+
char *uptime = NULL;
817+
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
818+
chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s", child->pid, "worker", child->reloads, uptime, child->version);
819+
if (ctx->debug)
820+
chunk_appendf(&trash, "\t\t %-15d %-15d", child->ipc_fd[0], child->ipc_fd[1]);
821+
chunk_appendf(&trash, "\n");
822+
ha_free(&uptime);
823+
}
824+
813825
/* Displays workers and processes */
814826
static int cli_io_handler_show_proc(struct appctx *appctx)
815827
{
@@ -869,12 +881,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
869881
}
870882
prev_ts = child->timestamp;
871883

872-
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
873-
chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s", child->pid, "worker", child->reloads, uptime, child->version);
874-
if (ctx->debug)
875-
chunk_appendf(&trash, "\t\t %-15d %-15d", child->ipc_fd[0], child->ipc_fd[1]);
876-
chunk_appendf(&trash, "\n");
877-
ha_free(&uptime);
884+
cli_append_worker_row(ctx, child, up);
878885
}
879886

880887
if (applet_putchk(appctx, &trash) == -1)
@@ -909,12 +916,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
909916
}
910917
prev_ts = child->timestamp;
911918

912-
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
913-
chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s", child->pid, "worker", child->reloads, uptime, child->version);
914-
if (ctx->debug)
915-
chunk_appendf(&trash, "\t\t %-15d %-15d", child->ipc_fd[0], child->ipc_fd[1]);
916-
chunk_appendf(&trash, "\n");
917-
ha_free(&uptime);
919+
cli_append_worker_row(ctx, child, up);
918920
}
919921
}
920922
if (prev_ts != -1) {

0 commit comments

Comments
 (0)