/[LeafOK_CVS]/lbbs/src/file_loader.c
ViewVC logotype

Diff of /lbbs/src/file_loader.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.23 by sysadm, Wed Nov 19 03:29:00 2025 UTC Revision 1.24 by sysadm, Wed Nov 19 13:35:38 2025 UTC
# Line 82  int load_file(const char *filename) Line 82  int load_file(const char *filename)
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);
# Line 155  int unload_file(const char *filename) Line 156  int unload_file(const char *filename)
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          {          {
# Line 183  void *get_file_shm_readonly(const char * Line 184  void *get_file_shm_readonly(const char *
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          {          {


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1