Diff for /freem/src/shmmgr.c between versions 1.10 and 1.12

version 1.10, 2025/04/15 19:26:13 version 1.12, 2025/04/15 21:57:10
Line 24 Line 24
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
  *   $Log$   *   $Log$
    *   Revision 1.12  2025/04/15 21:57:10  snw
    *   Fix SysV IPC bugs on FreeBSD
    *
    *   Revision 1.11  2025/04/15 21:08:51  snw
    *   Add some useful debug output
    *
  *   Revision 1.10  2025/04/15 19:26:13  snw   *   Revision 1.10  2025/04/15 19:26:13  snw
  *   Remove extra whitespace   *   Remove extra whitespace
  *   *
Line 87  void shm_daemon_init(void); Line 93  void shm_daemon_init(void);
   
 shm_config_t *shm_config = (shm_config_t *) NULL;  shm_config_t *shm_config = (shm_config_t *) NULL;
   
   #if defined(__FreeBSD__)
   # define FM_SHM_PERMS 0660
   #else
   # define FM_SHM_PERMS 0770
   #endif
   
 short shm_init(const size_t seg_size)  short shm_init(const size_t seg_size)
 {  {
     size_t alloc_map_size;      size_t alloc_map_size;
Line 108  short shm_init(const size_t seg_size) Line 120  short shm_init(const size_t seg_size)
     shm_config->segsiz = seg_size + alloc_map_size + pg_size;      shm_config->segsiz = seg_size + alloc_map_size + pg_size;
     shm_config->key = ftok (config_file, 1);      shm_config->key = ftok (config_file, 1);
     shm_config->pgsiz = pg_size;      shm_config->pgsiz = pg_size;
              
     shm_config->seg_id = shmget (shm_config->key, shm_config->segsiz, 0770 | IPC_CREAT);      shm_config->seg_id = shmget (shm_config->key, shm_config->segsiz, FM_SHM_PERMS | IPC_CREAT);
     if (shm_config->seg_id == -1) {      if (shm_config->seg_id == -1) {
         if (errno == 22) {          if (errno == 22) {
             logprintf (FM_LOG_ERROR, "shm_init:  cannot get shared memory segment of %ld bytes", (unsigned long) shm_config->segsiz);              logprintf (FM_LOG_ERROR, "shm_init:  cannot get shared memory segment of %ld bytes", (unsigned long) shm_config->segsiz);
Line 172  short shm_init(const size_t seg_size) Line 184  short shm_init(const size_t seg_size)
                 /* grab the pointers we need */                  /* grab the pointers we need */
                 void *old_addr = shm_config->dta;                  void *old_addr = shm_config->dta;
                 void *new_addr = shm_config->hdr->shmad;                  void *new_addr = shm_config->hdr->shmad;
   
                   logprintf (FM_LOG_INFO, "shmmgr:  remapping shared memory from virtual address %p to %p", old_addr, new_addr);
                                   
                 /* detach and reattach */                  /* detach and reattach */
                 if (shmdt (old_addr) == -1) {                  if (shmdt (old_addr) == -1) {
                     logprintf (FM_LOG_FATAL, "shm_init:  detach failed during detach/reattach [shmdt error %s]", strerror (errno));                      logprintf (FM_LOG_FATAL, "shm_init:  detach failed during detach/reattach [shmdt error %s]", strerror (errno));
                 }                  }
   
 #if defined(__FreeBSD__)  
                 shm_config->dta = shmat (shm_config->seg_id, new_addr, SHM_REMAP);  
 #else                  
                 shm_config->dta = shmat (shm_config->seg_id, new_addr, 0);                  shm_config->dta = shmat (shm_config->seg_id, new_addr, 0);
 #endif  
   
                 if (shm_config->dta == (void *) -1) {                  if (shm_config->dta == (void *) -1) {
                     logprintf (FM_LOG_FATAL, "shm_init:  fatal error attaching shared memory segment [shmat error '%s']", strerror (errno));                      logprintf (FM_LOG_FATAL, "shm_init:  fatal error attaching shared memory segment [shmat error '%s']", strerror (errno));

Removed from v.1.10  
changed lines
  Added in v.1.12


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>