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

Diff of /lbbs/src/trie_dict.c

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

Revision 1.23 by sysadm, Thu Nov 20 03:22:35 2025 UTC Revision 1.24 by sysadm, Sat Nov 22 01:56:59 2025 UTC
# Line 134  void trie_dict_cleanup(void) Line 134  void trie_dict_cleanup(void)
134          trie_node_shm_name[0] = '\0';          trie_node_shm_name[0] = '\0';
135  }  }
136    
 int get_trie_dict_shm_readonly(void)  
 {  
         int fd;  
         struct stat sb;  
         size_t size;  
         void *p_shm;  
   
         if ((fd = shm_open(trie_node_shm_name, O_RDONLY, 0600)) == -1)  
         {  
                 log_error("shm_open(%s) error (%d)\n", trie_node_shm_name, errno);  
                 return -2;  
         }  
   
         if (fstat(fd, &sb) < 0)  
         {  
                 log_error("fstat(fd) error (%d)\n", errno);  
                 close(fd);  
                 return -2;  
         }  
   
         size = (size_t)sb.st_size;  
   
         p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L);  
         if (p_shm == MAP_FAILED)  
         {  
                 log_error("mmap() error (%d)\n", errno);  
                 close(fd);  
                 return -2;  
         }  
   
         if (close(fd) < 0)  
         {  
                 log_error("close(fd) error (%d)\n", errno);  
                 return -1;  
         }  
   
         if (p_trie_node_pool->shm_size != size)  
         {  
                 log_error("Shared memory size mismatch (%ld != %ld)\n", p_trie_node_pool->shm_size, size);  
                 munmap(p_shm, size);  
                 return -3;  
         }  
   
         p_trie_node_pool = p_shm;  
   
         return 0;  
 }  
   
137  int set_trie_dict_shm_readonly(void)  int set_trie_dict_shm_readonly(void)
138  {  {
139          if (p_trie_node_pool != NULL && mprotect(p_trie_node_pool, p_trie_node_pool->shm_size, PROT_READ) < 0)          if (p_trie_node_pool != NULL && mprotect(p_trie_node_pool, p_trie_node_pool->shm_size, PROT_READ) < 0)


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

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