| 3 |
* test_file_loader |
* test_file_loader |
| 4 |
* - tester for shared memory based file loader |
* - tester for shared memory based file loader |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| 17 |
#include <stdio.h> |
#include <stdio.h> |
| 18 |
#include <string.h> |
#include <string.h> |
| 19 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <sys/shm.h> |
|
| 20 |
|
|
| 21 |
const char *files[] = { |
const char *files[] = { |
| 22 |
"../data/welcome.txt", |
"../data/welcome.txt", |
| 30 |
|
|
| 31 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
| 32 |
{ |
{ |
|
char file_path_temp[FILE_PATH_LEN]; |
|
| 33 |
int i; |
int i; |
| 34 |
void *p_shm; |
void *p_shm; |
| 35 |
size_t data_len; |
size_t data_len; |
| 37 |
const void *p_data; |
const void *p_data; |
| 38 |
const long *p_line_offsets; |
const long *p_line_offsets; |
| 39 |
|
|
|
// Change current dir |
|
|
strncpy(file_path_temp, argv[0], sizeof(file_path_temp) - 1); |
|
|
file_path_temp[sizeof(file_path_temp) - 1] = '\0'; |
|
|
|
|
|
if (chdir(dirname(file_path_temp)) < 0) |
|
|
{ |
|
|
fprintf(stderr, "chdir(%s) error: %d\n", dirname(file_path_temp), errno); |
|
|
return -1; |
|
|
} |
|
|
|
|
| 40 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
| 41 |
{ |
{ |
| 42 |
printf("Open log error\n"); |
printf("Open log error\n"); |
| 73 |
|
|
| 74 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 75 |
{ |
{ |
| 76 |
log_error("detach_file_shm(%s) error\n", files[i]); |
log_error("detach_file_shm(%s) error", files[i]); |
| 77 |
} |
} |
| 78 |
} |
} |
| 79 |
} |
} |
| 123 |
|
|
| 124 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 125 |
{ |
{ |
| 126 |
log_error("detach_file_shm(%s) error\n", files[i]); |
log_error("detach_file_shm(%s) error", files[i]); |
| 127 |
} |
} |
| 128 |
} |
} |
| 129 |
} |
} |