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