--- lbbs/src/file_loader.c 2025/11/19 03:29:00 1.23 +++ lbbs/src/file_loader.c 2025/11/19 13:35:38 1.24 @@ -82,15 +82,16 @@ int load_file(const char *filename) // Allocate shared memory size = sizeof(struct shm_header_t) + data_len + 1 + sizeof(long) * (size_t)(line_total + 1); - if (unload_file(filename) < 0) + strncpy(filepath, filename, sizeof(filepath) - 1); + filepath[sizeof(filepath) - 1] = '\0'; + snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); + + if (shm_unlink(shm_name) == -1 && errno != ENOENT) { + log_error("shm_unlink(%s) error (%d)\n", shm_name, errno); return -2; } - strncpy(filepath, filename, sizeof(filepath) - 1); - filepath[sizeof(filepath) - 1] = '\0'; - snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); - if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { log_error("shm_open(%s) error (%d)\n", shm_name, errno); @@ -155,7 +156,7 @@ int unload_file(const char *filename) strncpy(filepath, filename, sizeof(filepath) - 1); filepath[sizeof(filepath) - 1] = '\0'; - snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); + snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); if (shm_unlink(shm_name) == -1 && errno != ENOENT) { @@ -183,7 +184,7 @@ void *get_file_shm_readonly(const char * strncpy(filepath, filename, sizeof(filepath) - 1); filepath[sizeof(filepath) - 1] = '\0'; - snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath)); + snprintf(shm_name, sizeof(shm_name), "/FILE_SHM_%s", basename(filepath)); if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1) {