From dc4fb33be2e100a3939b74902a5f843f55f7c723 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Nov 2025 13:05:34 +0000 Subject: [PATCH] Fix compilation errors for non-test builds Fixed build errors in tinydfs_server and example_client targets caused by missing timeout parameter and simulation client references. **Changes:** **main_server.c:** - Added int timeout variable declaration in metadata_server_main() - Added int timeout variable declaration in chunk_server_main() - Pass &timeout to metadata_server_init() call - Pass &timeout to metadata_server_step() call - Pass &timeout to chunk_server_init() call - Pass &timeout to chunk_server_step() call **system.c:** - Guarded simulation_client.h include with #ifdef BUILD_TEST - Guarded PROCESS_TYPE_CLIENT enum value with #ifdef BUILD_TEST - Guarded SimulationClient member in Process union with #ifdef BUILD_TEST - Guarded is_client() function with #ifdef BUILD_TEST - Guarded client detection logic in spawn_simulated_process() - Guarded PROCESS_TYPE_CLIENT cases in all switch statements: - spawn_simulated_process() init switch - free_process() cleanup switch - update_simulation() step switch **Result:** - tinydfs_server.out now compiles successfully - example_client.out now compiles successfully - tinydfs_test.out continues to work correctly - Simulation client code only included when BUILD_TEST is defined - All three build targets pass compilation with only pre-existing warnings The simulation_client code is now properly isolated to test builds only, preventing linker errors when building the real server and example client. --- src/main_server.c | 10 ++++++---- src/system.c | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main_server.c b/src/main_server.c index ddd9f6f..8ffea16 100644 --- a/src/main_server.c +++ b/src/main_server.c @@ -18,14 +18,15 @@ int metadata_server_main(int argc, char **argv) void *contexts[MAX_CONNS+1]; struct pollfd polled[MAX_CONNS+1]; int num_polled; + int timeout; MetadataServer state; num_polled = metadata_server_init( - &state, argc, argv, contexts, polled); + &state, argc, argv, contexts, polled, &timeout); if (num_polled < 0) return -1; for (;;) { POLL(polled, num_polled, -1); num_polled = metadata_server_step( - &state, contexts, polled, num_polled); + &state, contexts, polled, num_polled, &timeout); if (num_polled < 0) return -1; } metadata_server_free(&state); @@ -37,14 +38,15 @@ int chunk_server_main(int argc, char **argv) void *contexts[MAX_CONNS+1]; struct pollfd polled[MAX_CONNS+1]; int num_polled; + int timeout; ChunkServer state; num_polled = chunk_server_init( - &state, argc, argv, contexts, polled); + &state, argc, argv, contexts, polled, &timeout); if (num_polled < 0) return -1; for (;;) { POLL(polled, num_polled, -1); num_polled = chunk_server_step( - &state, contexts, polled, num_polled); + &state, contexts, polled, num_polled, &timeout); if (num_polled < 0) return -1; } chunk_server_free(&state); diff --git a/src/system.c b/src/system.c index 6a88aec..ff87de2 100644 --- a/src/system.c +++ b/src/system.c @@ -5,7 +5,9 @@ #include "system.h" #include "chunk_server.h" #include "metadata_server.h" +#ifdef BUILD_TEST #include "simulation_client.h" +#endif #ifdef _WIN32 #define NATIVE_HANDLE HANDLE @@ -135,7 +137,9 @@ typedef struct { typedef enum { PROCESS_TYPE_METADATA_SERVER, PROCESS_TYPE_CHUNK_SERVER, +#ifdef BUILD_TEST PROCESS_TYPE_CLIENT, +#endif } ProcessType; struct Process { @@ -152,7 +156,9 @@ struct Process { union { ChunkServer chunk_server; MetadataServer metadata_server; +#ifdef BUILD_TEST SimulationClient simulation_client; +#endif }; }; @@ -244,6 +250,7 @@ static bool is_leader(int argc, char **argv) return false; } +#ifdef BUILD_TEST static bool is_client(int argc, char **argv) { for (int i = 0; i < argc; i++) @@ -251,6 +258,7 @@ static bool is_client(int argc, char **argv) return true; return false; } +#endif #define MAX_ARGS 128 @@ -299,16 +307,21 @@ int spawn_simulated_process(char *args) } bool leader = is_leader(argc, argv); +#ifdef BUILD_TEST bool client = is_client(argc, argv); +#endif Process *process = malloc(sizeof(Process)); if (process == NULL) return -1; // Determine process type +#ifdef BUILD_TEST if (client) { process->type = PROCESS_TYPE_CLIENT; - } else if (leader) { + } else +#endif + if (leader) { process->type = PROCESS_TYPE_METADATA_SERVER; } else { process->type = PROCESS_TYPE_CHUNK_SERVER; @@ -334,9 +347,11 @@ int spawn_simulated_process(char *args) case PROCESS_TYPE_CHUNK_SERVER: num_polled = chunk_server_init(&process->chunk_server, argc, argv, contexts, polled, &timeout); break; +#ifdef BUILD_TEST case PROCESS_TYPE_CLIENT: num_polled = simulation_client_init(&process->simulation_client, argc, argv, contexts, polled, &timeout); break; +#endif default: num_polled = -1; break; @@ -368,9 +383,11 @@ static void free_process(Process *process) case PROCESS_TYPE_CHUNK_SERVER: chunk_server_free(&process->chunk_server); break; +#ifdef BUILD_TEST case PROCESS_TYPE_CLIENT: simulation_client_free(&process->simulation_client); break; +#endif } free(process); } @@ -553,9 +570,11 @@ void update_simulation(void) case PROCESS_TYPE_CHUNK_SERVER: num_polled = chunk_server_step(¤t_process->chunk_server, contexts, polled, num_polled, &timeout); break; +#ifdef BUILD_TEST case PROCESS_TYPE_CLIENT: num_polled = simulation_client_step(¤t_process->simulation_client, contexts, polled, num_polled, &timeout); break; +#endif } if (num_polled < 0) {