]> git.ipfire.org Git - telemetry.git/commitdiff
daemon: main: Group any arguments into a new struct
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 14:59:19 +0000 (14:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 14:59:19 +0000 (14:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/main.c

index 09d1514129285f8eda9325d183e60c099c0dcf0b..34169cc4cae292f603388999b5660ffba1de1555 100644 (file)
@@ -49,13 +49,18 @@ static struct argp_option options[] = {
        { NULL },
 };
 
-// The database path
-static const char* path = NULL;
+static struct config {
+       // Database Path
+       const char* path;
 
-// Collect all sources that should be enabled
-static char** sources = NULL;
+       // All sources that should be enabled
+       char** sources;
 
-static const char* user = DAEMON_USER;
+       // Daemon User
+       const char* user;
+} config = {
+       .user = DAEMON_USER,
+};
 
 static error_t parse(int key, char* arg, struct argp_state* state) {
        td_ctx* ctx = state->input;
@@ -70,14 +75,14 @@ static error_t parse(int key, char* arg, struct argp_state* state) {
                        break;
 
                case OPT_PATH:
-                       path = arg;
+                       config.path = arg;
                        break;
 
                case OPT_SOURCE:
-                       return td_strings_append(&sources, arg);
+                       return td_strings_append(&config.sources, arg);
 
                case OPT_USER:
-                       user = arg;
+                       config.user = arg;
                        break;
 
                default:
@@ -109,12 +114,12 @@ int main(int argc, char* argv[]) {
                goto ERROR;
 
        // Drop privileges
-       r = td_priv_drop_privileges(ctx, user);
+       r = td_priv_drop_privileges(ctx, config.user);
        if (r < 0)
                goto ERROR;
 
        // Create a daemon
-       r = td_daemon_create(&daemon, ctx, path, sources);
+       r = td_daemon_create(&daemon, ctx, config.path, config.sources);
        if (r < 0) {
                ERROR(ctx, "Failed to initialize the daemon: %s\n", strerror(-r));
                goto ERROR;