Commit 15545ec4 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add NORNS_DEBUG_CONFIG_FILE_OVERRIDE env variable

Added a new environment variable NORNS_DEBUG_CONFIG_FILE_OVERRIDE that
allows test programs to override the load process for the default
configuration file. When setting this variable, the test program is
expected to call either libnorns_reload_config_file() or
libnornsctl_reload_config_file() to set the configuration file for the
test explicitly.

This commit closes #3.
parent 764d7a75
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -213,6 +213,19 @@ send_request(norns_rpc_type_t type, norns_response_t* resp, ...) {

    libcontext_t* ctx = get_context();

#ifdef __NORNS_DEBUG__
    libcontext_t zero_ctx;
    memset(&zero_ctx, 0, sizeof(zero_ctx));

    if(memcmp(ctx, &zero_ctx, sizeof(zero_ctx)) == 0) {
        FATAL("Library context not correctly initialized.\n"
              "    NORNS_DEBUG_CONFIG_FILE_OVERRIDE may have been set without "
              "calling\n" 
              "    libnorns_reload_config_file() or "
              "libnornsctl_reload_config_file()");
    }
#endif

    va_list ap;
    va_start(ap, resp);

+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ LIBSYMBOL(create_context)(void) {
        exit(EXIT_FAILURE);
    }

    memset(ctx, 0, sizeof(libcontext_t));

    int err = pthread_setspecific(LIBSYMBOL(context_key), ctx);

    if(err != 0) {
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ libnorns_create_context(void) {
        exit(EXIT_FAILURE);
    }

    memset(ctx, 0, sizeof(struct libnorns_context));

    int err = pthread_setspecific(libnorns_context_key, ctx);

    if(err != 0) {
+29 −0
Original line number Diff line number Diff line
@@ -79,9 +79,21 @@ load_config_file(void) {
        FATAL("Failed to retrieve library context");
    }
    
    if(ctx->config_file != NULL) {
        xfree(ctx->config_file);
    }

    ctx->config_file = xstrdup(config_file);

    if(ctx->api_socket != NULL) {
        xfree(ctx->api_socket);
    }

    ctx->api_socket = xstrdup(valid_opts[0].val);

    DBG("Configuration loaded from file:");
    DBG("   user api socket: %s", ctx->api_socket);

    xfree(valid_opts[0].val);
}

@@ -92,14 +104,31 @@ libnorns_init(void) {
    FILE* logfp = stderr;

#ifdef __NORNS_DEBUG__
    bool override_config_file = false;

    // parse relevant environment variables
    if(getenv("NORNS_DEBUG_OUTPUT_TO_STDERR") == NULL) {
        logfp = NULL;
        DBG("NORNS_DEBUG_OUTPUT_TO_STDERR is set, all messages will be "
            "sent to stderr");
    }

    if(getenv("NORNS_DEBUG_CONFIG_FILE_OVERRIDE") != NULL) {
        override_config_file = true;
        DBG("NORNS_DEBUG_CONFIG_FILE_OVERRIDE is set, default configuration "
            "file will be ignored");
    }
#endif

    log_init(LIBNORNS_LOG_PREFIX, logfp);
    libnorns_create_context();

#ifdef __NORNS_DEBUG__
    if(override_config_file) {
        return;
    }
#endif

    load_config_file();
}

+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ libnornsctl_create_context(void) {
        exit(EXIT_FAILURE);
    }

    memset(ctx, 0, sizeof(struct libnornsctl_context));

    int err = pthread_setspecific(libnornsctl_context_key, ctx);

    if(err != 0) {
Loading