xref: /titanic_50/usr/src/cmd/ypcmd/shared/lockmap.c (revision 3f95ae75d80ff5305433fd2a78219e39e23a08bb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3f95ae75Ssm26363  * Common Development and Distribution License (the "License").
6*3f95ae75Ssm26363  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*3f95ae75Ssm26363  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <unistd.h>
297c478bd9Sstevel@tonic-gate #include <syslog.h>
307c478bd9Sstevel@tonic-gate #include <sys/mman.h>
317c478bd9Sstevel@tonic-gate #include <thread.h>
327c478bd9Sstevel@tonic-gate #include <synch.h>
337c478bd9Sstevel@tonic-gate #include <ndbm.h>
347c478bd9Sstevel@tonic-gate #include "../ypsym.h"
357c478bd9Sstevel@tonic-gate #include "../ypdefs.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  *  These routines provide mutual exclusion between ypserv and ypxfr.
397c478bd9Sstevel@tonic-gate  *  Mutual exclusion is needed so that ypxfr doesn't try to rename
407c478bd9Sstevel@tonic-gate  *  dbm files while ypserv is trying to open them.  After ypserv has
417c478bd9Sstevel@tonic-gate  *  opened a dbm file, it is safe to rename it because ypserv still
427c478bd9Sstevel@tonic-gate  *  has access to the file through its file descriptor.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	LOCKFILE "/var/run/yp_maplock"
467c478bd9Sstevel@tonic-gate struct lockarray {
477c478bd9Sstevel@tonic-gate 	mutex_t		locknode[MAXHASH];
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate typedef struct lockarray lockarray;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Cross-process robust mutex locks.
537c478bd9Sstevel@tonic-gate  * Provide synchronization between YP processes
547c478bd9Sstevel@tonic-gate  * by implementing an exclusive locking mechanism
557c478bd9Sstevel@tonic-gate  * via a memory-mapped file.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate static struct lockarray	*shmlockarray;
587c478bd9Sstevel@tonic-gate static int	lockfile;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate int
617c478bd9Sstevel@tonic-gate hash(char *s)
627c478bd9Sstevel@tonic-gate {
63*3f95ae75Ssm26363 	unsigned int n = 0;
647c478bd9Sstevel@tonic-gate 	int i;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	for (i = 1; *s; i += 10, s++) {
677c478bd9Sstevel@tonic-gate 		n += i * (*s);
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 	n %= MAXHASH;
707c478bd9Sstevel@tonic-gate 	return (n);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate bool
747c478bd9Sstevel@tonic-gate init_locks_mem()
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	int iiter, rc;
777c478bd9Sstevel@tonic-gate 	int ebusy_cnt = 0;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/*
807c478bd9Sstevel@tonic-gate 	 * Initialize cross-process locks in memory-mapped file.
817c478bd9Sstevel@tonic-gate 	 */
827c478bd9Sstevel@tonic-gate 	for (iiter = 0; iiter < MAXHASH; iiter++) {
837c478bd9Sstevel@tonic-gate 		if (rc = mutex_init(&(shmlockarray->locknode[iiter]),
847c478bd9Sstevel@tonic-gate 		    USYNC_PROCESS_ROBUST, 0)) {
857c478bd9Sstevel@tonic-gate 			if (rc == EBUSY) {
867c478bd9Sstevel@tonic-gate 				ebusy_cnt++;
877c478bd9Sstevel@tonic-gate 			} else {
887c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
897c478bd9Sstevel@tonic-gate 				    "init_locks_mem():mutex_init():error=%d",
907c478bd9Sstevel@tonic-gate 				    rc);
917c478bd9Sstevel@tonic-gate 				return (FALSE);
927c478bd9Sstevel@tonic-gate 			}
937c478bd9Sstevel@tonic-gate 		}
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	/*
977c478bd9Sstevel@tonic-gate 	 * EBUSY for all locks OK, it means another process
987c478bd9Sstevel@tonic-gate 	 * has already initialized locks.
997c478bd9Sstevel@tonic-gate 	 */
1007c478bd9Sstevel@tonic-gate 	if ((ebusy_cnt > 0) && (ebusy_cnt != MAXHASH)) {
1017c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
1027c478bd9Sstevel@tonic-gate 		    "%s inconsistent. Remove and restart NIS (YP).", LOCKFILE);
1037c478bd9Sstevel@tonic-gate 		return (FALSE);
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 	return (TRUE);
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate bool
1097c478bd9Sstevel@tonic-gate init_lock_map()
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	char buff[ sizeof (lockarray) ];
1127c478bd9Sstevel@tonic-gate 	int write_cnt, lf_size;
1137c478bd9Sstevel@tonic-gate 	struct stat fdata;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	/*
1167c478bd9Sstevel@tonic-gate 	 * Locking file initialization algorithm, with recovery mechanism.
1177c478bd9Sstevel@tonic-gate 	 * This mechanism has been devised to ensure proper creation
1187c478bd9Sstevel@tonic-gate 	 * of a memory-mapped lock file containing mutexes for robust,
1197c478bd9Sstevel@tonic-gate 	 * inter-process communication.
1207c478bd9Sstevel@tonic-gate 	 * File name is /var/run/yp_maplock (LOCKFILE).  It might or might
1217c478bd9Sstevel@tonic-gate 	 * not exist.
1227c478bd9Sstevel@tonic-gate 	 *
1237c478bd9Sstevel@tonic-gate 	 * Algorithm:
1247c478bd9Sstevel@tonic-gate 	 * Try to open the file. If file doesn't exist, or size is too small,
1257c478bd9Sstevel@tonic-gate 	 * create/rewrite the file, m-map it into memory and initialize the
1267c478bd9Sstevel@tonic-gate 	 * mutexes in it.
1277c478bd9Sstevel@tonic-gate 	 * If file exists and size is at least large enough, assume it's a
1287c478bd9Sstevel@tonic-gate 	 * good file, and m-map the lock structure directly to it.
1297c478bd9Sstevel@tonic-gate 	 *
1307c478bd9Sstevel@tonic-gate 	 * Recovery from inconsistent state is easy - simply delete the file
1317c478bd9Sstevel@tonic-gate 	 * and restart NIS (YP).
1327c478bd9Sstevel@tonic-gate 	 */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	lockfile = open(LOCKFILE, O_RDWR|O_CREAT, 0600);
1357c478bd9Sstevel@tonic-gate 	if (lockfile != -1) {
1367c478bd9Sstevel@tonic-gate 		if (lockf(lockfile, F_LOCK, 0) == 0) {
1377c478bd9Sstevel@tonic-gate 			if (fstat(lockfile, &fdata) == 0) {
1387c478bd9Sstevel@tonic-gate 				lf_size = fdata.st_size;
1397c478bd9Sstevel@tonic-gate 				if (lf_size < sizeof (lockarray)) {
1407c478bd9Sstevel@tonic-gate 					bzero(buff, sizeof (buff));
1417c478bd9Sstevel@tonic-gate 					if ((write_cnt = write(lockfile, buff,
1427c478bd9Sstevel@tonic-gate 					    sizeof (buff)) != sizeof (buff))) {
1437c478bd9Sstevel@tonic-gate 						if (write_cnt < 0) {
1447c478bd9Sstevel@tonic-gate 							syslog(LOG_ERR,
1457c478bd9Sstevel@tonic-gate 						    "write(%s) => errno=%d",
1467c478bd9Sstevel@tonic-gate 							    LOCKFILE, errno);
1477c478bd9Sstevel@tonic-gate 						} else {
1487c478bd9Sstevel@tonic-gate 							syslog(LOG_ERR,
1497c478bd9Sstevel@tonic-gate 		    "write(%s) => %d!=%d: wrong number of bytes written.",
1507c478bd9Sstevel@tonic-gate 							    LOCKFILE,
1517c478bd9Sstevel@tonic-gate 							    write_cnt,
1527c478bd9Sstevel@tonic-gate 							    sizeof (buff));
1537c478bd9Sstevel@tonic-gate 						}
1547c478bd9Sstevel@tonic-gate 						lockf(lockfile, F_ULOCK, 0);
1557c478bd9Sstevel@tonic-gate 						close(lockfile);
1567c478bd9Sstevel@tonic-gate 						return (FALSE);
1577c478bd9Sstevel@tonic-gate 					}
1587c478bd9Sstevel@tonic-gate 				}
1597c478bd9Sstevel@tonic-gate 			} else {
1607c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
1617c478bd9Sstevel@tonic-gate 				    "fstat(%s) => errno=%d", LOCKFILE, errno);
1627c478bd9Sstevel@tonic-gate 				lockf(lockfile, F_ULOCK, 0);
1637c478bd9Sstevel@tonic-gate 				close(lockfile);
1647c478bd9Sstevel@tonic-gate 				return (FALSE);
1657c478bd9Sstevel@tonic-gate 			}
1667c478bd9Sstevel@tonic-gate 		} else {
1677c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR,
1687c478bd9Sstevel@tonic-gate 			    "lockf(%s,F_LOCK) => errno=%d", LOCKFILE, errno);
1697c478bd9Sstevel@tonic-gate 			close(lockfile);
1707c478bd9Sstevel@tonic-gate 			return (FALSE);
1717c478bd9Sstevel@tonic-gate 		}
1727c478bd9Sstevel@tonic-gate 	} else {
1737c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
1747c478bd9Sstevel@tonic-gate 		    "open(%s) => errno=%d", LOCKFILE, errno);
1757c478bd9Sstevel@tonic-gate 		return (FALSE);
1767c478bd9Sstevel@tonic-gate 	}
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	/*
1797c478bd9Sstevel@tonic-gate 	 * File exists with correct size, is open, and we're holding
1807c478bd9Sstevel@tonic-gate 	 * the file lock.
1817c478bd9Sstevel@tonic-gate 	 */
1827c478bd9Sstevel@tonic-gate 	shmlockarray = (lockarray *)mmap((caddr_t)0, sizeof (lockarray),
1837c478bd9Sstevel@tonic-gate 	    PROT_READ | PROT_WRITE, MAP_SHARED, lockfile, 0);
1847c478bd9Sstevel@tonic-gate 	if (shmlockarray == MAP_FAILED) {
1857c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "mmap(%s) => errno=%d", LOCKFILE, errno);
1867c478bd9Sstevel@tonic-gate 		lockf(lockfile, F_ULOCK, 0);
1877c478bd9Sstevel@tonic-gate 		close(lockfile);
1887c478bd9Sstevel@tonic-gate 		return (FALSE);
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * If we wrote zeroes to the file, we also need to initialize
1937c478bd9Sstevel@tonic-gate 	 * the mutex locks.
1947c478bd9Sstevel@tonic-gate 	 */
1957c478bd9Sstevel@tonic-gate 	if (lf_size < sizeof (lockarray)) {
1967c478bd9Sstevel@tonic-gate 		if (init_locks_mem() == FALSE) {
1977c478bd9Sstevel@tonic-gate 			lockf(lockfile, F_ULOCK, 0);
1987c478bd9Sstevel@tonic-gate 			close(lockfile);
1997c478bd9Sstevel@tonic-gate 			if (remove(LOCKFILE) != 0) {
2007c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
2017c478bd9Sstevel@tonic-gate 			    "remove(%s) => errno=%d: Please delete file.",
2027c478bd9Sstevel@tonic-gate 				    LOCKFILE, errno);
2037c478bd9Sstevel@tonic-gate 			}
2047c478bd9Sstevel@tonic-gate 			return (FALSE);
2057c478bd9Sstevel@tonic-gate 		}
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	if (lockf(lockfile, F_ULOCK, 0) != 0) {
2097c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
2107c478bd9Sstevel@tonic-gate 		    "lockf(%s,F_ULOCK) => errno=%d",
2117c478bd9Sstevel@tonic-gate 		    LOCKFILE, errno);
2127c478bd9Sstevel@tonic-gate 		close(lockfile);
2137c478bd9Sstevel@tonic-gate 		return (FALSE);
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	if (close(lockfile) == 0) {
2177c478bd9Sstevel@tonic-gate 		return (TRUE);
2187c478bd9Sstevel@tonic-gate 	} else {
2197c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
2207c478bd9Sstevel@tonic-gate 		    "close(%s) => errno=%d", LOCKFILE, errno);
2217c478bd9Sstevel@tonic-gate 		return (FALSE);
2227c478bd9Sstevel@tonic-gate 	}
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * FUNCTION : 	lock_map()
2277c478bd9Sstevel@tonic-gate  *
2287c478bd9Sstevel@tonic-gate  * DESCRIPTION: Front end to the lock routine taking map name as argument.
2297c478bd9Sstevel@tonic-gate  *
2307c478bd9Sstevel@tonic-gate  * GIVEN :	Map name.
2317c478bd9Sstevel@tonic-gate  *
2327c478bd9Sstevel@tonic-gate  * RETURNS :	Same as lock_core
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate int
2357c478bd9Sstevel@tonic-gate lock_map(char *mapname)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	int hashval;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	hashval = hash(mapname);
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	return (lock_core(hashval));
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate  * FUNCTION : 	lock_core()
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  * DESCRIPTION: The core map locking function
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  * GIVEN :	Map hash value
2507c478bd9Sstevel@tonic-gate  *
2517c478bd9Sstevel@tonic-gate  * RETURNS :	0 = Failure
2527c478bd9Sstevel@tonic-gate  *		1 = Success
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate int
2557c478bd9Sstevel@tonic-gate lock_core(int hashval)
2567c478bd9Sstevel@tonic-gate {
2577c478bd9Sstevel@tonic-gate 	int rc;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/*
2607c478bd9Sstevel@tonic-gate 	 * Robust, cross-process lock implementation
2617c478bd9Sstevel@tonic-gate 	 */
2627c478bd9Sstevel@tonic-gate 	rc = mutex_lock(&(shmlockarray->locknode[hashval]));
2637c478bd9Sstevel@tonic-gate 	while (rc != 0) {
2647c478bd9Sstevel@tonic-gate 		switch (rc) {
2657c478bd9Sstevel@tonic-gate 		case EOWNERDEAD:
2667c478bd9Sstevel@tonic-gate 			/*
2677c478bd9Sstevel@tonic-gate 			 * Previows lock owner died, resetting lock
2687c478bd9Sstevel@tonic-gate 			 * to recover from error.
2697c478bd9Sstevel@tonic-gate 			 */
2707c478bd9Sstevel@tonic-gate 			rc = mutex_init(&(shmlockarray->locknode[hashval]),
2717c478bd9Sstevel@tonic-gate 			    USYNC_PROCESS_ROBUST, 0);
2727c478bd9Sstevel@tonic-gate 			if (rc != 0) {
2737c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
2747c478bd9Sstevel@tonic-gate 				    "mutex_init(): error=%d", rc);
2757c478bd9Sstevel@tonic-gate 				return (0);
2767c478bd9Sstevel@tonic-gate 			}
2777c478bd9Sstevel@tonic-gate 			rc = mutex_unlock(&(shmlockarray->locknode[hashval]));
2787c478bd9Sstevel@tonic-gate 			if (rc != 0) {
2797c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
2807c478bd9Sstevel@tonic-gate 				    "mutex_unlock(): error=%d", rc);
2817c478bd9Sstevel@tonic-gate 				return (0);
2827c478bd9Sstevel@tonic-gate 			}
2837c478bd9Sstevel@tonic-gate 			break;
2847c478bd9Sstevel@tonic-gate 		default:
2857c478bd9Sstevel@tonic-gate 			/*
2867c478bd9Sstevel@tonic-gate 			 * Unrecoverable problem - nothing to do
2877c478bd9Sstevel@tonic-gate 			 * but exit YP and delete lock file.
2887c478bd9Sstevel@tonic-gate 			 */
2897c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR,
2907c478bd9Sstevel@tonic-gate 			    "mutex_lock(): error=%d", rc);
2917c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR,
2927c478bd9Sstevel@tonic-gate 			    "Please restart NIS (ypstop/ypstart).");
2937c478bd9Sstevel@tonic-gate 			if (remove(LOCKFILE) != 0) {
2947c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
2957c478bd9Sstevel@tonic-gate 			    "remove(%s) => errno=%d: Please delete file.",
2967c478bd9Sstevel@tonic-gate 				    LOCKFILE, errno);
2977c478bd9Sstevel@tonic-gate 			}
2987c478bd9Sstevel@tonic-gate 			return (0);
2997c478bd9Sstevel@tonic-gate 		}
3007c478bd9Sstevel@tonic-gate 		rc = mutex_lock(&(shmlockarray->locknode[hashval]));
3017c478bd9Sstevel@tonic-gate 	}
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	/* Success */
3047c478bd9Sstevel@tonic-gate 	return (1);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * FUNCTION : 	unlock_map()
3107c478bd9Sstevel@tonic-gate  *
3117c478bd9Sstevel@tonic-gate  * DESCRIPTION: Front end to the unlock routine taking map name as argument.
3127c478bd9Sstevel@tonic-gate  *
3137c478bd9Sstevel@tonic-gate  * GIVEN :	Map name.
3147c478bd9Sstevel@tonic-gate  *
3157c478bd9Sstevel@tonic-gate  * RETURNS :	Same as unlock_core
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate int
3187c478bd9Sstevel@tonic-gate unlock_map(char *mapname)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	int hashval;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	hashval = hash(mapname);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	return (unlock_core(hashval));
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * FUNCTION : 	unlock_core()
3297c478bd9Sstevel@tonic-gate  *
3307c478bd9Sstevel@tonic-gate  * DESCRIPTION: The core map locking function
3317c478bd9Sstevel@tonic-gate  *
3327c478bd9Sstevel@tonic-gate  * GIVEN :	Map hash value
3337c478bd9Sstevel@tonic-gate  *
3347c478bd9Sstevel@tonic-gate  * RETURNS :	0 = Failure
3357c478bd9Sstevel@tonic-gate  *		1 = Success
3367c478bd9Sstevel@tonic-gate  */
3377c478bd9Sstevel@tonic-gate int
3387c478bd9Sstevel@tonic-gate unlock_core(int hashval)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate 	int rc;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	rc = mutex_unlock(&(shmlockarray->locknode[hashval]));
3437c478bd9Sstevel@tonic-gate 	if (rc != 0) {
3447c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
3457c478bd9Sstevel@tonic-gate 		    "mutex_unlock(): error=%d", rc);
3467c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR,
3477c478bd9Sstevel@tonic-gate 		    "Please restart NIS (ypstop/ypstart).");
3487c478bd9Sstevel@tonic-gate 		if (remove(LOCKFILE) != 0) {
3497c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR,
3507c478bd9Sstevel@tonic-gate 			    "remove(%s) => errno=%d: Please delete file.",
3517c478bd9Sstevel@tonic-gate 			    LOCKFILE, errno);
3527c478bd9Sstevel@tonic-gate 		}
3537c478bd9Sstevel@tonic-gate 		return (0);
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	/* Success */
3577c478bd9Sstevel@tonic-gate 	return (1);
3587c478bd9Sstevel@tonic-gate }
359