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
53f95ae75Ssm26363 * Common Development and Distribution License (the "License").
63f95ae75Ssm26363 * 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 */
21*883492d5Sraf
227c478bd9Sstevel@tonic-gate /*
23*883492d5Sraf * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <unistd.h>
287c478bd9Sstevel@tonic-gate #include <syslog.h>
297c478bd9Sstevel@tonic-gate #include <sys/mman.h>
307c478bd9Sstevel@tonic-gate #include <thread.h>
317c478bd9Sstevel@tonic-gate #include <synch.h>
324a190493Ssdussud #include <strings.h>
337c478bd9Sstevel@tonic-gate #include <ndbm.h>
347c478bd9Sstevel@tonic-gate #include "../ypsym.h"
357c478bd9Sstevel@tonic-gate #include "../ypdefs.h"
364a190493Ssdussud #include "shim.h"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate * These routines provide mutual exclusion between ypserv and ypxfr.
407c478bd9Sstevel@tonic-gate * Mutual exclusion is needed so that ypxfr doesn't try to rename
417c478bd9Sstevel@tonic-gate * dbm files while ypserv is trying to open them. After ypserv has
427c478bd9Sstevel@tonic-gate * opened a dbm file, it is safe to rename it because ypserv still
437c478bd9Sstevel@tonic-gate * has access to the file through its file descriptor.
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define LOCKFILE "/var/run/yp_maplock"
477c478bd9Sstevel@tonic-gate struct lockarray {
487c478bd9Sstevel@tonic-gate mutex_t locknode[MAXHASH];
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate typedef struct lockarray lockarray;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate * Cross-process robust mutex locks.
547c478bd9Sstevel@tonic-gate * Provide synchronization between YP processes
557c478bd9Sstevel@tonic-gate * by implementing an exclusive locking mechanism
567c478bd9Sstevel@tonic-gate * via a memory-mapped file.
577c478bd9Sstevel@tonic-gate */
587c478bd9Sstevel@tonic-gate static struct lockarray *shmlockarray;
597c478bd9Sstevel@tonic-gate static int lockfile;
607c478bd9Sstevel@tonic-gate
614a190493Ssdussud /*
624a190493Ssdussud * Hash functions, used for by the locking mechanism.
634a190493Ssdussud *
644a190493Ssdussud * - hash() is the front-end function that gets called.
654a190493Ssdussud * - get_map_id() returns a unique int value per map.
664a190493Ssdussud * It is used in N2L mode only.
674a190493Ssdussud * It is called by hash() in N2L mode.
684a190493Ssdussud */
694a190493Ssdussud int
get_map_id(char * map_name,int index)704a190493Ssdussud get_map_id(char *map_name, int index)
714a190493Ssdussud {
724a190493Ssdussud map_id_elt_t *cur_elt;
734a190493Ssdussud /*
744a190493Ssdussud * Local references to hash table for map lists
754a190493Ssdussud * and to max number of maps
764a190493Ssdussud */
774a190493Ssdussud map_id_elt_t **map_list_p;
784a190493Ssdussud int max_map;
794a190493Ssdussud
804a190493Ssdussud /* initializes map_list_p & max_map */
814a190493Ssdussud get_list_max(&map_list_p, &max_map);
824a190493Ssdussud
834a190493Ssdussud cur_elt = map_list_p[index];
844a190493Ssdussud while (cur_elt != NULL) {
854a190493Ssdussud if (strcmp(map_name, cur_elt->map_name) == 0) {
864a190493Ssdussud /* found */
874a190493Ssdussud return (cur_elt->map_id);
884a190493Ssdussud }
894a190493Ssdussud cur_elt = cur_elt->next;
904a190493Ssdussud }
914a190493Ssdussud syslog(LOG_WARNING, "get_map_id: no hash id found for %s"
924a190493Ssdussud ", giving max_map value (%d)",
934a190493Ssdussud map_name, max_map);
944a190493Ssdussud /*
954a190493Ssdussud * max_map does not match any map id, hence
964a190493Ssdussud * will not trigger any lock collision
974a190493Ssdussud * with existing maps.
984a190493Ssdussud * Needed for yp regular locking mechanism.
994a190493Ssdussud */
1004a190493Ssdussud return (max_map);
1014a190493Ssdussud }
1024a190493Ssdussud
1037c478bd9Sstevel@tonic-gate int
hash(char * s)1047c478bd9Sstevel@tonic-gate hash(char *s)
1057c478bd9Sstevel@tonic-gate {
1063f95ae75Ssm26363 unsigned int n = 0;
1077c478bd9Sstevel@tonic-gate int i;
1084a190493Ssdussud char *map_name = s;
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate for (i = 1; *s; i += 10, s++) {
1117c478bd9Sstevel@tonic-gate n += i * (*s);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate n %= MAXHASH;
1144a190493Ssdussud
1154a190493Ssdussud if (yptol_mode & yptol_newlock) {
1164a190493Ssdussud return (get_map_id(map_name, n));
1174a190493Ssdussud } else {
1187c478bd9Sstevel@tonic-gate return (n);
1197c478bd9Sstevel@tonic-gate }
1204a190493Ssdussud }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate bool
init_locks_mem()1237c478bd9Sstevel@tonic-gate init_locks_mem()
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate int iiter, rc;
1267c478bd9Sstevel@tonic-gate int ebusy_cnt = 0;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate * Initialize cross-process locks in memory-mapped file.
1307c478bd9Sstevel@tonic-gate */
1317c478bd9Sstevel@tonic-gate for (iiter = 0; iiter < MAXHASH; iiter++) {
1327c478bd9Sstevel@tonic-gate if (rc = mutex_init(&(shmlockarray->locknode[iiter]),
133*883492d5Sraf USYNC_PROCESS | LOCK_ROBUST, 0)) {
1347c478bd9Sstevel@tonic-gate if (rc == EBUSY) {
1357c478bd9Sstevel@tonic-gate ebusy_cnt++;
1367c478bd9Sstevel@tonic-gate } else {
1377c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1387c478bd9Sstevel@tonic-gate "init_locks_mem():mutex_init():error=%d",
1397c478bd9Sstevel@tonic-gate rc);
1407c478bd9Sstevel@tonic-gate return (FALSE);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate * EBUSY for all locks OK, it means another process
1477c478bd9Sstevel@tonic-gate * has already initialized locks.
1487c478bd9Sstevel@tonic-gate */
1497c478bd9Sstevel@tonic-gate if ((ebusy_cnt > 0) && (ebusy_cnt != MAXHASH)) {
1507c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1517c478bd9Sstevel@tonic-gate "%s inconsistent. Remove and restart NIS (YP).", LOCKFILE);
1527c478bd9Sstevel@tonic-gate return (FALSE);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate return (TRUE);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate bool
init_lock_map()1587c478bd9Sstevel@tonic-gate init_lock_map()
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate char buff[ sizeof (lockarray) ];
1617c478bd9Sstevel@tonic-gate int write_cnt, lf_size;
1627c478bd9Sstevel@tonic-gate struct stat fdata;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate * Locking file initialization algorithm, with recovery mechanism.
1667c478bd9Sstevel@tonic-gate * This mechanism has been devised to ensure proper creation
1677c478bd9Sstevel@tonic-gate * of a memory-mapped lock file containing mutexes for robust,
1687c478bd9Sstevel@tonic-gate * inter-process communication.
1697c478bd9Sstevel@tonic-gate * File name is /var/run/yp_maplock (LOCKFILE). It might or might
1707c478bd9Sstevel@tonic-gate * not exist.
1717c478bd9Sstevel@tonic-gate *
1727c478bd9Sstevel@tonic-gate * Algorithm:
1737c478bd9Sstevel@tonic-gate * Try to open the file. If file doesn't exist, or size is too small,
1747c478bd9Sstevel@tonic-gate * create/rewrite the file, m-map it into memory and initialize the
1757c478bd9Sstevel@tonic-gate * mutexes in it.
1767c478bd9Sstevel@tonic-gate * If file exists and size is at least large enough, assume it's a
1777c478bd9Sstevel@tonic-gate * good file, and m-map the lock structure directly to it.
1787c478bd9Sstevel@tonic-gate *
1797c478bd9Sstevel@tonic-gate * Recovery from inconsistent state is easy - simply delete the file
1807c478bd9Sstevel@tonic-gate * and restart NIS (YP).
1817c478bd9Sstevel@tonic-gate */
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate lockfile = open(LOCKFILE, O_RDWR|O_CREAT, 0600);
1847c478bd9Sstevel@tonic-gate if (lockfile != -1) {
1857c478bd9Sstevel@tonic-gate if (lockf(lockfile, F_LOCK, 0) == 0) {
1867c478bd9Sstevel@tonic-gate if (fstat(lockfile, &fdata) == 0) {
1877c478bd9Sstevel@tonic-gate lf_size = fdata.st_size;
1887c478bd9Sstevel@tonic-gate if (lf_size < sizeof (lockarray)) {
1897c478bd9Sstevel@tonic-gate bzero(buff, sizeof (buff));
1907c478bd9Sstevel@tonic-gate if ((write_cnt = write(lockfile, buff,
1917c478bd9Sstevel@tonic-gate sizeof (buff)) != sizeof (buff))) {
1927c478bd9Sstevel@tonic-gate if (write_cnt < 0) {
1937c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1947c478bd9Sstevel@tonic-gate "write(%s) => errno=%d",
1957c478bd9Sstevel@tonic-gate LOCKFILE, errno);
1967c478bd9Sstevel@tonic-gate } else {
1977c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1987c478bd9Sstevel@tonic-gate "write(%s) => %d!=%d: wrong number of bytes written.",
1997c478bd9Sstevel@tonic-gate LOCKFILE,
2007c478bd9Sstevel@tonic-gate write_cnt,
2017c478bd9Sstevel@tonic-gate sizeof (buff));
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0);
2047c478bd9Sstevel@tonic-gate close(lockfile);
2057c478bd9Sstevel@tonic-gate return (FALSE);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate } else {
2097c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2107c478bd9Sstevel@tonic-gate "fstat(%s) => errno=%d", LOCKFILE, errno);
2117c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0);
2127c478bd9Sstevel@tonic-gate close(lockfile);
2137c478bd9Sstevel@tonic-gate return (FALSE);
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate } else {
2167c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2177c478bd9Sstevel@tonic-gate "lockf(%s,F_LOCK) => errno=%d", LOCKFILE, errno);
2187c478bd9Sstevel@tonic-gate close(lockfile);
2197c478bd9Sstevel@tonic-gate return (FALSE);
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate } else {
2227c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2237c478bd9Sstevel@tonic-gate "open(%s) => errno=%d", LOCKFILE, errno);
2247c478bd9Sstevel@tonic-gate return (FALSE);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate * File exists with correct size, is open, and we're holding
2297c478bd9Sstevel@tonic-gate * the file lock.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate shmlockarray = (lockarray *)mmap((caddr_t)0, sizeof (lockarray),
2327c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE, MAP_SHARED, lockfile, 0);
2337c478bd9Sstevel@tonic-gate if (shmlockarray == MAP_FAILED) {
2347c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "mmap(%s) => errno=%d", LOCKFILE, errno);
2357c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0);
2367c478bd9Sstevel@tonic-gate close(lockfile);
2377c478bd9Sstevel@tonic-gate return (FALSE);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate * If we wrote zeroes to the file, we also need to initialize
2427c478bd9Sstevel@tonic-gate * the mutex locks.
2437c478bd9Sstevel@tonic-gate */
2447c478bd9Sstevel@tonic-gate if (lf_size < sizeof (lockarray)) {
2457c478bd9Sstevel@tonic-gate if (init_locks_mem() == FALSE) {
2467c478bd9Sstevel@tonic-gate lockf(lockfile, F_ULOCK, 0);
2477c478bd9Sstevel@tonic-gate close(lockfile);
2487c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) {
2497c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2507c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.",
2517c478bd9Sstevel@tonic-gate LOCKFILE, errno);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate return (FALSE);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate if (lockf(lockfile, F_ULOCK, 0) != 0) {
2587c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2597c478bd9Sstevel@tonic-gate "lockf(%s,F_ULOCK) => errno=%d",
2607c478bd9Sstevel@tonic-gate LOCKFILE, errno);
2617c478bd9Sstevel@tonic-gate close(lockfile);
2627c478bd9Sstevel@tonic-gate return (FALSE);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate if (close(lockfile) == 0) {
2667c478bd9Sstevel@tonic-gate return (TRUE);
2677c478bd9Sstevel@tonic-gate } else {
2687c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
2697c478bd9Sstevel@tonic-gate "close(%s) => errno=%d", LOCKFILE, errno);
2707c478bd9Sstevel@tonic-gate return (FALSE);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate * FUNCTION : lock_map()
2767c478bd9Sstevel@tonic-gate *
2777c478bd9Sstevel@tonic-gate * DESCRIPTION: Front end to the lock routine taking map name as argument.
2787c478bd9Sstevel@tonic-gate *
2797c478bd9Sstevel@tonic-gate * GIVEN : Map name.
2807c478bd9Sstevel@tonic-gate *
2817c478bd9Sstevel@tonic-gate * RETURNS : Same as lock_core
2827c478bd9Sstevel@tonic-gate */
2837c478bd9Sstevel@tonic-gate int
lock_map(char * mapname)2847c478bd9Sstevel@tonic-gate lock_map(char *mapname)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate int hashval;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate hashval = hash(mapname);
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate return (lock_core(hashval));
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate * FUNCTION : lock_core()
2957c478bd9Sstevel@tonic-gate *
2967c478bd9Sstevel@tonic-gate * DESCRIPTION: The core map locking function
2977c478bd9Sstevel@tonic-gate *
2987c478bd9Sstevel@tonic-gate * GIVEN : Map hash value
2997c478bd9Sstevel@tonic-gate *
3007c478bd9Sstevel@tonic-gate * RETURNS : 0 = Failure
3017c478bd9Sstevel@tonic-gate * 1 = Success
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate int
lock_core(int hashval)3047c478bd9Sstevel@tonic-gate lock_core(int hashval)
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate int rc;
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate * Robust, cross-process lock implementation
3107c478bd9Sstevel@tonic-gate */
3117c478bd9Sstevel@tonic-gate rc = mutex_lock(&(shmlockarray->locknode[hashval]));
3127c478bd9Sstevel@tonic-gate while (rc != 0) {
3137c478bd9Sstevel@tonic-gate switch (rc) {
3147c478bd9Sstevel@tonic-gate case EOWNERDEAD:
3157c478bd9Sstevel@tonic-gate /*
316*883492d5Sraf * Previous lock owner died, resetting lock
3177c478bd9Sstevel@tonic-gate * to recover from error.
3187c478bd9Sstevel@tonic-gate */
319*883492d5Sraf rc = mutex_consistent(
320*883492d5Sraf &(shmlockarray->locknode[hashval]));
3217c478bd9Sstevel@tonic-gate if (rc != 0) {
3227c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
323*883492d5Sraf "mutex_consistent(): error=%d", rc);
3247c478bd9Sstevel@tonic-gate return (0);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate rc = mutex_unlock(&(shmlockarray->locknode[hashval]));
3277c478bd9Sstevel@tonic-gate if (rc != 0) {
3287c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3297c478bd9Sstevel@tonic-gate "mutex_unlock(): error=%d", rc);
3307c478bd9Sstevel@tonic-gate return (0);
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate break;
3337c478bd9Sstevel@tonic-gate default:
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate * Unrecoverable problem - nothing to do
3367c478bd9Sstevel@tonic-gate * but exit YP and delete lock file.
3377c478bd9Sstevel@tonic-gate */
3387c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3397c478bd9Sstevel@tonic-gate "mutex_lock(): error=%d", rc);
3407c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3417c478bd9Sstevel@tonic-gate "Please restart NIS (ypstop/ypstart).");
3427c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) {
3437c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3447c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.",
3457c478bd9Sstevel@tonic-gate LOCKFILE, errno);
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate return (0);
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate rc = mutex_lock(&(shmlockarray->locknode[hashval]));
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate /* Success */
3537c478bd9Sstevel@tonic-gate return (1);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate /*
3587c478bd9Sstevel@tonic-gate * FUNCTION : unlock_map()
3597c478bd9Sstevel@tonic-gate *
3607c478bd9Sstevel@tonic-gate * DESCRIPTION: Front end to the unlock routine taking map name as argument.
3617c478bd9Sstevel@tonic-gate *
3627c478bd9Sstevel@tonic-gate * GIVEN : Map name.
3637c478bd9Sstevel@tonic-gate *
3647c478bd9Sstevel@tonic-gate * RETURNS : Same as unlock_core
3657c478bd9Sstevel@tonic-gate */
3667c478bd9Sstevel@tonic-gate int
unlock_map(char * mapname)3677c478bd9Sstevel@tonic-gate unlock_map(char *mapname)
3687c478bd9Sstevel@tonic-gate {
3697c478bd9Sstevel@tonic-gate int hashval;
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate hashval = hash(mapname);
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate return (unlock_core(hashval));
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate * FUNCTION : unlock_core()
3787c478bd9Sstevel@tonic-gate *
3797c478bd9Sstevel@tonic-gate * DESCRIPTION: The core map locking function
3807c478bd9Sstevel@tonic-gate *
3817c478bd9Sstevel@tonic-gate * GIVEN : Map hash value
3827c478bd9Sstevel@tonic-gate *
3837c478bd9Sstevel@tonic-gate * RETURNS : 0 = Failure
3847c478bd9Sstevel@tonic-gate * 1 = Success
3857c478bd9Sstevel@tonic-gate */
3867c478bd9Sstevel@tonic-gate int
unlock_core(int hashval)3877c478bd9Sstevel@tonic-gate unlock_core(int hashval)
3887c478bd9Sstevel@tonic-gate {
3897c478bd9Sstevel@tonic-gate int rc;
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate rc = mutex_unlock(&(shmlockarray->locknode[hashval]));
3927c478bd9Sstevel@tonic-gate if (rc != 0) {
3937c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3947c478bd9Sstevel@tonic-gate "mutex_unlock(): error=%d", rc);
3957c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3967c478bd9Sstevel@tonic-gate "Please restart NIS (ypstop/ypstart).");
3977c478bd9Sstevel@tonic-gate if (remove(LOCKFILE) != 0) {
3987c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
3997c478bd9Sstevel@tonic-gate "remove(%s) => errno=%d: Please delete file.",
4007c478bd9Sstevel@tonic-gate LOCKFILE, errno);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate return (0);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /* Success */
4067c478bd9Sstevel@tonic-gate return (1);
4077c478bd9Sstevel@tonic-gate }
408