- if (error == PSHMCACHE_NOTFOUND) {
- incache = 0;
- if (fmode & O_CREAT) {
- /* create a new one (commit the allocation) */
- pinfo = new_pinfo;
- pinfo->pshm_flags = PSHM_DEFINED | PSHM_INCREATE;
- pinfo->pshm_usecount = 1; /* existence reference */
- pinfo->pshm_mode = cmode;
- pinfo->pshm_uid = kauth_getuid();
- pinfo->pshm_gid = kauth_getgid();
- bcopy(pnbuf, &pinfo->pshm_name[0], pathlen);
- pinfo->pshm_name[pathlen]=0;
-#if CONFIG_MACF
- error = mac_posixshm_check_create(kauth_cred_get(), nameptr);
- if (error) {
- goto bad;
- }
- mac_posixshm_label_associate(kauth_cred_get(), pinfo, nameptr);
-#endif
- }
- } else {
- incache = 1;
- if (fmode & O_CREAT) {
- /* already exists */
- if ((fmode & O_EXCL)) {
- AUDIT_ARG(posix_ipc_perm, pinfo->pshm_uid,
- pinfo->pshm_gid,
- pinfo->pshm_mode);
-
- /* shm obj exists and opened O_EXCL */
- error = EEXIST;
- goto bad;
- }
-
- if( pinfo->pshm_flags & PSHM_INDELETE) {
- error = ENOENT;
- goto bad;
- }
- AUDIT_ARG(posix_ipc_perm, pinfo->pshm_uid,
- pinfo->pshm_gid, pinfo->pshm_mode);
-#if CONFIG_MACF
- if ((error = mac_posixshm_check_open(kauth_cred_get(), pinfo, fmode))) {
- goto bad;
- }
-#endif
- if ( (error = pshm_access(pinfo, fmode, kauth_cred_get(), p)) ) {
- goto bad;
- }
- }
- }
- if (!(fmode & O_CREAT)) {
- if (!incache) {
- /* O_CREAT is not set and the object does not exist */
- error = ENOENT;
- goto bad;
- }
- if( pinfo->pshm_flags & PSHM_INDELETE) {
- error = ENOENT;
- goto bad;
- }
-#if CONFIG_MACF
- if ((error = mac_posixshm_check_open(kauth_cred_get(), pinfo, fmode))) {
- goto bad;