@@ -810,6 +810,23 @@ struct cli_showproc_ctx {
810810 int next_reload ; /* reload number to resume from, 0 = from the beginning */
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 , time_t tv_sec )
815+ {
816+ char * uptime = NULL ;
817+ int up = tv_sec - child -> timestamp ;
818+
819+ if (up < 0 ) /* must never be negative because of clock drift */
820+ up = 0 ;
821+
822+ memprintf (& uptime , "%dd%02dh%02dm%02ds" , up / 86400 , (up % 86400 ) / 3600 , (up % 3600 ) / 60 , (up % 60 ));
823+ chunk_appendf (& trash , "%-15u %-15s %-15d %-15s %-15s" , child -> pid , "worker" , child -> reloads , uptime , child -> version );
824+ if (ctx -> debug )
825+ chunk_appendf (& trash , "\t\t %-15d %-15d" , child -> ipc_fd [0 ], child -> ipc_fd [1 ]);
826+ chunk_appendf (& trash , "\n" );
827+ ha_free (& uptime );
828+ }
829+
813830/* Displays workers and processes */
814831static int cli_io_handler_show_proc (struct appctx * appctx )
815832{
@@ -851,23 +868,14 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
851868 if (ctx -> next_reload != 0 )
852869 continue ;
853870
854- up = date .tv_sec - child -> timestamp ;
855- if (up < 0 ) /* must never be negative because of clock drift */
856- up = 0 ;
857-
858871 if (!(child -> options & PROC_O_TYPE_WORKER ))
859872 continue ;
860873
861874 if (child -> options & PROC_O_LEAVING ) {
862875 old ++ ;
863876 continue ;
864877 }
865- memprintf (& uptime , "%dd%02dh%02dm%02ds" , up / 86400 , (up % 86400 ) / 3600 , (up % 3600 ) / 60 , (up % 60 ));
866- chunk_appendf (& trash , "%-15u %-15s %-15d %-15s %-15s" , child -> pid , "worker" , child -> reloads , uptime , child -> version );
867- if (ctx -> debug )
868- chunk_appendf (& trash , "\t\t %-15d %-15d" , child -> ipc_fd [0 ], child -> ipc_fd [1 ]);
869- chunk_appendf (& trash , "\n" );
870- ha_free (& uptime );
878+ cli_append_worker_row (ctx , child , date .tv_sec );
871879 }
872880
873881 if (applet_putchk (appctx , & trash ) == -1 )
@@ -878,10 +886,6 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
878886 if (ctx -> next_reload == 0 )
879887 chunk_appendf (& trash , "# old workers\n" );
880888 list_for_each_entry (child , & proc_list , list ) {
881- up = date .tv_sec - child -> timestamp ;
882- if (up <= 0 ) /* must never be negative because of clock drift */
883- up = 0 ;
884-
885889 /* If we're resuming, skip entries that were already printed (reload >= ctx->next_reload) */
886890 if (ctx -> next_reload && child -> reloads >= ctx -> next_reload )
887891 continue ;
@@ -890,12 +894,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
890894 continue ;
891895
892896 if (child -> options & PROC_O_LEAVING ) {
893- memprintf (& uptime , "%dd%02dh%02dm%02ds" , up / 86400 , (up % 86400 ) / 3600 , (up % 3600 ) / 60 , (up % 60 ));
894- chunk_appendf (& trash , "%-15u %-15s %-15d %-15s %-15s" , child -> pid , "worker" , child -> reloads , uptime , child -> version );
895- if (ctx -> debug )
896- chunk_appendf (& trash , "\t\t %-15d %-15d" , child -> ipc_fd [0 ], child -> ipc_fd [1 ]);
897- chunk_appendf (& trash , "\n" );
898- ha_free (& uptime );
897+ cli_append_worker_row (ctx , child , date .tv_sec );
899898
900899 /* Try to flush so we can resume after this reload on next page if the buffer is full. */
901900 if (applet_putchk (appctx , & trash ) == -1 ) {
0 commit comments