refactor: quality cleanup — table-driven CLI, file.c split, scanner helpers, unified error reporting #216
+25
-25
@@ -60,7 +60,7 @@ static bool parse_positive_int(const char* s, int* out_val) {
|
|||||||
static int set_string_option(char** dest, const char* value, const char* option_name) {
|
static int set_string_option(char** dest, const char* value, const char* option_name) {
|
||||||
char* dup = str_dup(value);
|
char* dup = str_dup(value);
|
||||||
if (!dup) {
|
if (!dup) {
|
||||||
fprintf(stderr, "Error: memory allocation failed for %s\n", option_name);
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed for %s", option_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(*dest);
|
free(*dest);
|
||||||
@@ -71,7 +71,7 @@ static int set_string_option(char** dest, const char* value, const char* option_
|
|||||||
/* Parse a string as a positive integer into *dest. Returns true on success, false on error. */
|
/* Parse a string as a positive integer into *dest. Returns true on success, false on error. */
|
||||||
static int set_positive_int_option(int* dest, const char* value, const char* option_name) {
|
static int set_positive_int_option(int* dest, const char* value, const char* option_name) {
|
||||||
if (!parse_positive_int(value, dest)) {
|
if (!parse_positive_int(value, dest)) {
|
||||||
fprintf(stderr, "Error: %s must be a positive integer\n", option_name);
|
log_message(LOG_LEVEL_ERROR, "%s must be a positive integer", option_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -80,7 +80,7 @@ static int set_positive_int_option(int* dest, const char* value, const char* opt
|
|||||||
/* Parse a string as a non-negative integer into *dest. Returns true on success, false on error. */
|
/* Parse a string as a non-negative integer into *dest. Returns true on success, false on error. */
|
||||||
static int set_nonneg_int_option(int* dest, const char* value, const char* option_name) {
|
static int set_nonneg_int_option(int* dest, const char* value, const char* option_name) {
|
||||||
if (!parse_nonneg_int(value, dest)) {
|
if (!parse_nonneg_int(value, dest)) {
|
||||||
fprintf(stderr, "Error: %s must be a non-negative integer\n", option_name);
|
log_message(LOG_LEVEL_ERROR, "%s must be a non-negative integer", option_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -94,7 +94,7 @@ static int parse_ull_arg(const char* val, unsigned long long* out, const char* o
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
unsigned long long v = strtoull(val, &end, 10);
|
unsigned long long v = strtoull(val, &end, 10);
|
||||||
if (errno != 0 || *end != '\0') {
|
if (errno != 0 || *end != '\0') {
|
||||||
fprintf(stderr, "Error: %s must be a non-negative integer\n", optname);
|
log_message(LOG_LEVEL_ERROR, "%s must be a non-negative integer", optname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*out = v;
|
*out = v;
|
||||||
@@ -106,13 +106,13 @@ static int config_add_pattern(char*** patterns, int* count, const char* value,
|
|||||||
const char* optname) {
|
const char* optname) {
|
||||||
char** tmp = realloc(*patterns, (*count + 1) * sizeof(char*));
|
char** tmp = realloc(*patterns, (*count + 1) * sizeof(char*));
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
fprintf(stderr, "Error: memory allocation failed for %s\n", optname);
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed for %s", optname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*patterns = tmp;
|
*patterns = tmp;
|
||||||
char* dup = str_dup(value);
|
char* dup = str_dup(value);
|
||||||
if (!dup) {
|
if (!dup) {
|
||||||
fprintf(stderr, "Error: memory allocation failed for %s\n", optname);
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed for %s", optname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(*patterns)[(*count)++] = dup;
|
(*patterns)[(*count)++] = dup;
|
||||||
@@ -215,7 +215,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
if (entry->kind != OPT_FLAG) {
|
if (entry->kind != OPT_FLAG) {
|
||||||
if (i + 1 >= argc) {
|
if (i + 1 >= argc) {
|
||||||
fprintf(stderr, "Error: missing argument for %s\n", entry->name);
|
log_message(LOG_LEVEL_ERROR, "missing argument for %s", entry->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (apply_table_option(config, entry, argv[++i]) != 0)
|
if (apply_table_option(config, entry, argv[++i]) != 0)
|
||||||
@@ -241,7 +241,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (set_positive_int_option(&config->ssh_port, argv[++i], "-p") != 0)
|
if (set_positive_int_option(&config->ssh_port, argv[++i], "-p") != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (config->ssh_port > 65535) {
|
if (config->ssh_port > 65535) {
|
||||||
log_message(LOG_LEVEL_ERROR, "SSH port must be 1-65535\n");
|
log_message(LOG_LEVEL_ERROR, "SSH port must be 1-65535");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (opt_is(argv[i], "--exclude", NULL) && i + 1 < argc) {
|
} else if (opt_is(argv[i], "--exclude", NULL) && i + 1 < argc) {
|
||||||
@@ -259,7 +259,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (val >= DELTA_BLOCK_SIZE_MIN && val <= DELTA_BLOCK_SIZE_MAX)
|
if (val >= DELTA_BLOCK_SIZE_MIN && val <= DELTA_BLOCK_SIZE_MAX)
|
||||||
config->delta_block_size = (uint32_t)val;
|
config->delta_block_size = (uint32_t)val;
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Warning: --delta-block value %llu out of range, using default\n", val);
|
log_message(LOG_LEVEL_WARNING, "--delta-block value %llu out of range, using default", val);
|
||||||
} else if (opt_is(argv[i], "--delta-max", NULL) && i + 1 < argc) {
|
} else if (opt_is(argv[i], "--delta-max", NULL) && i + 1 < argc) {
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
if (parse_ull_arg(argv[++i], &val, "--delta-max") != 0)
|
if (parse_ull_arg(argv[++i], &val, "--delta-max") != 0)
|
||||||
@@ -267,7 +267,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (val >= DELTA_MIN_FILE_SIZE)
|
if (val >= DELTA_MIN_FILE_SIZE)
|
||||||
config->delta_max_file_size = val;
|
config->delta_max_file_size = val;
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Warning: --delta-max value %llu too small, using default\n", val);
|
log_message(LOG_LEVEL_WARNING, "--delta-max value %llu too small, using default", val);
|
||||||
} else if (opt_is(argv[i], "-c", "-z")) {
|
} else if (opt_is(argv[i], "-c", "-z")) {
|
||||||
config->use_compression = true;
|
config->use_compression = true;
|
||||||
log_message(LOG_LEVEL_INFO, "Enabled Compression");
|
log_message(LOG_LEVEL_INFO, "Enabled Compression");
|
||||||
@@ -276,7 +276,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
long level = strtol(argv[i + 1], &end_ptr, 10);
|
long level = strtol(argv[i + 1], &end_ptr, 10);
|
||||||
if (*end_ptr == '\0') {
|
if (*end_ptr == '\0') {
|
||||||
if (level < 1 || level > 22) {
|
if (level < 1 || level > 22) {
|
||||||
fprintf(stderr, "Error: compression level must be 1-22\n");
|
log_message(LOG_LEVEL_ERROR, "compression level must be 1-22");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
config->compression_level = (int)level;
|
config->compression_level = (int)level;
|
||||||
@@ -298,11 +298,11 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
log_message(LOG_LEVEL_INFO, "Enabled Chunk Serialization");
|
log_message(LOG_LEVEL_INFO, "Enabled Chunk Serialization");
|
||||||
} else if (opt_is(argv[i], "--server-port", NULL) && i + 1 < argc) {
|
} else if (opt_is(argv[i], "--server-port", NULL) && i + 1 < argc) {
|
||||||
if (!parse_positive_int(argv[++i], &config->server_port)) {
|
if (!parse_positive_int(argv[++i], &config->server_port)) {
|
||||||
fprintf(stderr, "Error: invalid --server-port value: %s\n", argv[i]);
|
log_message(LOG_LEVEL_ERROR, "invalid --server-port value: %s", argv[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (config->server_port > 65535) {
|
if (config->server_port > 65535) {
|
||||||
fprintf(stderr, "Error: server port must be 1-65535\n");
|
log_message(LOG_LEVEL_ERROR, "server port must be 1-65535");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (opt_is(argv[i], "--bwlimit", NULL) && i + 1 < argc) {
|
} else if (opt_is(argv[i], "--bwlimit", NULL) && i + 1 < argc) {
|
||||||
@@ -310,11 +310,11 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (parse_ull_arg(argv[++i], &kbps, "--bwlimit") != 0)
|
if (parse_ull_arg(argv[++i], &kbps, "--bwlimit") != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (kbps == 0) {
|
if (kbps == 0) {
|
||||||
fprintf(stderr, "Error: --bwlimit must be a positive integer\n");
|
log_message(LOG_LEVEL_ERROR, "--bwlimit must be a positive integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (kbps > ULLONG_MAX / 1024) {
|
if (kbps > ULLONG_MAX / 1024) {
|
||||||
fprintf(stderr, "Error: --bwlimit value too large\n");
|
log_message(LOG_LEVEL_ERROR, "--bwlimit value too large");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
io_set_bwlimit(kbps * 1024);
|
io_set_bwlimit(kbps * 1024);
|
||||||
@@ -324,7 +324,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (parse_ull_arg(argv[++i], &val, "--chunk-size") != 0)
|
if (parse_ull_arg(argv[++i], &val, "--chunk-size") != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (val == 0) {
|
if (val == 0) {
|
||||||
fprintf(stderr, "Error: --chunk-size must be a positive integer\n");
|
log_message(LOG_LEVEL_ERROR, "--chunk-size must be a positive integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
config->chunk_size = val;
|
config->chunk_size = val;
|
||||||
@@ -336,7 +336,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
}
|
}
|
||||||
FILE* lf = fopen(argv[++i], "a");
|
FILE* lf = fopen(argv[++i], "a");
|
||||||
if (!lf) {
|
if (!lf) {
|
||||||
fprintf(stderr, "Error: could not open log file '%s': %s\n", argv[i], strerror(errno));
|
log_message(LOG_LEVEL_ERROR, "could not open log file '%s': %s", argv[i], strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
config->log_file = lf;
|
config->log_file = lf;
|
||||||
@@ -358,7 +358,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
if (set_positive_int_option(&config->compression_level, argv[++i], "--compress-level") != 0)
|
if (set_positive_int_option(&config->compression_level, argv[++i], "--compress-level") != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (config->compression_level < 1 || config->compression_level > 22) {
|
if (config->compression_level < 1 || config->compression_level > 22) {
|
||||||
fprintf(stderr, "Error: --compress-level must be between 1 and 22\n");
|
log_message(LOG_LEVEL_ERROR, "--compress-level must be between 1 and 22");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (argv[i][0] == '-') {
|
} else if (argv[i][0] == '-') {
|
||||||
@@ -381,7 +381,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
|||||||
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count) {
|
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count) {
|
||||||
FILE* fp = fopen(filepath, "r");
|
FILE* fp = fopen(filepath, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "Error: could not open pattern file '%s': %s\n", filepath, strerror(errno));
|
log_message(LOG_LEVEL_ERROR, "could not open pattern file '%s': %s", filepath, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
@@ -420,7 +420,7 @@ int main(int argc, char* argv[]) {
|
|||||||
bool config_owned_by_pipeline = false;
|
bool config_owned_by_pipeline = false;
|
||||||
Config* config = config_create();
|
Config* config = config_create();
|
||||||
if (!config) {
|
if (!config) {
|
||||||
fprintf(stderr, "Error: failed to allocate config\n");
|
log_message(LOG_LEVEL_ERROR, "failed to allocate config");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
config->save_to_disk = save_to_disk;
|
config->save_to_disk = save_to_disk;
|
||||||
@@ -441,20 +441,20 @@ int main(int argc, char* argv[]) {
|
|||||||
free(config->receive_root_directory);
|
free(config->receive_root_directory);
|
||||||
config->send_directory = str_dup(argv[positional_args[0]]);
|
config->send_directory = str_dup(argv[positional_args[0]]);
|
||||||
if (!config->send_directory) {
|
if (!config->send_directory) {
|
||||||
fprintf(stderr, "Error: memory allocation failed\n");
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed");
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
config->receive_root_directory = str_dup(argv[positional_args[1]]);
|
config->receive_root_directory = str_dup(argv[positional_args[1]]);
|
||||||
if (!config->receive_root_directory) {
|
if (!config->receive_root_directory) {
|
||||||
fprintf(stderr, "Error: memory allocation failed\n");
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed");
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
config->save_to_disk = true;
|
config->save_to_disk = true;
|
||||||
config_parse_ssh_dest(config);
|
config_parse_ssh_dest(config);
|
||||||
} else if (positional_count == 1) {
|
} else if (positional_count == 1) {
|
||||||
fprintf(stderr, "Error: missing destination argument\n");
|
log_message(LOG_LEVEL_ERROR, "missing destination argument");
|
||||||
print_usage();
|
print_usage();
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -462,7 +462,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (!config->send_directory && env_source) {
|
if (!config->send_directory && env_source) {
|
||||||
config->send_directory = str_dup(env_source);
|
config->send_directory = str_dup(env_source);
|
||||||
if (!config->send_directory) {
|
if (!config->send_directory) {
|
||||||
fprintf(stderr, "Error: memory allocation failed\n");
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed");
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@@ -470,7 +470,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (!config->receive_root_directory && env_dest) {
|
if (!config->receive_root_directory && env_dest) {
|
||||||
config->receive_root_directory = str_dup(env_dest);
|
config->receive_root_directory = str_dup(env_dest);
|
||||||
if (!config->receive_root_directory) {
|
if (!config->receive_root_directory) {
|
||||||
fprintf(stderr, "Error: memory allocation failed\n");
|
log_message(LOG_LEVEL_ERROR, "memory allocation failed");
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ static ScannerOptions scanner_options_from_config(const Config* config, int num_
|
|||||||
static Client* connect_transfer_client(const Config* config) {
|
static Client* connect_transfer_client(const Config* config) {
|
||||||
if (config->transport == TRANSPORT_SSH) {
|
if (config->transport == TRANSPORT_SSH) {
|
||||||
if (config->use_sendfile) {
|
if (config->use_sendfile) {
|
||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
log_message(LOG_LEVEL_ERROR, "-f/--sendfile is not supported with SSH transport");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return client_connect_ssh(config->ssh_destination, config->ssh_port,
|
return client_connect_ssh(config->ssh_destination, config->ssh_port,
|
||||||
@@ -377,7 +377,7 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
Client* client = connect_transfer_client(context->config);
|
Client* client = connect_transfer_client(context->config);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
if (context->config->transport == TRANSPORT_TCP)
|
if (context->config->transport == TRANSPORT_TCP)
|
||||||
fprintf(stderr, "Error: could not connect to server%s\n",
|
log_message(LOG_LEVEL_ERROR, "could not connect to server%s",
|
||||||
context->config->use_tls ? " via TLS" : "");
|
context->config->use_tls ? " via TLS" : "");
|
||||||
pipeline_cancel(context);
|
pipeline_cancel(context);
|
||||||
mark_sender_done(context);
|
mark_sender_done(context);
|
||||||
@@ -425,7 +425,7 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
if (send_chunk(client, current_chunk, context->config) != 0) {
|
if (send_chunk(client, current_chunk, context->config) != 0) {
|
||||||
fprintf(stderr, "Error: unexpected error while sending chunk\n");
|
log_message(LOG_LEVEL_ERROR, "unexpected error while sending chunk");
|
||||||
chunk_destroy(current_chunk);
|
chunk_destroy(current_chunk);
|
||||||
pipeline_cancel(context);
|
pipeline_cancel(context);
|
||||||
disconnect_transfer_client(client);
|
disconnect_transfer_client(client);
|
||||||
@@ -585,7 +585,7 @@ int send_files(Config* config) {
|
|||||||
Client* client = connect_transfer_client(config);
|
Client* client = connect_transfer_client(config);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
if (config->transport == TRANSPORT_TCP)
|
if (config->transport == TRANSPORT_TCP)
|
||||||
fprintf(stderr, "Error: could not connect to server%s\n", config->use_tls ? " via TLS" : "");
|
log_message(LOG_LEVEL_ERROR, "could not connect to server%s", config->use_tls ? " via TLS" : "");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ProtocolSession session;
|
ProtocolSession session;
|
||||||
@@ -736,7 +736,7 @@ int send_files_multithreaded(Config* config) {
|
|||||||
sender_created = (thrd_create(&sender, send_chunks_multithreaded, context) == thrd_success);
|
sender_created = (thrd_create(&sender, send_chunks_multithreaded, context) == thrd_success);
|
||||||
|
|
||||||
if (!scanner_created || !loader_created || !sender_created) {
|
if (!scanner_created || !loader_created || !sender_created) {
|
||||||
perror("Error creating threads");
|
log_perror("Error creating threads");
|
||||||
pipeline_cancel(context);
|
pipeline_cancel(context);
|
||||||
mtx_lock(&context->mutex_progress);
|
mtx_lock(&context->mutex_progress);
|
||||||
context->sender_done = true;
|
context->sender_done = true;
|
||||||
@@ -756,7 +756,7 @@ int send_files_multithreaded(Config* config) {
|
|||||||
if (config->show_progress) {
|
if (config->show_progress) {
|
||||||
progress_created = (thrd_create(&progress, progress_thread_fn, context) == thrd_success);
|
progress_created = (thrd_create(&progress, progress_thread_fn, context) == thrd_success);
|
||||||
if (!progress_created) {
|
if (!progress_created) {
|
||||||
perror("Error creating progress thread");
|
log_perror("Error creating progress thread");
|
||||||
/* Non-fatal; continue without progress reporting */
|
/* Non-fatal; continue without progress reporting */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,38 @@
|
|||||||
#include "client_validation.h"
|
#include "client_validation.h"
|
||||||
|
#include "log.h"
|
||||||
#include "usage.h"
|
#include "usage.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* Validate config after parsing. Returns true if valid. */
|
/* Validate config after parsing. Returns true if valid. */
|
||||||
bool validate_config(const Config* config) {
|
bool validate_config(const Config* config) {
|
||||||
if (!config->send_directory || !config->receive_root_directory) {
|
if (!config->send_directory || !config->receive_root_directory) {
|
||||||
fprintf(stderr, "Error: source and destination directories are required\n");
|
log_message(LOG_LEVEL_ERROR, "source and destination directories are required");
|
||||||
print_usage();
|
print_usage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->use_sendfile && (config->use_chunk_serialization || config->use_compression)) {
|
if (config->use_sendfile && (config->use_chunk_serialization || config->use_compression)) {
|
||||||
fprintf(stderr, "Error: -f/--sendfile cannot be combined with -c (compression) or -s (chunk "
|
log_message(LOG_LEVEL_ERROR, "-f/--sendfile cannot be combined with -c (compression) or -s "
|
||||||
"serialization)\n");
|
"(chunk serialization)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->transport == TRANSPORT_SSH && config->use_sendfile) {
|
if (config->transport == TRANSPORT_SSH && config->use_sendfile) {
|
||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
log_message(LOG_LEVEL_ERROR, "-f/--sendfile is not supported with SSH transport");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->use_incremental && config->use_chunk_serialization) {
|
if (config->use_incremental && config->use_chunk_serialization) {
|
||||||
fprintf(stderr, "Error: --incremental is not supported with -s (chunk serialization)\n");
|
log_message(LOG_LEVEL_ERROR, "--incremental is not supported with -s (chunk serialization)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->use_delta && !config->use_incremental) {
|
if (config->use_delta && !config->use_incremental) {
|
||||||
fprintf(stderr, "Error: --delta requires --incremental\n");
|
log_message(LOG_LEVEL_ERROR, "--delta requires --incremental");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->use_delta && config->use_chunk_serialization) {
|
if (config->use_delta && config->use_chunk_serialization) {
|
||||||
fprintf(stderr, "Error: --delta cannot be combined with -s (chunk serialization)\n");
|
log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -s (chunk serialization)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->use_delta && config->use_sendfile) {
|
if (config->use_delta && config->use_sendfile) {
|
||||||
fprintf(stderr, "Error: --delta cannot be combined with -f (sendfile)\n");
|
log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -f (sendfile)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config->append || config->append_verify) {
|
if (config->append || config->append_verify) {
|
||||||
@@ -42,7 +43,7 @@ bool validate_config(const Config* config) {
|
|||||||
}
|
}
|
||||||
if (config->use_tls) {
|
if (config->use_tls) {
|
||||||
if (!config->tls_cert || !config->tls_key) {
|
if (!config->tls_cert || !config->tls_key) {
|
||||||
fprintf(stderr, "Error: --tls requires --cert and --key\n");
|
log_message(LOG_LEVEL_ERROR, "--tls requires --cert and --key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "array_list.h"
|
#include "array_list.h"
|
||||||
#include "chunk.h"
|
#include "chunk.h"
|
||||||
@@ -226,7 +227,7 @@ static int open_next_directory(DirectoryScanner* scanner) {
|
|||||||
free(de);
|
free(de);
|
||||||
scanner->current_dir = opendir(scanner->current_path);
|
scanner->current_dir = opendir(scanner->current_path);
|
||||||
if (scanner->current_dir == NULL) {
|
if (scanner->current_dir == NULL) {
|
||||||
perror("Could not open directory");
|
log_perror("Could not open directory");
|
||||||
free(scanner->current_path);
|
free(scanner->current_path);
|
||||||
scanner->current_path = NULL;
|
scanner->current_path = NULL;
|
||||||
scanner->failed = true;
|
scanner->failed = true;
|
||||||
@@ -564,7 +565,7 @@ static bool scan_root_directory(ParallelScanner* ps, const char* root_directory,
|
|||||||
ArrayList* subdirs) {
|
ArrayList* subdirs) {
|
||||||
DIR* dir = opendir(root_directory);
|
DIR* dir = opendir(root_directory);
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
perror("Could not open root directory for parallel scan");
|
log_perror("Could not open root directory for parallel scan");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const struct dirent* entry;
|
const struct dirent* entry;
|
||||||
|
|||||||
+1
-1
@@ -129,7 +129,7 @@ void handler(int file_descriptor) {
|
|||||||
if (receiver_created)
|
if (receiver_created)
|
||||||
writer_created = thrd_create(&writer, write_thread, context) == thrd_success;
|
writer_created = thrd_create(&writer, write_thread, context) == thrd_success;
|
||||||
if (!receiver_created || !writer_created) {
|
if (!receiver_created || !writer_created) {
|
||||||
perror("Error creating Threads");
|
log_perror("Error creating Threads");
|
||||||
if (receiver_created) {
|
if (receiver_created) {
|
||||||
mtx_lock(&context->mutex);
|
mtx_lock(&context->mutex);
|
||||||
atomic_store(&context->cancelled, true);
|
atomic_store(&context->cancelled, true);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log.h"
|
||||||
#include "array_list.h"
|
#include "array_list.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -6,7 +7,7 @@
|
|||||||
ArrayList* array_list_create(void (*item_destroyer)(void* item)) {
|
ArrayList* array_list_create(void (*item_destroyer)(void* item)) {
|
||||||
ArrayList* list = (ArrayList*)malloc(sizeof(ArrayList));
|
ArrayList* list = (ArrayList*)malloc(sizeof(ArrayList));
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for array list struct");
|
log_perror("ERROR: Could not allocate memory for array list struct");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ static bool array_list_extend(ArrayList* array_list) {
|
|||||||
new_capacity = INITIAL_ARRAY_SIZE;
|
new_capacity = INITIAL_ARRAY_SIZE;
|
||||||
void* new_items = realloc(array_list->items, new_capacity * sizeof(void*));
|
void* new_items = realloc(array_list->items, new_capacity * sizeof(void*));
|
||||||
if (new_items == NULL) {
|
if (new_items == NULL) {
|
||||||
perror("ERROR: Could not reallocate memory for array list items");
|
log_perror("ERROR: Could not reallocate memory for array list items");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
array_list->items = new_items;
|
array_list->items = new_items;
|
||||||
@@ -68,7 +69,7 @@ void** array_list_to_array(const ArrayList* array_list) {
|
|||||||
}
|
}
|
||||||
void** array = malloc(array_list->size * sizeof(void*));
|
void** array = malloc(array_list->size * sizeof(void*));
|
||||||
if (array == NULL) {
|
if (array == NULL) {
|
||||||
perror("Could not malloc space for array from array list!");
|
log_perror("Could not malloc space for array from array list!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(array, array_list->items, array_list->size * sizeof(void*));
|
memcpy(array, array_list->items, array_list->size * sizeof(void*));
|
||||||
|
|||||||
+3
-3
@@ -20,7 +20,7 @@
|
|||||||
Chunk* chunk_create(File** items, int element_count) {
|
Chunk* chunk_create(File** items, int element_count) {
|
||||||
Chunk* chunk = (Chunk*)malloc(sizeof(Chunk));
|
Chunk* chunk = (Chunk*)malloc(sizeof(Chunk));
|
||||||
if (chunk == NULL) {
|
if (chunk == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for chunk structure");
|
log_perror("ERROR: Could not allocate memory for chunk structure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ Chunk* chunk_deserialize(Data* data, bool use_metadata) {
|
|||||||
|
|
||||||
char* path = malloc(path_len + 1);
|
char* path = malloc(path_len + 1);
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
perror("Could not allocate memory for file path");
|
log_perror("Could not allocate memory for file path");
|
||||||
array_list_delete(files);
|
array_list_delete(files);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ Chunk* chunk_deserialize(Data* data, bool use_metadata) {
|
|||||||
|
|
||||||
void* file_data = malloc(file_data_size > 0 ? file_data_size : 1);
|
void* file_data = malloc(file_data_size > 0 ? file_data_size : 1);
|
||||||
if (file_data == NULL) {
|
if (file_data == NULL) {
|
||||||
perror("Could not allocate memory for file data");
|
log_perror("Could not allocate memory for file data");
|
||||||
file_destroy(file);
|
file_destroy(file);
|
||||||
array_list_delete(files);
|
array_list_delete(files);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+5
-5
@@ -29,7 +29,7 @@ File* file_create(const char* path) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
File* file = (File*)malloc(sizeof(File));
|
File* file = (File*)malloc(sizeof(File));
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for file struct");
|
log_perror("ERROR: Could not allocate memory for file struct");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ void file_destroy(void* item) {
|
|||||||
FileMetadata* file_metadata_create(const struct stat* stats) {
|
FileMetadata* file_metadata_create(const struct stat* stats) {
|
||||||
FileMetadata* m = malloc(sizeof(FileMetadata));
|
FileMetadata* m = malloc(sizeof(FileMetadata));
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for file metadata");
|
log_perror("ERROR: Could not allocate memory for file metadata");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
m->mode = stats->st_mode;
|
m->mode = stats->st_mode;
|
||||||
@@ -96,7 +96,7 @@ bool file_load_data(File* file) {
|
|||||||
return true;
|
return true;
|
||||||
file->data->data = malloc(file->data->size);
|
file->data->data = malloc(file->data->size);
|
||||||
if (file->data->data == NULL) {
|
if (file->data->data == NULL) {
|
||||||
perror("Could not allocate memory for file data");
|
log_perror("Could not allocate memory for file data");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,13 +125,13 @@ bool file_write_to_disk(const char* path, const void* data, unsigned long long d
|
|||||||
size_t file_content_to_buffer(File* file) {
|
size_t file_content_to_buffer(File* file) {
|
||||||
FILE* file_pointer = fopen(file->path, "rb");
|
FILE* file_pointer = fopen(file->path, "rb");
|
||||||
if (file_pointer == NULL) {
|
if (file_pointer == NULL) {
|
||||||
perror("Could not open the file!");
|
log_perror("Could not open the file!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t bytes_read = fread(file->data->data, 1, file->data->size, file_pointer);
|
size_t bytes_read = fread(file->data->data, 1, file->data->size, file_pointer);
|
||||||
if (bytes_read != (size_t)file->data->size) {
|
if (bytes_read != (size_t)file->data->size) {
|
||||||
fclose(file_pointer);
|
fclose(file_pointer);
|
||||||
perror("Read unexpected number of bytes from File!");
|
log_perror("Read unexpected number of bytes from File!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fclose(file_pointer);
|
fclose(file_pointer);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
|
|||||||
|
|
||||||
int fd = open(file->path, O_RDONLY);
|
int fd = open(file->path, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror("Could not open file for sendfile");
|
log_perror("Could not open file for sendfile");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
|
|||||||
if (sent == -1) {
|
if (sent == -1) {
|
||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
perror("sendfile failed");
|
log_perror("sendfile failed");
|
||||||
close(fd);
|
close(fd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
static const char* log_level_strings[] = {"DEBUG", "INFO", "WARN", "ERROR"};
|
static const char* log_level_strings[] = {"DEBUG", "INFO", "WARN", "ERROR"};
|
||||||
@@ -50,3 +52,7 @@ void log_message(LogLevel log_level, const char* format, ...) {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log_perror(const char* context) {
|
||||||
|
log_message(LOG_LEVEL_ERROR, "%s: %s", context, strerror(errno));
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
typedef enum { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR } LogLevel;
|
typedef enum { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR } LogLevel;
|
||||||
|
|
||||||
void log_message(LogLevel log_level, const char* message, ...);
|
void log_message(LogLevel log_level, const char* message, ...);
|
||||||
|
void log_perror(const char* context);
|
||||||
void set_log_level(LogLevel level);
|
void set_log_level(LogLevel level);
|
||||||
void log_set_file(FILE* fp);
|
void log_set_file(FILE* fp);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ PipelineContextSender* pipeline_context_sender_create(Config* config, Queue* que
|
|||||||
return context;
|
return context;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
perror("Error initializing synchronization objects");
|
log_perror("Error initializing synchronization objects");
|
||||||
if (init >= 6)
|
if (init >= 6)
|
||||||
cnd_destroy(&context->condition_not_empty_loader);
|
cnd_destroy(&context->condition_not_empty_loader);
|
||||||
if (init >= 5)
|
if (init >= 5)
|
||||||
@@ -116,7 +116,7 @@ PipelineContextReceiver* pipeline_context_receiver_create(Config* config, Queue*
|
|||||||
return context;
|
return context;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
perror("Error initializing synchronization objects");
|
log_perror("Error initializing synchronization objects");
|
||||||
if (init >= 3)
|
if (init >= 3)
|
||||||
cnd_destroy(&context->condition_not_empty);
|
cnd_destroy(&context->condition_not_empty);
|
||||||
if (init >= 2)
|
if (init >= 2)
|
||||||
|
|||||||
+4
-3
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -13,7 +14,7 @@ Queue* queue_create(int capacity, void (*destroyer)(void* item)) {
|
|||||||
|
|
||||||
Queue* queue = (Queue*)malloc(sizeof(Queue));
|
Queue* queue = (Queue*)malloc(sizeof(Queue));
|
||||||
if (queue == NULL) {
|
if (queue == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for queue structure");
|
log_perror("ERROR: Could not allocate memory for queue structure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ static bool queue_double_capacity(Queue* queue) {
|
|||||||
new_capacity = 100;
|
new_capacity = 100;
|
||||||
void** new_items = malloc(new_capacity * sizeof(void*));
|
void** new_items = malloc(new_capacity * sizeof(void*));
|
||||||
if (new_items == NULL) {
|
if (new_items == NULL) {
|
||||||
perror("ERROR: Could not allocate memory for doubling capacity of queue.");
|
log_perror("ERROR: Could not allocate memory for doubling capacity of queue.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < queue->size; i++)
|
for (int i = 0; i < queue->size; i++)
|
||||||
@@ -127,7 +128,7 @@ bool queue_enqueue_multithreaded_cancel(Queue* queue, void* item, mtx_t* mutex,
|
|||||||
|
|
||||||
void* queue_dequeue(Queue* queue) {
|
void* queue_dequeue(Queue* queue) {
|
||||||
if (queue == NULL || queue_is_empty(queue)) {
|
if (queue == NULL || queue_is_empty(queue)) {
|
||||||
perror("ERROR: Could not dequeue from null or empty queue.");
|
log_perror("ERROR: Could not dequeue from null or empty queue.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log.h"
|
||||||
#include "transport_ssh.h"
|
#include "transport_ssh.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -76,7 +77,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
|
|||||||
|
|
||||||
int sv[2];
|
int sv[2];
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
|
||||||
perror("socketpair failed");
|
log_perror("socketpair failed");
|
||||||
remote_dest_destroy(&r);
|
remote_dest_destroy(&r);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
|
|||||||
|
|
||||||
int exec_pipe[2];
|
int exec_pipe[2];
|
||||||
if (pipe(exec_pipe) < 0) {
|
if (pipe(exec_pipe) < 0) {
|
||||||
perror("pipe failed");
|
log_perror("pipe failed");
|
||||||
close(sv[0]);
|
close(sv[0]);
|
||||||
close(sv[1]);
|
close(sv[1]);
|
||||||
remote_dest_destroy(&r);
|
remote_dest_destroy(&r);
|
||||||
@@ -98,7 +99,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
|
|||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
perror("fork failed");
|
log_perror("fork failed");
|
||||||
close(sv[0]);
|
close(sv[0]);
|
||||||
close(sv[1]);
|
close(sv[1]);
|
||||||
close(exec_pipe[0]);
|
close(exec_pipe[0]);
|
||||||
@@ -151,7 +152,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
|
|||||||
ssh_argv[ac++] = "--stdio";
|
ssh_argv[ac++] = "--stdio";
|
||||||
ssh_argv[ac] = NULL;
|
ssh_argv[ac] = NULL;
|
||||||
execvp("ssh", ssh_argv);
|
execvp("ssh", ssh_argv);
|
||||||
perror("exec of ssh failed");
|
log_perror("exec of ssh failed");
|
||||||
ssize_t wret = write(exec_pipe[1], "x", 1);
|
ssize_t wret = write(exec_pipe[1], "x", 1);
|
||||||
(void)wret;
|
(void)wret;
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
|||||||
@@ -30,20 +30,20 @@ static void sigchld_handler(int sig) {
|
|||||||
Server* server_create(int port) {
|
Server* server_create(int port) {
|
||||||
Server* server = (Server*)malloc(sizeof(Server));
|
Server* server = (Server*)malloc(sizeof(Server));
|
||||||
if (server == NULL) {
|
if (server == NULL) {
|
||||||
perror("Could not allocate space for Server");
|
log_perror("Could not allocate space for Server");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_descriptor = socket(AF_INET, SOCK_STREAM, 0);
|
int file_descriptor = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (file_descriptor < 0) {
|
if (file_descriptor < 0) {
|
||||||
perror("Could not create Socket!");
|
log_perror("Could not create Socket!");
|
||||||
free(server);
|
free(server);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
server->file_descriptor = file_descriptor;
|
server->file_descriptor = file_descriptor;
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
if (setsockopt(server->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
|
if (setsockopt(server->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
|
||||||
perror("Error setting a socket option!");
|
log_perror("Error setting a socket option!");
|
||||||
close(server->file_descriptor);
|
close(server->file_descriptor);
|
||||||
free(server);
|
free(server);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -59,7 +59,7 @@ Server* server_create(int port) {
|
|||||||
|
|
||||||
if (bind(server->file_descriptor, (struct sockaddr*)&server->address, server->address_length) <
|
if (bind(server->file_descriptor, (struct sockaddr*)&server->address, server->address_length) <
|
||||||
0) {
|
0) {
|
||||||
perror("Could not bind server");
|
log_perror("Could not bind server");
|
||||||
close(server->file_descriptor);
|
close(server->file_descriptor);
|
||||||
free(server);
|
free(server);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -83,7 +83,7 @@ void server_delete(Server** server) {
|
|||||||
static void accept_loop(Server* server, void (*child_fn)(int, void*), void* child_ctx,
|
static void accept_loop(Server* server, void (*child_fn)(int, void*), void* child_ctx,
|
||||||
const char* log_fmt) {
|
const char* log_fmt) {
|
||||||
if (listen(server->file_descriptor, SOMAXCONN) < 0) {
|
if (listen(server->file_descriptor, SOMAXCONN) < 0) {
|
||||||
perror("Could not listen on port!");
|
log_perror("Could not listen on port!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
signal(SIGCHLD, sigchld_handler);
|
signal(SIGCHLD, sigchld_handler);
|
||||||
@@ -92,7 +92,7 @@ static void accept_loop(Server* server, void (*child_fn)(int, void*), void* chil
|
|||||||
socklen_t client_len = sizeof(client_addr);
|
socklen_t client_len = sizeof(client_addr);
|
||||||
int fd = accept(server->file_descriptor, (struct sockaddr*)&client_addr, &client_len);
|
int fd = accept(server->file_descriptor, (struct sockaddr*)&client_addr, &client_len);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Could not accept the connection");
|
log_perror("Could not accept the connection");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tcp_apply_socket_timeout(fd);
|
tcp_apply_socket_timeout(fd);
|
||||||
@@ -222,7 +222,7 @@ bool tcp_connect_socket(Client* client, char* host, int port) {
|
|||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
perror("Could not connect to Server!");
|
log_perror("Could not connect to Server!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "array_list.h"
|
#include "array_list.h"
|
||||||
#include "libgen.h"
|
#include "libgen.h"
|
||||||
@@ -54,7 +55,7 @@ bool mkdir_r(const char* path) {
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(path_current, &st) != 0) {
|
if (stat(path_current, &st) != 0) {
|
||||||
if (mkdir(path_current, 0755) != 0) {
|
if (mkdir(path_current, 0755) != 0) {
|
||||||
perror("Could not create directory");
|
log_perror("Could not create directory");
|
||||||
ok = false;
|
ok = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user