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

version 1.12, 2025/04/15 21:57:10 version 1.13, 2025/04/16 17:36:12
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.13  2025/04/16 17:36:12  snw
    *   Add FreeBSD shm cleanup script
    *
  *   Revision 1.12  2025/04/15 21:57:10  snw   *   Revision 1.12  2025/04/15 21:57:10  snw
  *   Fix SysV IPC bugs on FreeBSD   *   Fix SysV IPC bugs on FreeBSD
  *   *
Line 94  void shm_daemon_init(void); Line 97  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__)  #if defined(__FreeBSD__)
 # define FM_SHM_PERMS 0660  # define FM_SHM_PERMS 0777
 #else  #else
 # define FM_SHM_PERMS 0770  # define FM_SHM_PERMS 0770
 #endif  #endif
Line 104  short shm_init(const size_t seg_size) Line 107  short shm_init(const size_t seg_size)
     size_t alloc_map_size;      size_t alloc_map_size;
     long pg_size;      long pg_size;
     key_t shm_sk;      key_t shm_sk;
       
   #if defined(__FreeBSD__)
       struct shmid_ds ctl;
   #endif
       
     shm_sk = ftok (config_file, 5);          shm_sk = ftok (config_file, 5);    
     pg_size = sysconf (_SC_PAGESIZE);      pg_size = sysconf (_SC_PAGESIZE);
           
Line 137  short shm_init(const size_t seg_size) Line 144  short shm_init(const size_t seg_size)
 #endif  #endif
           
     if (shm_config->dta == (void *) -1) {           if (shm_config->dta == (void *) -1) {     
         return SHMS_ATTACH_ERR;          logprintf (FM_LOG_FATAL, "shm_init:  shmat() failed (error code %d [%s])", errno, strerror (errno));
     }      }
     /* view the first sizeof (shm_hdr_t) bytes of the data area as an shm_hdr_t */      /* view the first sizeof (shm_hdr_t) bytes of the data area as an shm_hdr_t */
     shm_config->hdr = (shm_hdr_t *) shm_config->dta;      shm_config->hdr = (shm_hdr_t *) shm_config->dta;
Line 192  short shm_init(const size_t seg_size) Line 199  short shm_init(const size_t seg_size)
                     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));
                 }                  }
   
                 shm_config->dta = shmat (shm_config->seg_id, new_addr, 0);                  if ((shm_config->dta = shmat (shm_config->seg_id, new_addr, 0)) == -1) {
                       switch (errno) {
   
                 if (shm_config->dta == (void *) -1) {                          case EINVAL:
                     logprintf (FM_LOG_FATAL, "shm_init:  fatal error attaching shared memory segment [shmat error '%s']", strerror (errno));                              logprintf (FM_LOG_FATAL, "shm_init:  shmat() failed; no matching shared memory segment exists or shared memory address invalid");
                               break;
   
                           case ENOMEM:
                               logprintf (FM_LOG_ERROR, "shm_init:  shmat() failed; specified address cannot be used for mapping");
                               exit (1);
                               break;
   
                           case EMFILE:
                               logprintf (FM_LOG_FATAL, "shm_init:  shmat() failed; per-process shared memory segment limit reached; check kernel tuning parameters");
                               break;
   
                           default:
                               logprintf (FM_LOG_FATAL, "shm_init:  shmat() failed; error code %d [%s]", errno, strerror (errno));
                               break;
                               
                       }
                 }                  }
                                   
                 shm_config->hdr = (shm_hdr_t *) shm_config->dta;                  shm_config->hdr = (shm_hdr_t *) shm_config->dta;

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


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