Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce constants for application name and directories #74

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
49 changes: 22 additions & 27 deletions app/dockerdwrapperwithcompose.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <syslog.h>
#include <unistd.h>

#define APP_DIRECTORY "/usr/local/packages/" APP_NAME
#define APP_LOCALDATA APP_DIRECTORY "/localdata"

struct settings {
char *data_root;
bool use_tls;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand All @@ -645,17 +641,16 @@ 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;
}

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);
Expand Down Expand Up @@ -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);
}
Expand Down