plugin_services: hoist the service-table helpers above the platform guards
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 08:38:39
Commitee801fe7
Parentsc9a520eb
Changed files
src/plugin_services.c+29−25■■■■■
1 file+29−25
Diff
src/plugin_services.c+29−25■■■■■
index cd49e27..deadf80 100644
--- a/src/plugin_services.c
+++ b/src/plugin_services.c
@@ -356,6 +356,35 @@ static int run_argv(char *const argv[])
356356 }
357357 #endif
358358
359+/* ------------------------------------------------------------------ */
360+/* Service table helpers (all platforms) */
361+/* ------------------------------------------------------------------ */
362+
363+static void svc_add(const char *name, const char *desc, const char *active,
364+ const char *sub, int pid)
365+{
366+ svc_t *s;
367+ if (g_count >= MAX_SERVICES) return;
368+ s = &g_svc[g_count++];
369+ memset(s, 0, sizeof *s);
370+ str_copy(s->name, sizeof s->name, name);
371+ str_copy(s->desc, sizeof s->desc, desc);
372+ str_copy(s->active, sizeof s->active, active);
373+ str_copy(s->sub, sizeof s->sub, sub);
374+ str_copy(s->enabled, sizeof s->enabled, "-");
375+ str_copy(s->since, sizeof s->since, "-");
376+ s->pid = pid;
377+}
378+
379+static svc_t *svc_find(const char *name)
380+{
381+ int i;
382+ if (!name) return NULL;
383+ for (i = 0; i < g_count; i++)
384+ if (strcmp(g_svc[i].name, name) == 0) return &g_svc[i];
385+ return NULL;
386+}
387+
359388 /* ------------------------------------------------------------------ */
360389 /* Minimal JSON field extraction (for systemctl --output=json output) */
361390 /* ------------------------------------------------------------------ */
@@ -456,31 +485,6 @@ static int json_field(const char *obj, const char *end, const char *key,
456485 /* Collection: systemd (Linux) */
457486 /* ------------------------------------------------------------------ */
458487
459-static void svc_add(const char *name, const char *desc, const char *active,
460- const char *sub, int pid)
461-{
462- svc_t *s;
463- if (g_count >= MAX_SERVICES) return;
464- s = &g_svc[g_count++];
465- memset(s, 0, sizeof *s);
466- str_copy(s->name, sizeof s->name, name);
467- str_copy(s->desc, sizeof s->desc, desc);
468- str_copy(s->active, sizeof s->active, active);
469- str_copy(s->sub, sizeof s->sub, sub);
470- str_copy(s->enabled, sizeof s->enabled, "-");
471- str_copy(s->since, sizeof s->since, "-");
472- s->pid = pid;
473-}
474-
475-static svc_t *svc_find(const char *name)
476-{
477- int i;
478- if (!name) return NULL;
479- for (i = 0; i < g_count; i++)
480- if (strcmp(g_svc[i].name, name) == 0) return &g_svc[i];
481- return NULL;
482-}
483-
484488 static char *read_file_all(const char *path, size_t *len)
485489 {
486490 FILE *f;
487491
src/plugin_services.c+29−25■■■■■
index cd49e27..deadf80 100644index cd49e27..deadf80 100644
--- a/src/plugin_services.c--- a/src/plugin_services.c
+++ b/src/plugin_services.c+++ b/src/plugin_services.c
@@ -356,6 +356,35 @@ static int run_argv(char *const argv[])@@ -356,6 +356,35 @@ static int run_argv(char *const argv[])
356 }356 }
357 #endif357 #endif
358 358
359+/* ------------------------------------------------------------------ */
360+/* Service table helpers (all platforms) */
361+/* ------------------------------------------------------------------ */
362+
363+static void svc_add(const char *name, const char *desc, const char *active,
364+ const char *sub, int pid)
365+{
366+ svc_t *s;
367+ if (g_count >= MAX_SERVICES) return;
368+ s = &g_svc[g_count++];
369+ memset(s, 0, sizeof *s);
370+ str_copy(s->name, sizeof s->name, name);
371+ str_copy(s->desc, sizeof s->desc, desc);
372+ str_copy(s->active, sizeof s->active, active);
373+ str_copy(s->sub, sizeof s->sub, sub);
374+ str_copy(s->enabled, sizeof s->enabled, "-");
375+ str_copy(s->since, sizeof s->since, "-");
376+ s->pid = pid;
377+}
378+
379+static svc_t *svc_find(const char *name)
380+{
381+ int i;
382+ if (!name) return NULL;
383+ for (i = 0; i < g_count; i++)
384+ if (strcmp(g_svc[i].name, name) == 0) return &g_svc[i];
385+ return NULL;
386+}
387+
359 /* ------------------------------------------------------------------ */388 /* ------------------------------------------------------------------ */
360 /* Minimal JSON field extraction (for systemctl --output=json output) */389 /* Minimal JSON field extraction (for systemctl --output=json output) */
361 /* ------------------------------------------------------------------ */390 /* ------------------------------------------------------------------ */
@@ -456,31 +485,6 @@ static int json_field(const char *obj, const char *end, const char *key,@@ -456,31 +485,6 @@ static int json_field(const char *obj, const char *end, const char *key,
456 /* Collection: systemd (Linux) */485 /* Collection: systemd (Linux) */
457 /* ------------------------------------------------------------------ */486 /* ------------------------------------------------------------------ */
458 487
459-static void svc_add(const char *name, const char *desc, const char *active,
460- const char *sub, int pid)
461-{
462- svc_t *s;
463- if (g_count >= MAX_SERVICES) return;
464- s = &g_svc[g_count++];
465- memset(s, 0, sizeof *s);
466- str_copy(s->name, sizeof s->name, name);
467- str_copy(s->desc, sizeof s->desc, desc);
468- str_copy(s->active, sizeof s->active, active);
469- str_copy(s->sub, sizeof s->sub, sub);
470- str_copy(s->enabled, sizeof s->enabled, "-");
471- str_copy(s->since, sizeof s->since, "-");
472- s->pid = pid;
473-}
474-
475-static svc_t *svc_find(const char *name)
476-{
477- int i;
478- if (!name) return NULL;
479- for (i = 0; i < g_count; i++)
480- if (strcmp(g_svc[i].name, name) == 0) return &g_svc[i];
481- return NULL;
482-}
483-
484 static char *read_file_all(const char *path, size_t *len)488 static char *read_file_all(const char *path, size_t *len)
485 {489 {
486 FILE *f;490 FILE *f;
487491