1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1997-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9#include "db_config.h" 10 11#include "db_int.h" 12 13/* 14 * __os_qnx_region_open -- 15 * Open a shared memory region file using POSIX shm_open. 16 * 17 * PUBLIC: #ifdef HAVE_QNX 18 * PUBLIC: int __os_qnx_region_open 19 * PUBLIC: __P((ENV *, const char *, int, int, DB_FH **)); 20 * PUBLIC: #endif 21 */ 22int 23__os_qnx_region_open(env, name, oflags, mode, fhpp) 24 ENV *env; 25 const char *name; 26 int oflags, mode; 27 DB_FH **fhpp; 28{ 29 DB_FH *fhp; 30 int fcntl_flags; 31 int ret; 32 33 /* 34 * Allocate the file handle and copy the file name. We generally only 35 * use the name for verbose or error messages, but on systems where we 36 * can't unlink temporary files immediately, we use the name to unlink 37 * the temporary file when the file handle is closed. 38 * 39 * Lock the ENV handle and insert the new file handle on the list. 40 */ 41 if ((ret = __os_calloc(env, 1, sizeof(DB_FH), &fhp)) != 0) 42 return (ret); 43 if ((ret = __os_strdup(env, name, &fhp->name)) != 0) 44 goto err; 45 if (env != NULL) { 46 MUTEX_LOCK(env, env->mtx_env); 47 TAILQ_INSERT_TAIL(&env->fdlist, fhp, q); 48 MUTEX_UNLOCK(env, env->mtx_env); 49 F_SET(fhp, DB_FH_ENVLINK); 50 } 51 52 /* 53 * Once we have created the object, we don't need the name 54 * anymore. Other callers of this will convert themselves. 55 */ 56 if ((fhp->fd = shm_open(name, oflags, mode)) == -1) { 57 ret = __os_posix_err(__os_get_syserr()); 58err: (void)__os_closehandle(env, fhp); 59 return (ret); 60 } 61 62 F_SET(fhp, DB_FH_OPENED); 63 64#ifdef HAVE_FCNTL_F_SETFD 65 /* Deny file descriptor access to any child process. */ 66 if ((fcntl_flags = fcntl(fhp->fd, F_GETFD)) == -1 || 67 fcntl(fhp->fd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) { 68 ret = __os_get_syserr(); 69 __db_syserr(env, ret, "fcntl(F_SETFD)"); 70 (void)__os_closehandle(env, fhp); 71 return (__os_posix_err(ret)); 72 } 73#else 74 COMPQUIET(fcntl_flags, 0); 75#endif 76 F_SET(fhp, DB_FH_OPENED); 77 *fhpp = fhp; 78 return (0); 79} 80