Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258779e234 | ||
|
|
342defca6b | ||
|
|
580aec7d57 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ Trash/
|
|||||||
src/version.h
|
src/version.h
|
||||||
dev-config/
|
dev-config/
|
||||||
db/
|
db/
|
||||||
|
copy_executable_local.sh
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
12
src/config.c
12
src/config.c
@@ -577,12 +577,20 @@ const char* get_config_value(const char* key) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 1: Database configuration (updated from file)
|
// Priority 1: Command line overrides via environment variables
|
||||||
|
if (strcmp(key, "relay_port") == 0) {
|
||||||
|
const char* port_override = getenv("C_RELAY_PORT_OVERRIDE");
|
||||||
|
if (port_override) {
|
||||||
|
return port_override;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Priority 2: Database configuration (updated from file)
|
||||||
if (get_database_config(key, buffer, sizeof(buffer)) == 0) {
|
if (get_database_config(key, buffer, sizeof(buffer)) == 0) {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2: Environment variables (fallback)
|
// Priority 3: Environment variables (fallback)
|
||||||
const char* env_value = getenv(key);
|
const char* env_value = getenv(key);
|
||||||
if (env_value) {
|
if (env_value) {
|
||||||
return env_value;
|
return env_value;
|
||||||
|
|||||||
85
src/main.c
85
src/main.c
@@ -3052,12 +3052,7 @@ int main(int argc, char* argv[]) {
|
|||||||
log_error("Invalid port number");
|
log_error("Invalid port number");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Store port in configuration system
|
// Port will be stored in configuration system after it's initialized
|
||||||
char port_str[16];
|
|
||||||
snprintf(port_str, sizeof(port_str), "%d", port);
|
|
||||||
set_database_config("relay_port", port_str, "command_line");
|
|
||||||
// Re-apply configuration to make sure global variables are updated
|
|
||||||
apply_configuration_to_globals();
|
|
||||||
} else {
|
} else {
|
||||||
log_error("Port argument requires a value");
|
log_error("Port argument requires a value");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -3118,12 +3113,8 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store database path override in configuration if specified
|
// Database path override is applied via environment variable - no need to store in config
|
||||||
if (database_path_override) {
|
// (storing database path in database creates circular dependency)
|
||||||
if (set_database_config("database_path", database_path_override, "command_line") != 0) {
|
|
||||||
log_warning("Failed to store database path override in configuration");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize nostr library BEFORE configuration system
|
// Initialize nostr library BEFORE configuration system
|
||||||
// (required for Nostr event generation in config files)
|
// (required for Nostr event generation in config files)
|
||||||
@@ -3141,6 +3132,76 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store metadata about actual paths used (for reference, not for configuration lookup)
|
||||||
|
if (database_path_override) {
|
||||||
|
// Convert to absolute path and normalize
|
||||||
|
char actual_db_path[1024];
|
||||||
|
if (database_path_override[0] == '/') {
|
||||||
|
// Already absolute
|
||||||
|
strncpy(actual_db_path, database_path_override, sizeof(actual_db_path) - 1);
|
||||||
|
} else {
|
||||||
|
// Make absolute by prepending current working directory
|
||||||
|
char cwd[1024];
|
||||||
|
if (getcwd(cwd, sizeof(cwd))) {
|
||||||
|
// Handle the case where path starts with ./
|
||||||
|
const char* clean_path = database_path_override;
|
||||||
|
if (strncmp(database_path_override, "./", 2) == 0) {
|
||||||
|
clean_path = database_path_override + 2;
|
||||||
|
}
|
||||||
|
snprintf(actual_db_path, sizeof(actual_db_path), "%s/%s", cwd, clean_path);
|
||||||
|
} else {
|
||||||
|
strncpy(actual_db_path, database_path_override, sizeof(actual_db_path) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actual_db_path[sizeof(actual_db_path) - 1] = '\0';
|
||||||
|
|
||||||
|
if (set_database_config("database_location", actual_db_path, "system") == 0) {
|
||||||
|
log_info("Stored database location metadata");
|
||||||
|
} else {
|
||||||
|
log_warning("Failed to store database location metadata");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store metadata about configuration file path used
|
||||||
|
if (strlen(g_config_manager.config_file_path) > 0) {
|
||||||
|
// Convert to absolute path and normalize
|
||||||
|
char actual_config_path[1024];
|
||||||
|
if (g_config_manager.config_file_path[0] == '/') {
|
||||||
|
// Already absolute
|
||||||
|
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
||||||
|
} else {
|
||||||
|
// Make absolute by prepending current working directory
|
||||||
|
char cwd[1024];
|
||||||
|
if (getcwd(cwd, sizeof(cwd))) {
|
||||||
|
// Handle the case where path starts with ./
|
||||||
|
const char* clean_path = g_config_manager.config_file_path;
|
||||||
|
if (strncmp(g_config_manager.config_file_path, "./", 2) == 0) {
|
||||||
|
clean_path = g_config_manager.config_file_path + 2;
|
||||||
|
}
|
||||||
|
snprintf(actual_config_path, sizeof(actual_config_path), "%s/%s", cwd, clean_path);
|
||||||
|
} else {
|
||||||
|
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actual_config_path[sizeof(actual_config_path) - 1] = '\0';
|
||||||
|
|
||||||
|
if (set_database_config("config_location", actual_config_path, "system") == 0) {
|
||||||
|
log_info("Stored configuration location metadata");
|
||||||
|
} else {
|
||||||
|
log_warning("Failed to store configuration location metadata");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply command line overrides AFTER configuration system is initialized
|
||||||
|
if (port != DEFAULT_PORT) {
|
||||||
|
log_info("Applying port override from command line");
|
||||||
|
printf(" Port: %d\n", port);
|
||||||
|
// Set environment variable for port override (runtime only, not persisted)
|
||||||
|
char port_str[16];
|
||||||
|
snprintf(port_str, sizeof(port_str), "%d", port);
|
||||||
|
setenv("C_RELAY_PORT_OVERRIDE", port_str, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize NIP-11 relay information
|
// Initialize NIP-11 relay information
|
||||||
init_relay_info();
|
init_relay_info();
|
||||||
|
|
||||||
|
|||||||
BIN
test_check.db
Normal file
BIN
test_check.db
Normal file
Binary file not shown.
BIN
test_clean_paths.db
Normal file
BIN
test_clean_paths.db
Normal file
Binary file not shown.
BIN
test_combined.db
Normal file
BIN
test_combined.db
Normal file
Binary file not shown.
BIN
test_metadata.db
Normal file
BIN
test_metadata.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user