/[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.22 by sysadm, Wed Nov 19 03:12:58 2025 UTC Revision 1.24 by sysadm, Wed Nov 19 13:35:38 2025 UTC
# Line 32  struct shm_header_t Line 32  struct shm_header_t
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;
# Line 81  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    
95          strncpy(filepath, filename, sizeof(filepath) - 1);          if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)
         filepath[sizeof(filepath) - 1] = '\0';  
   
         if ((fd = shm_open(basename(filepath), O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)  
96          {          {
97                  log_error("shm_open(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_open(%s) error (%d)\n", shm_name, errno);
98                  return -2;                  return -2;
99          }          }
100          if (ftruncate(fd, (off_t)size) == -1)          if (ftruncate(fd, (off_t)size) == -1)
# Line 143  int load_file(const char *filename) Line 146  int load_file(const char *filename)
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];
150    
151          if (filename == NULL)          if (filename == NULL)
152          {          {
# Line 152  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), "/FILE_SHM_%s", basename(filepath));
160    
161          if (shm_unlink(basename(filepath)) == -1 && errno != ENOENT)          if (shm_unlink(shm_name) == -1 && errno != ENOENT)
162          {          {
163                  log_error("shm_unlink(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_unlink(%s) error (%d)\n", shm_name, errno);
164                  return -2;                  return -2;
165          }          }
166    
# Line 165  int unload_file(const char *filename) Line 170  int unload_file(const char *filename)
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];
174          int fd;          int fd;
175          void *p_shm = NULL;          void *p_shm = NULL;
176          struct stat sb;          struct stat sb;
# Line 178  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), "/FILE_SHM_%s", basename(filepath));
188    
189          if ((fd = shm_open(basename(filepath), O_RDONLY, 0600)) == -1)          if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1)
190          {          {
191                  log_error("shm_open(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_open(%s) error (%d)\n", shm_name, errno);
192                  return NULL;                  return NULL;
193          }          }
194    


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

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