| 32 |
int load_file(const char *filename) |
int load_file(const char *filename) |
| 33 |
{ |
{ |
| 34 |
char filepath[FILE_PATH_LEN]; |
char filepath[FILE_PATH_LEN]; |
| 35 |
char shm_name[FILE_PATH_LEN]; |
char shm_name[FILE_NAME_LEN]; |
| 36 |
int fd; |
int fd; |
| 37 |
struct stat sb; |
struct stat sb; |
| 38 |
void *p_data; |
void *p_data; |
| 82 |
// Allocate shared memory |
// Allocate shared memory |
| 83 |
size = sizeof(struct shm_header_t) + data_len + 1 + sizeof(long) * (size_t)(line_total + 1); |
size = sizeof(struct shm_header_t) + data_len + 1 + sizeof(long) * (size_t)(line_total + 1); |
| 84 |
|
|
| 85 |
if (unload_file(filename) < 0) |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 86 |
|
filepath[sizeof(filepath) - 1] = '\0'; |
| 87 |
|
snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); |
| 88 |
|
|
| 89 |
|
if (shm_unlink(shm_name) == -1 && errno != ENOENT) |
| 90 |
{ |
{ |
| 91 |
|
log_error("shm_unlink(%s) error (%d)\n", shm_name, errno); |
| 92 |
return -2; |
return -2; |
| 93 |
} |
} |
| 94 |
|
|
|
strncpy(filepath, filename, sizeof(filepath) - 1); |
|
|
filepath[sizeof(filepath) - 1] = '\0'; |
|
|
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
|
|
|
|
| 95 |
if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) |
if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) |
| 96 |
{ |
{ |
| 97 |
log_error("shm_open(%s) error (%d)\n", shm_name, errno); |
log_error("shm_open(%s) error (%d)\n", shm_name, errno); |
| 146 |
int unload_file(const char *filename) |
int unload_file(const char *filename) |
| 147 |
{ |
{ |
| 148 |
char filepath[FILE_PATH_LEN]; |
char filepath[FILE_PATH_LEN]; |
| 149 |
char shm_name[FILE_PATH_LEN]; |
char shm_name[FILE_NAME_LEN]; |
| 150 |
|
|
| 151 |
if (filename == NULL) |
if (filename == NULL) |
| 152 |
{ |
{ |
| 156 |
|
|
| 157 |
strncpy(filepath, filename, sizeof(filepath) - 1); |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 158 |
filepath[sizeof(filepath) - 1] = '\0'; |
filepath[sizeof(filepath) - 1] = '\0'; |
| 159 |
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); |
| 160 |
|
|
| 161 |
if (shm_unlink(shm_name) == -1 && errno != ENOENT) |
if (shm_unlink(shm_name) == -1 && errno != ENOENT) |
| 162 |
{ |
{ |
| 170 |
void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_line_total, const void **pp_data, const long **pp_line_offsets) |
void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_line_total, const void **pp_data, const long **pp_line_offsets) |
| 171 |
{ |
{ |
| 172 |
char filepath[FILE_PATH_LEN]; |
char filepath[FILE_PATH_LEN]; |
| 173 |
char shm_name[FILE_PATH_LEN]; |
char shm_name[FILE_NAME_LEN]; |
| 174 |
int fd; |
int fd; |
| 175 |
void *p_shm = NULL; |
void *p_shm = NULL; |
| 176 |
struct stat sb; |
struct stat sb; |
| 184 |
|
|
| 185 |
strncpy(filepath, filename, sizeof(filepath) - 1); |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 186 |
filepath[sizeof(filepath) - 1] = '\0'; |
filepath[sizeof(filepath) - 1] = '\0'; |
| 187 |
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); |
| 188 |
|
|
| 189 |
if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1) |
if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1) |
| 190 |
{ |
{ |