From 3490d7446032e454b42680cb244a7023a9f003de Mon Sep 17 00:00:00 2001 From: Mattias Axelsson Date: Thu, 4 Apr 2024 14:45:47 +0200 Subject: [PATCH 1/2] Introduce constants for application name and directories --- app/Makefile | 3 +- app/dockerdwrapperwithcompose.c | 49 +++++++++++++++------------------ 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/Makefile b/app/Makefile index a605762..d9263f7 100644 --- a/app/Makefile +++ b/app/Makefile @@ -8,7 +8,8 @@ LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(PKGS)) FLAGS += -W -Wformat=2 -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes \ -Wmissing-prototypes -Winline -Wdisabled-optimization -Wfloat-equal -Wall -Werror \ - -Wno-unused-variable + -Wno-unused-variable \ + -D APP_NAME=\"$(PROG1)\" all: $(PROG1) diff --git a/app/dockerdwrapperwithcompose.c b/app/dockerdwrapperwithcompose.c index 88832b3..0f40d60 100644 --- a/app/dockerdwrapperwithcompose.c +++ b/app/dockerdwrapperwithcompose.c @@ -26,6 +26,9 @@ #include #include +#define APP_DIRECTORY "/usr/local/packages/" APP_NAME +#define APP_LOCALDATA APP_DIRECTORY "/localdata" + struct settings { char *data_root; bool use_tls; @@ -61,8 +64,7 @@ static const char *ax_parameters[] = {"IPCSocket", "TCPSocket", "UseTLS"}; -static const char *tls_cert_path = - "/usr/local/packages/dockerdwrapperwithcompose/"; +static const char *tls_cert_path = APP_DIRECTORY; static const char *tls_certs[] = {"ca.pem", "server-cert.pem", @@ -137,8 +139,7 @@ static char * get_parameter_value(const char *parameter_name) { GError *error = NULL; - AXParameter *ax_parameter = - ax_parameter_new("dockerdwrapperwithcompose", &error); + AXParameter *ax_parameter = ax_parameter_new(APP_NAME, &error); char *parameter_value = NULL; if (ax_parameter == NULL) { @@ -320,9 +321,9 @@ get_and_verify_tls_selection(bool *use_tls_ret) const bool use_tls = is_parameter_yes("UseTLS"); { if (use_tls) { - char *ca_path = g_strdup_printf("%s%s", tls_cert_path, tls_certs[0]); - char *cert_path = g_strdup_printf("%s%s", tls_cert_path, tls_certs[1]); - char *key_path = g_strdup_printf("%s%s", tls_cert_path, tls_certs[2]); + char *ca_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[0]); + char *cert_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[1]); + char *key_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[2]); bool ca_exists = access(ca_path, F_OK) == 0; bool cert_exists = access(cert_path, F_OK) == 0; @@ -432,13 +433,11 @@ start_dockerd(const struct settings *settings, struct app_state *app_state) guint args_offset = 0; gchar **args_split = NULL; - args_offset += g_snprintf( - args + args_offset, - args_len - args_offset, - "%s %s", - "dockerd", - "--config-file " - "/usr/local/packages/dockerdwrapperwithcompose/localdata/daemon.json"); + args_offset += g_snprintf(args + args_offset, + args_len - args_offset, + "%s %s", + "dockerd", + "--config-file " APP_LOCALDATA "/daemon.json"); g_strlcpy(msg, "Starting dockerd", msg_len); @@ -466,12 +465,9 @@ start_dockerd(const struct settings *settings, struct app_state *app_state) " -H tcp://0.0.0.0:%d", port); if (use_tls) { - const char *ca_path = - "/usr/local/packages/dockerdwrapperwithcompose/ca.pem"; - const char *cert_path = - "/usr/local/packages/dockerdwrapperwithcompose/server-cert.pem"; - const char *key_path = - "/usr/local/packages/dockerdwrapperwithcompose/server-key.pem"; + const char *ca_path = APP_DIRECTORY "/ca.pem"; + const char *cert_path = APP_DIRECTORY "/server-cert.pem"; + const char *key_path = APP_DIRECTORY "/server-key.pem"; args_offset += g_snprintf(args + args_offset, args_len - args_offset, " %s %s %s %s %s %s %s", @@ -629,7 +625,7 @@ parameter_changed_callback(const gchar *name, const gchar *value, __attribute__((unused)) gpointer data) { - const gchar *parname = name += strlen("root.dockerdwrapperwithcompose."); + const gchar *parname = name += strlen("root." APP_NAME "."); for (size_t i = 0; i < sizeof(ax_parameters) / sizeof(ax_parameters[0]); ++i) { @@ -645,8 +641,7 @@ setup_axparameter(void) { bool success = false; GError *error = NULL; - AXParameter *ax_parameter = - ax_parameter_new("dockerdwrapperwithcompose", &error); + AXParameter *ax_parameter = ax_parameter_new(APP_NAME, &error); if (ax_parameter == NULL) { syslog(LOG_ERR, "Error when creating AXParameter: %s", error->message); goto end; @@ -654,8 +649,8 @@ setup_axparameter(void) for (size_t i = 0; i < sizeof(ax_parameters) / sizeof(ax_parameters[0]); ++i) { - char *parameter_path = g_strdup_printf( - "%s.%s", "root.dockerdwrapperwithcompose", ax_parameters[i]); + char *parameter_path = + g_strdup_printf("root.%s.%s", APP_NAME, ax_parameters[i]); gboolean geresult = ax_parameter_register_callback( ax_parameter, parameter_path, parameter_changed_callback, NULL, &error); free(parameter_path); @@ -719,8 +714,8 @@ main(void) if (ax_parameter != NULL) { for (size_t i = 0; i < sizeof(ax_parameters) / sizeof(ax_parameters[0]); ++i) { - char *parameter_path = g_strdup_printf( - "%s.%s", "root.dockerdwrapperwithcompose", ax_parameters[i]); + char *parameter_path = + g_strdup_printf("root.%s.%s", APP_NAME, ax_parameters[i]); ax_parameter_unregister_callback(ax_parameter, parameter_path); free(parameter_path); } From 6c97c57e78ceb02f9a626a13d7dcbaa79bf94808 Mon Sep 17 00:00:00 2001 From: Madelen Andersson Date: Thu, 4 Apr 2024 15:21:20 +0200 Subject: [PATCH 2/2] Update Makefile --- app/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Makefile b/app/Makefile index d9263f7..9d6f55c 100644 --- a/app/Makefile +++ b/app/Makefile @@ -6,7 +6,7 @@ DOCKS = docker dockerd docker-compose docker-init docker-proxy CFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags $(PKGS)) LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(PKGS)) -FLAGS += -W -Wformat=2 -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes \ +CFLAGS += -W -Wformat=2 -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes \ -Wmissing-prototypes -Winline -Wdisabled-optimization -Wfloat-equal -Wall -Werror \ -Wno-unused-variable \ -D APP_NAME=\"$(PROG1)\"