1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <unistd.h> 30*7c478bd9Sstevel@tonic-gate #include <syslog.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/mman.h> 32*7c478bd9Sstevel@tonic-gate #include <thread.h> 33*7c478bd9Sstevel@tonic-gate #include <synch.h> 34*7c478bd9Sstevel@tonic-gate #include <ndbm.h> 35*7c478bd9Sstevel@tonic-gate #include "../ypsym.h" 36*7c478bd9Sstevel@tonic-gate #include "../ypdefs.h" 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate /* 39*7c478bd9Sstevel@tonic-gate * These routines provide mutual exclusion between ypserv and ypxfr. 40*7c478bd9Sstevel@tonic-gate * Mutual exclusion is needed so that ypxfr doesn't try to rename 41*7c478bd9Sstevel@tonic-gate * dbm files while ypserv is trying to open them. After ypserv has 42*7c478bd9Sstevel@tonic-gate * opened a dbm file, it is safe to rename it because ypserv still 43*7c478bd9Sstevel@tonic-gate * has access to the file through its file descriptor. 44*7c478bd9Sstevel@tonic-gate */ 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #define LOCKFILE "/var/run/yp_maplock" 47*7c478bd9Sstevel@tonic-gate struct lockarray { 48*7c478bd9Sstevel@tonic-gate mutex_t locknode[MAXHASH]; 49*7c478bd9Sstevel@tonic-gate }; 50*7c478bd9Sstevel@tonic-gate typedef struct lockarray lockarray; 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * Cross-process robust mutex locks. 54*7c478bd9Sstevel@tonic-gate * Provide synchronization between YP processes 55*7c478bd9Sstevel@tonic-gate * by implementing an exclusive locking mechanism 56*7c478bd9Sstevel@tonic-gate * via a memory-mapped file. 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate static struct lockarray *shmlockarray; 59*7c478bd9Sstevel@tonic-gate static int lockfile; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate int 62*7c478bd9Sstevel@tonic-gate hash(char *s) 63*7c478bd9Sstevel@tonic-gate { 64*7c478bd9Sstevel@tonic-gate int n = 0; 65*7c478bd9Sstevel@tonic-gate int i; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate for (i = 1; *s; i += 10, s++) { 68*7c478bd9Sstevel@tonic-gate n += i * (*s); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate n %= MAXHASH; 71*7c478bd9Sstevel@tonic-gate return (n); 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate bool 75*7c478bd9Sstevel@tonic-gate init_locks_mem() 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate int iiter, rc; 78*7c478bd9Sstevel@tonic-gate int ebusy_cnt = 0; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* 81*7c478bd9Sstevel@tonic-gate * Initialize cross-process locks in memory-mapped file. 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate for (iiter = 0; iiter < MAXHASH; iiter++) { 84*7c478bd9Sstevel@tonic-gate if (rc = mutex_init(&(shmlockarray->locknode[iiter]), 85*7c478bd9Sstevel@tonic-gate USYNC_PROCESS_ROBUST, 0)) { 86*7c478bd9Sstevel@tonic-gate if (rc == EBUSY) { 87*7c478bd9Sstevel@tonic-gate ebusy_cnt++; 88*7c478bd9Sstevel@tonic-gate } else { 89*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 90*7c478bd9Sstevel@tonic-gate "init_locks_mem():mutex_init():error=%d", 91*7c478bd9Sstevel@tonic-gate rc); 92*7c478bd9Sstevel@tonic-gate return (FALSE); 93*7c478bd9Sstevel@tonic-gate } 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * EBUSY for all locks OK, it means another process 99*7c478bd9Sstevel@tonic-gate * has already initialized locks. 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate if ((ebusy_cnt > 0) && (ebusy_cnt != MAXHASH)) { 102*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 103*7c478bd9Sstevel@tonic-gate "%s inconsistent. Remove and restart NIS (YP).", LOCKFILE); 104*7c478bd9Sstevel@tonic-gate return (FALSE); 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate return (TRUE); 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate bool 110*7c478bd9Sstevel@tonic-gate init_lock_map() 111*7c478bd9Sstevel@tonic-gate { 112*7c478bd9Sstevel@tonic-gate char buff[ sizeof (lockarray) ]; 113*7c478bd9Sstevel@tonic-gate int write_cnt, lf_size; 114*7c478bd9Sstevel@tonic-gate struct stat fdata; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /* 117*7c478bd9Sstevel@tonic-gate * Locking file initialization algorithm, with recovery mechanism. 118*7c478bd9Sstevel@tonic-gate * This mechanism has been devised to ensure proper creation 119*7c478bd9Sstevel@tonic-gate * of a memory-mapped lock file containing mutexes for robust, 120*7c478bd9Sstevel@tonic-gate * inter-process communication. 121*7c478bd9Sstevel@tonic-gate * File name is /var/run/yp_maplock (LOCKFILE). It might or might 122*7c478bd9Sstevel@tonic-gate * not exist. 123*7c478bd9Sstevel@tonic-gate * 124*7c478bd9Sstevel@tonic-gate * Algorithm: 125*7c478bd9Sstevel@tonic-gate * Try to open the file. If file doesn't exist, or size is too small, 126*7c478bd9Sstevel@tonic-gate * create/rewrite the file, m-map it into memory and initialize the 127*7c478bd9Sstevel@tonic-gate * mutexes in it. 128*7c478bd9Sstevel@tonic-gate * If file exists and size is at least large enough, assume it's a 129*7c478bd9Sstevel@tonic-gate * good file, and m-map the lock structure directly to it. 130*7c478bd9Sstevel@tonic-gate * 131*7c478bd9Sstevel@tonic-gate * Recovery from inconsistent state is easy - simply delete the file 132*7c478bd9Sstevel@tonic-gate * and restart NIS (YP). 133*7c478bd9Sstevel@tonic-gate */ 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate lockfile = open(LOCKFILE, O_RDWR|O_CREAT, 0600); 136*7c478bd9Sstevel@tonic-gate if (lockfile != -1) { 137*7c478bd9Sstevel@tonic-gate if (lockf(lockfile, F_LOCK, 0) == 0) { 138*7c478bd9Sstevel@tonic-gate if (fstat(lockfile, &fdata) == 0) { 139*7c478bd9Sstevel@tonic-gate lf_size = fdata.st_size; 140*7c478bd9Sstevel@tonic-gate if (lf_size < sizeof (lockarray)) { 141*7c478bd9Sstevel@tonic-gate bzero(buff, sizeof (buff)); 142*7c478bd9Sstevel@tonic-gate if ((write_cnt = write(lockfile, buff, 143*7c478bd9Sstevel@tonic-gate sizeof (buff)) != sizeof (buff))) { 144*7c478bd9Sstevel@tonic-gate if (write_cnt < 0) { 145*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 146*7c478bd9Sstevel@tonic-gate "write(%s) => errno=%d", 147*7c478bd9Sstevel@tonic-gate LOCKFILE, errno); 148*7c478bd9Sstevel@tonic-gate } else { 149*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 150*7c478bd9Sstevel@tonic-gate "write(%s) => %d!=%d: wrong number of bytes written.", 151*7c478bd9Sstevel@tonic-gate LOCKFILE, 152*7c478bd9Sstevel@tonic-gate write_cnt, 153*7c478bd9Sstevel@tonic-gate sizeof (buff)); 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0); 156*7c478bd9Sstevel@tonic-gate close(lockfile); 157*7c478bd9Sstevel@tonic-gate return (FALSE); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate } else { 161*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 162*7c478bd9Sstevel@tonic-gate "fstat(%s) => errno=%d", LOCKFILE, errno); 163*7c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0); 164*7c478bd9Sstevel@tonic-gate close(lockfile); 165*7c478bd9Sstevel@tonic-gate return (FALSE); 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate } else { 168*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 169*7c478bd9Sstevel@tonic-gate "lockf(%s,F_LOCK) => errno=%d", LOCKFILE, errno); 170*7c478bd9Sstevel@tonic-gate close(lockfile); 171*7c478bd9Sstevel@tonic-gate return (FALSE); 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate } else { 174*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 175*7c478bd9Sstevel@tonic-gate "open(%s) => errno=%d", LOCKFILE, errno); 176*7c478bd9Sstevel@tonic-gate return (FALSE); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * File exists with correct size, is open, and we're holding 181*7c478bd9Sstevel@tonic-gate * the file lock. 182*7c478bd9Sstevel@tonic-gate */ 183*7c478bd9Sstevel@tonic-gate shmlockarray = (lockarray *)mmap((caddr_t) 0, sizeof (lockarray), 184*7c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE, MAP_SHARED, lockfile, 0); 185*7c478bd9Sstevel@tonic-gate if (shmlockarray == MAP_FAILED) { 186*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "mmap(%s) => errno=%d", LOCKFILE, errno); 187*7c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0); 188*7c478bd9Sstevel@tonic-gate close(lockfile); 189*7c478bd9Sstevel@tonic-gate return (FALSE); 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate /* 193*7c478bd9Sstevel@tonic-gate * If we wrote zeroes to the file, we also need to initialize 194*7c478bd9Sstevel@tonic-gate * the mutex locks. 195*7c478bd9Sstevel@tonic-gate */ 196*7c478bd9Sstevel@tonic-gate if (lf_size < sizeof (lockarray)) { 197*7c478bd9Sstevel@tonic-gate if (init_locks_mem() == FALSE) { 198*7c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0); 199*7c478bd9Sstevel@tonic-gate close(lockfile); 200*7c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) { 201*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 202*7c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.", 203*7c478bd9Sstevel@tonic-gate LOCKFILE, errno); 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate return (FALSE); 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate if (lockf(lockfile, F_ULOCK, 0) != 0) { 210*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 211*7c478bd9Sstevel@tonic-gate "lockf(%s,F_ULOCK) => errno=%d", 212*7c478bd9Sstevel@tonic-gate LOCKFILE, errno); 213*7c478bd9Sstevel@tonic-gate close(lockfile); 214*7c478bd9Sstevel@tonic-gate return (FALSE); 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate if (close(lockfile) == 0) { 218*7c478bd9Sstevel@tonic-gate return (TRUE); 219*7c478bd9Sstevel@tonic-gate } else { 220*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 221*7c478bd9Sstevel@tonic-gate "close(%s) => errno=%d", LOCKFILE, errno); 222*7c478bd9Sstevel@tonic-gate return (FALSE); 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate /* 227*7c478bd9Sstevel@tonic-gate * FUNCTION : lock_map() 228*7c478bd9Sstevel@tonic-gate * 229*7c478bd9Sstevel@tonic-gate * DESCRIPTION: Front end to the lock routine taking map name as argument. 230*7c478bd9Sstevel@tonic-gate * 231*7c478bd9Sstevel@tonic-gate * GIVEN : Map name. 232*7c478bd9Sstevel@tonic-gate * 233*7c478bd9Sstevel@tonic-gate * RETURNS : Same as lock_core 234*7c478bd9Sstevel@tonic-gate */ 235*7c478bd9Sstevel@tonic-gate int 236*7c478bd9Sstevel@tonic-gate lock_map(char *mapname) 237*7c478bd9Sstevel@tonic-gate { 238*7c478bd9Sstevel@tonic-gate int hashval; 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate hashval = hash(mapname); 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate return( lock_core(hashval)); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate /* 246*7c478bd9Sstevel@tonic-gate * FUNCTION : lock_core() 247*7c478bd9Sstevel@tonic-gate * 248*7c478bd9Sstevel@tonic-gate * DESCRIPTION: The core map locking function 249*7c478bd9Sstevel@tonic-gate * 250*7c478bd9Sstevel@tonic-gate * GIVEN : Map hash value 251*7c478bd9Sstevel@tonic-gate * 252*7c478bd9Sstevel@tonic-gate * RETURNS : 0 = Failure 253*7c478bd9Sstevel@tonic-gate * 1 = Success 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate int 256*7c478bd9Sstevel@tonic-gate lock_core(int hashval) 257*7c478bd9Sstevel@tonic-gate { 258*7c478bd9Sstevel@tonic-gate int rc; 259*7c478bd9Sstevel@tonic-gate 260*7c478bd9Sstevel@tonic-gate /* 261*7c478bd9Sstevel@tonic-gate *Robust, cross-process lock implementation 262*7c478bd9Sstevel@tonic-gate */ 263*7c478bd9Sstevel@tonic-gate rc = mutex_lock(&(shmlockarray->locknode[hashval])); 264*7c478bd9Sstevel@tonic-gate while (rc != 0) { 265*7c478bd9Sstevel@tonic-gate switch (rc) { 266*7c478bd9Sstevel@tonic-gate case EOWNERDEAD: 267*7c478bd9Sstevel@tonic-gate /* 268*7c478bd9Sstevel@tonic-gate * Previows lock owner died, resetting lock 269*7c478bd9Sstevel@tonic-gate * to recover from error. 270*7c478bd9Sstevel@tonic-gate */ 271*7c478bd9Sstevel@tonic-gate rc = mutex_init(&(shmlockarray->locknode[hashval]), 272*7c478bd9Sstevel@tonic-gate USYNC_PROCESS_ROBUST, 0); 273*7c478bd9Sstevel@tonic-gate if (rc != 0) { 274*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 275*7c478bd9Sstevel@tonic-gate "mutex_init(): error=%d", rc); 276*7c478bd9Sstevel@tonic-gate return (0); 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate rc = mutex_unlock(&(shmlockarray->locknode[hashval])); 279*7c478bd9Sstevel@tonic-gate if (rc != 0) { 280*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 281*7c478bd9Sstevel@tonic-gate "mutex_unlock(): error=%d", rc); 282*7c478bd9Sstevel@tonic-gate return (0); 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate break; 285*7c478bd9Sstevel@tonic-gate default: 286*7c478bd9Sstevel@tonic-gate /* 287*7c478bd9Sstevel@tonic-gate * Unrecoverable problem - nothing to do 288*7c478bd9Sstevel@tonic-gate * but exit YP and delete lock file. 289*7c478bd9Sstevel@tonic-gate */ 290*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 291*7c478bd9Sstevel@tonic-gate "mutex_lock(): error=%d", rc); 292*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 293*7c478bd9Sstevel@tonic-gate "Please restart NIS (ypstop/ypstart)."); 294*7c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) { 295*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 296*7c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.", 297*7c478bd9Sstevel@tonic-gate LOCKFILE, errno); 298*7c478bd9Sstevel@tonic-gate } 299*7c478bd9Sstevel@tonic-gate return (0); 300*7c478bd9Sstevel@tonic-gate } 301*7c478bd9Sstevel@tonic-gate rc = mutex_lock(&(shmlockarray->locknode[hashval])); 302*7c478bd9Sstevel@tonic-gate } 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate /* Success */ 305*7c478bd9Sstevel@tonic-gate return (1); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate /* 310*7c478bd9Sstevel@tonic-gate * FUNCTION : unlock_map() 311*7c478bd9Sstevel@tonic-gate * 312*7c478bd9Sstevel@tonic-gate * DESCRIPTION: Front end to the unlock routine taking map name as argument. 313*7c478bd9Sstevel@tonic-gate * 314*7c478bd9Sstevel@tonic-gate * GIVEN : Map name. 315*7c478bd9Sstevel@tonic-gate * 316*7c478bd9Sstevel@tonic-gate * RETURNS : Same as unlock_core 317*7c478bd9Sstevel@tonic-gate */ 318*7c478bd9Sstevel@tonic-gate int 319*7c478bd9Sstevel@tonic-gate unlock_map(char *mapname) 320*7c478bd9Sstevel@tonic-gate { 321*7c478bd9Sstevel@tonic-gate int hashval; 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate hashval = hash(mapname); 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate return( unlock_core( hashval )); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate /* 329*7c478bd9Sstevel@tonic-gate * FUNCTION : unlock_core() 330*7c478bd9Sstevel@tonic-gate * 331*7c478bd9Sstevel@tonic-gate * DESCRIPTION: The core map locking function 332*7c478bd9Sstevel@tonic-gate * 333*7c478bd9Sstevel@tonic-gate * GIVEN : Map hash value 334*7c478bd9Sstevel@tonic-gate * 335*7c478bd9Sstevel@tonic-gate * RETURNS : 0 = Failure 336*7c478bd9Sstevel@tonic-gate * 1 = Success 337*7c478bd9Sstevel@tonic-gate */ 338*7c478bd9Sstevel@tonic-gate int 339*7c478bd9Sstevel@tonic-gate unlock_core(int hashval) 340*7c478bd9Sstevel@tonic-gate { 341*7c478bd9Sstevel@tonic-gate int rc; 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate rc = mutex_unlock(&(shmlockarray->locknode[hashval])); 344*7c478bd9Sstevel@tonic-gate if (rc != 0) { 345*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 346*7c478bd9Sstevel@tonic-gate "mutex_unlock(): error=%d", rc); 347*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 348*7c478bd9Sstevel@tonic-gate "Please restart NIS (ypstop/ypstart)."); 349*7c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) { 350*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 351*7c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.", 352*7c478bd9Sstevel@tonic-gate LOCKFILE, errno); 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate return (0); 355*7c478bd9Sstevel@tonic-gate } 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate /* Success */ 358*7c478bd9Sstevel@tonic-gate return (1); 359*7c478bd9Sstevel@tonic-gate } 360