Diff for /freem/src/locktab.c between versions 1.3 and 1.7

version 1.3, 2025/03/09 15:20:18 version 1.7, 2025/05/01 21:02:31
Line 1 Line 1
 /*  /*
  *                            *   *   $Id$
  *                           * *  
  *                          *   *  
  *                     ***************  
  *                      * *       * *  
  *                       *  MUMPS  *  
  *                      * *       * *  
  *                     ***************  
  *                          *   *  
  *                           * *  
  *                            *  
  *  
  *   locktab.c  
  *    lock table implementation   *    lock table implementation
  *   *
  *     *  
  *   Author: Serena Willis <snw@coherent-logic.com>   *   Author: Serena Willis <snw@coherent-logic.com>
  *    Copyright (C) 1998 MUG Deutschland   *    Copyright (C) 1998 MUG Deutschland
  *    Copyright (C) 2021 Coherent Logic Development LLC   *    Copyright (C) 2021, 2025 Coherent Logic Development LLC
  *   *
  *   *
  *   This file is part of FreeM.   *   This file is part of FreeM.
Line 35 Line 23
  *   You should have received a copy of the GNU Affero Public License   *   You should have received a copy of the GNU Affero Public License
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
    *   $Log$
    *   Revision 1.7  2025/05/01 21:02:31  snw
    *   Documentation updates
    *
    *   Revision 1.6  2025/04/13 04:22:43  snw
    *   Fix snprintf calls
    *
    *   Revision 1.5  2025/03/24 02:57:25  snw
    *   Shared memory compatibility fixes for OS/2
    *
    *   Revision 1.4  2025/03/09 19:14:25  snw
    *   First phase of REUSE compliance and header reformat
    *
    *
    * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
    * SPDX-License-Identifier: AGPL-3.0-or-later
  **/   **/
   
 #include <stdio.h>  #include <stdio.h>
Line 48 Line 52
 #include "shmmgr.h"  #include "shmmgr.h"
 #include "mref.h"  #include "mref.h"
 #include "transact.h"  #include "transact.h"
   #include "log.h"
   
 #if !defined(__OpenBSD__) && !defined(__APPLE__)  #if !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__OS2__)
 union semun {  union semun {
     int              val;    /* Value for SETVAL */      int              val;    /* Value for SETVAL */
     struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */      struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
Line 109  short locktab_get_sem(void) Line 114  short locktab_get_sem(void)
         if (semop (semid_locktab, &s, 1) != -1) {          if (semop (semid_locktab, &s, 1) != -1) {
             return TRUE;              return TRUE;
         }          }
           printf ("jibjaw\r\n");
         sleep (1);          sleep (1);
   
     }      }
Line 236  void locktab_increment(char *key, long l Line 241  void locktab_increment(char *key, long l
                                   
             }              }
             else {              else {
                   int sigint_ct = 0;
                   
                 for (;;) {                  for (;;) {
                                           
                     if (locktab_insert (key) != NULL) {                      if (locktab_insert (key) != NULL) {
Line 243  void locktab_increment(char *key, long l Line 250  void locktab_increment(char *key, long l
                         return;                          return;
                     }                      }
                     else {                      else {
                           if (merr () == INRPT) {
                               sigint_ct++;
   
                               if (sigint_ct == 1) {
                                   printf ("\r\nlocktab_insert:  got Ctrl-C in blocking LOCK; Ctrl-C again to force the process to halt\r\n");
                                   merr_clear ();
                               }
                               else {
                                   printf ("\r\n");
                                   logprintf (FM_LOG_FATAL, "locktab_insert:  blocking LOCK was interrupted; forcing halt");
                               }
                           }
                         sleep (1);                          sleep (1);
                     }                      }
                                   
Line 408  void locktab_decrement(char *key, long l Line 427  void locktab_decrement(char *key, long l
   
 void locktab_unlock_all(void)  void locktab_unlock_all(void)
 {  {
       locktab_unlock_all_by_pid (pid);
   }
   
   void locktab_unlock_all_by_pid(const pid_t target_pid)
   {
     locktab_ent_t *lck;      locktab_ent_t *lck;
       int remove_ct;
   
       remove_ct = 0;
       if (target_pid != pid) {
           logprintf (FM_LOG_INFO, "locktab_unlock_all_by_pid:  removing all locks for pid %ld", target_pid);
       }
   
           
     for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {      for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {
   
         if (lck->owner_job == pid) {          if (lck->owner_job == target_pid) {
               remove_ct++;
               
             if (tp_level > lck->tp_level) {              if (tp_level > lck->tp_level) {
                 merr_raise (M41);                  merr_raise (M41);
                 return;                  return;
Line 427  void locktab_unlock_all(void) Line 459  void locktab_unlock_all(void)
                           
         }          }
   
     }             }
   
       if (target_pid != pid) {
           logprintf (FM_LOG_INFO, "locktab_unlock_all_by_pid:  removed %ld lock(s) for pid %ld", remove_ct, target_pid);
       }
   
           
 }  }
   
Line 438  locktab_ent_t *locktab_find(char *key) Line 475  locktab_ent_t *locktab_find(char *key)
     char chk_ns[255];      char chk_ns[255];
   
     if (key[1] == '%') {      if (key[1] == '%') {
         snprintf (chk_ns, 255, "SYSTEM");          snprintf (chk_ns, sizeof (chk_ns) - 1, "SYSTEM");
     }      }
     else {      else {
         snprintf (chk_ns, 255, "%s", nsname);          snprintf (chk_ns, sizeof (chk_ns) - 1, "%s", nsname);
     }      }
   
     for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {      for (lck = shm_config->hdr->locktab_head; lck != NULL; lck = lck->next) {
Line 482  locktab_ent_t *locktab_insert(char *key) Line 519  locktab_ent_t *locktab_insert(char *key)
     ik = internal_to_mref (ik, key);      ik = internal_to_mref (ik, key);
           
     if (key[1] == '%') {      if (key[1] == '%') {
         snprintf (chk_ns, 255, "SYSTEM");          snprintf (chk_ns, sizeof (chk_ns) - 1, "SYSTEM");
     }      }
     else {      else {
         snprintf (chk_ns, 255, "%s", nsname);          snprintf (chk_ns, sizeof (chk_ns) - 1, "%s", nsname);
     }      }
           
     for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {      for (l = shm_config->hdr->locktab_head; l != NULL; l = l->next) {
Line 537  new_insert: Line 574  new_insert:
     }      }
   
     stcpy (l->nref, key);      stcpy (l->nref, key);
     snprintf (l->namespace, 255, "%s", chk_ns);      snprintf (l->namespace, sizeof (l->namespace) - 1, "%s", chk_ns);
                   
     l->owner_job = pid;      l->owner_job = pid;
     l->ct = 1;      l->ct = 1;

Removed from v.1.3  
changed lines
  Added in v.1.7


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