Print this page
5910 libnisdb won't build with modern GCC


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*

  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 /*
  30  * DESCRIPTION: Contains code supporting the 'update in progress' flag. This is
  31  *              a near copy of lock flag code (in
  32  *              usr/src/cmd/ypcmd/shared/lockmp.c) If we implement a clean
  33  *              version of the locking code this file will probably disappear.
  34  *
  35  *              These locks are held while a map is being updated from the
  36  *              DIT. They prevent a second update being started while this is
  37  *              in progress. This is independant from the `lockmap` mechanism
  38  *              which protects maps, generally for a much shorter period,
  39  *              while their control structures are modified.
  40  */
  41 
  42 #include <unistd.h>
  43 #include <syslog.h>
  44 #include <sys/mman.h>
  45 #include <thread.h>
  46 #include <synch.h>
  47 #include <ndbm.h>
  48 #include <strings.h>


  59 
  60 /*
  61  * Cross-process robust mutex locks.
  62  * Provide synchronization between YP processes
  63  * by implementing an exclusive locking mechanism
  64  * via a memory-mapped file.
  65  */
  66 static struct updatearray       *shmupdatearray;
  67 static int      lockfile;
  68 
  69 bool_t
  70 init_update_locks_mem()
  71 {
  72         int iiter, rc;
  73         int ebusy_cnt = 0;
  74 
  75         /*
  76          * Initialize cross-process locks in memory-mapped file.
  77          */
  78         for (iiter = 0; iiter < MAXHASH; iiter++) {
  79                 if (rc = mutex_init(&(shmupdatearray->updatenode[iiter]),
  80                     USYNC_PROCESS | LOCK_ROBUST, 0)) {
  81                         if (rc == EBUSY) {
  82                                 ebusy_cnt++;
  83                         } else {
  84                                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
  85                                         "init_update_locks_mem():mutex_init():"
  86                                         "error=%d", rc);
  87                                 return (FALSE);
  88                         }
  89                 }
  90         }
  91 
  92         /*
  93          * EBUSY for all locks OK, it means another process
  94          * has already initialized locks.
  95          */
  96         if ((ebusy_cnt > 0) && (ebusy_cnt != MAXHASH)) {
  97                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
  98                 "%s inconsistent. Remove this file and restart NIS (YP)",
  99                                                                 LOCKFILE);
 100                 return (FALSE);




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2015 Gary Mills
  24  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 


  28 /*
  29  * DESCRIPTION: Contains code supporting the 'update in progress' flag. This is
  30  *              a near copy of lock flag code (in
  31  *              usr/src/cmd/ypcmd/shared/lockmp.c) If we implement a clean
  32  *              version of the locking code this file will probably disappear.
  33  *
  34  *              These locks are held while a map is being updated from the
  35  *              DIT. They prevent a second update being started while this is
  36  *              in progress. This is independant from the `lockmap` mechanism
  37  *              which protects maps, generally for a much shorter period,
  38  *              while their control structures are modified.
  39  */
  40 
  41 #include <unistd.h>
  42 #include <syslog.h>
  43 #include <sys/mman.h>
  44 #include <thread.h>
  45 #include <synch.h>
  46 #include <ndbm.h>
  47 #include <strings.h>


  58 
  59 /*
  60  * Cross-process robust mutex locks.
  61  * Provide synchronization between YP processes
  62  * by implementing an exclusive locking mechanism
  63  * via a memory-mapped file.
  64  */
  65 static struct updatearray       *shmupdatearray;
  66 static int      lockfile;
  67 
  68 bool_t
  69 init_update_locks_mem()
  70 {
  71         int iiter, rc;
  72         int ebusy_cnt = 0;
  73 
  74         /*
  75          * Initialize cross-process locks in memory-mapped file.
  76          */
  77         for (iiter = 0; iiter < MAXHASH; iiter++) {
  78                 if ((rc = mutex_init(&(shmupdatearray->updatenode[iiter]),
  79                     USYNC_PROCESS | LOCK_ROBUST, 0)) != 0) {
  80                         if (rc == EBUSY) {
  81                                 ebusy_cnt++;
  82                         } else {
  83                                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
  84                                         "init_update_locks_mem():mutex_init():"
  85                                         "error=%d", rc);
  86                                 return (FALSE);
  87                         }
  88                 }
  89         }
  90 
  91         /*
  92          * EBUSY for all locks OK, it means another process
  93          * has already initialized locks.
  94          */
  95         if ((ebusy_cnt > 0) && (ebusy_cnt != MAXHASH)) {
  96                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
  97                 "%s inconsistent. Remove this file and restart NIS (YP)",
  98                                                                 LOCKFILE);
  99                 return (FALSE);