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.
This commit is contained in:
Claude
2025-11-02 13:05:34 +00:00
parent 88a3a6e4f0
commit dc4fb33be2
2 changed files with 26 additions and 5 deletions
+20 -1
View File
@@ -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(&current_process->chunk_server, contexts, polled, num_polled, &timeout);
break;
#ifdef BUILD_TEST
case PROCESS_TYPE_CLIENT:
num_polled = simulation_client_step(&current_process->simulation_client, contexts, polled, num_polled, &timeout);
break;
#endif
}
if (num_polled < 0) {