| 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]; |
| 36 |
int fd; |
int fd; |
| 37 |
struct stat sb; |
struct stat sb; |
| 38 |
void *p_data; |
void *p_data; |
| 89 |
|
|
| 90 |
strncpy(filepath, filename, sizeof(filepath) - 1); |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 91 |
filepath[sizeof(filepath) - 1] = '\0'; |
filepath[sizeof(filepath) - 1] = '\0'; |
| 92 |
|
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
| 93 |
|
|
| 94 |
if ((fd = shm_open(basename(filepath), O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) |
if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) |
| 95 |
{ |
{ |
| 96 |
log_error("shm_open(%s) error (%d)\n", basename(filepath), errno); |
log_error("shm_open(%s) error (%d)\n", shm_name, errno); |
| 97 |
return -2; |
return -2; |
| 98 |
} |
} |
| 99 |
if (ftruncate(fd, (off_t)size) == -1) |
if (ftruncate(fd, (off_t)size) == -1) |
| 145 |
int unload_file(const char *filename) |
int unload_file(const char *filename) |
| 146 |
{ |
{ |
| 147 |
char filepath[FILE_PATH_LEN]; |
char filepath[FILE_PATH_LEN]; |
| 148 |
|
char shm_name[FILE_PATH_LEN]; |
| 149 |
|
|
| 150 |
if (filename == NULL) |
if (filename == NULL) |
| 151 |
{ |
{ |
| 155 |
|
|
| 156 |
strncpy(filepath, filename, sizeof(filepath) - 1); |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 157 |
filepath[sizeof(filepath) - 1] = '\0'; |
filepath[sizeof(filepath) - 1] = '\0'; |
| 158 |
|
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
| 159 |
|
|
| 160 |
if (shm_unlink(basename(filepath)) == -1 && errno != ENOENT) |
if (shm_unlink(shm_name) == -1 && errno != ENOENT) |
| 161 |
{ |
{ |
| 162 |
log_error("shm_unlink(%s) error (%d)\n", basename(filepath), errno); |
log_error("shm_unlink(%s) error (%d)\n", shm_name, errno); |
| 163 |
return -2; |
return -2; |
| 164 |
} |
} |
| 165 |
|
|
| 169 |
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) |
| 170 |
{ |
{ |
| 171 |
char filepath[FILE_PATH_LEN]; |
char filepath[FILE_PATH_LEN]; |
| 172 |
|
char shm_name[FILE_PATH_LEN]; |
| 173 |
int fd; |
int fd; |
| 174 |
void *p_shm = NULL; |
void *p_shm = NULL; |
| 175 |
struct stat sb; |
struct stat sb; |
| 183 |
|
|
| 184 |
strncpy(filepath, filename, sizeof(filepath) - 1); |
strncpy(filepath, filename, sizeof(filepath) - 1); |
| 185 |
filepath[sizeof(filepath) - 1] = '\0'; |
filepath[sizeof(filepath) - 1] = '\0'; |
| 186 |
|
snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); |
| 187 |
|
|
| 188 |
if ((fd = shm_open(basename(filepath), O_RDONLY, 0600)) == -1) |
if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1) |
| 189 |
{ |
{ |
| 190 |
log_error("shm_open(%s) error (%d)\n", basename(filepath), errno); |
log_error("shm_open(%s) error (%d)\n", shm_name, errno); |
| 191 |
return NULL; |
return NULL; |
| 192 |
} |
} |
| 193 |
|
|