From jau@jau.thunderbolt.fi  Tue Jan 28 01:51:36 1997
Received: from jau.thunderbolt.fi (root@jukkonen.dial.tele.fi [194.89.253.78])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id BAA03286
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 28 Jan 1997 01:51:25 -0800 (PST)
Received: (from jau@localhost) by jau.thunderbolt.fi (8.7.5/8.6.12+CSC-2.1) id LAA13781; Tue, 28 Jan 1997 11:33:24 +0200 (EET)
Message-Id: <199701280933.LAA13781@jau.thunderbolt.fi>
Date: Tue, 28 Jan 1997 11:33:24 +0200 (EET)
From: Jukka Ukkonen <jau@jau.thunderbolt.fi>
Reply-To: jau@jau.thunderbolt.fi
To: FreeBSD-gnats-submit@freebsd.org
Subject: Added POSIX.4/POSIX.1b shm_open()/shm_unlink()
X-Send-Pr-Version: 3.2

>Number:         2604
>Category:       bin
>Synopsis:       Added POSIX.4/POSIX.1b shm_open()/shm_unlink()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dufault
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 28 02:00:04 PST 1997
>Closed-Date:    Thu Jun 1 18:32:45 PDT 2000
>Last-Modified:  Thu Jun 01 18:35:51 PDT 2000
>Originator:     Jukka Ukkonen
>Release:        FreeBSD 2.1-STABLE i386
>Organization:
Private person
>Environment:

	This is a new feature to the system library. The exact
	version or release of the operating system as well as
	the hardware environment are meaningless in this context.

>Description:

	This is a minimal implementation of the shared memory objects
	library interface required by POSIX.4.

	Using the normal files as the objects to mmap() has been
	supported for quite a long time in BSD environments, and I saw
	no practical reason to change the file descriptor used by shm_*
	interface to refer to something else.
	POSIX requires only mmap(), ftruncate(), and close() to work
	with the descriptors returned by shm_open(), though.

>How-To-Repeat:

	Share and enjoy.

>Fix:
	
	See the attached shar package below...

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	shm_open.c
#	shm_unlink.c
#
echo x - shm_open.c
sed 's/^X//' >shm_open.c << 'END-of-shm_open.c'
X/*
X * Copyright (c) 1995-1997 Jukka Ukkonen	<jau@iki.fi>
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *      This product includes software developed by Jukka Antero Ukkonen.
X * 4. Neither the names of the authors nor the names of contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X * 5. The source code must be available for anyone who wishes to have it.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *  %W%	(Jukka Ukkonen)	%E%
X */
X
X#ifndef	lint
Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%";
X#endif
X
X/*
X *  usage/example:
X *
X *  fd = shm_open (name, O_RDWR|O_CREAT|O_EXCL, 0600);
X *
X *  shm = mmap (NULL, pagesize, PROT_READ | PROT_WRITE,
X *              MAP_INHERIT | MAP_SHARED, fd, (off_t) 0);
X */
X	 
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <sys/stat.h>
X#include <fcntl.h>
X#include <errno.h>
X
Xint
Xshm_open (name, flags, mode)
X    char    *name;
X    int	    flags;
X    mode_t  mode;
X{
X    struct stat	    st;
X    register int    fd;
X
X    if (! name) {
X	errno = EINVAL;
X
X	return (-1);
X    }
X
X    if ((fd = open (name, flags, mode)) < 0)
X	return (-1);
X
X    if (fstat (fd, &st) < 0)
X	return (-1);
X
X    /*
X     *	The whole difference to the plain open(2) is here.
X     *
X     *	We check that the file descriptor we just opened
X     *	refers to a regular file. We also report invalid
X     *	parameter, if the file name did not give us just
X     *	a plain regular file.
X     *	This is to guarantee that the opened descriptor
X     *	really can be mmap()ed later on.
X     */
X
X    if (! S_ISREG (st.st_mode)) {
X	close (fd);
X
X	errno = EINVAL;
X
X	return (-1);
X    }
X
X    return (fd);
X}
END-of-shm_open.c
echo x - shm_unlink.c
sed 's/^X//' >shm_unlink.c << 'END-of-shm_unlink.c'
X/*
X * Copyright (c) 1995-1997 Jukka Ukkonen	<jau@iki.fi>
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *      This product includes software developed by Jukka Antero Ukkonen.
X * 4. Neither the names of the authors nor the names of contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X * 5. The source code must be available for anyone who wishes to have it.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *  %W%	(Jukka Ukkonen)	%E%
X */
X
X#ifndef	lint
Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%";
X#endif
X
X
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <sys/stat.h>
X#include <unistd.h>
X#include <errno.h>
X
Xint
Xshm_unlink (name)
X    char    *name;
X{
X    struct stat	    st;
X
X    if (! name) {
X	errno = EINVAL;
X	return (-1);
X    }
X
X    if (stat (name, &st) < 0)
X	return (-1);
X
X    /*
X     *	Try to protect against unlinking something that
X     *	never was a potential candidate for being mmap()'ed
X     *	for shared memory access.
X     */
X
X    if (! S_ISREG (st.st_mode)) {
X	errno = EINVAL;
X
X	return (-1);
X    }
X
X    return (unlink (name));
X}
X
END-of-shm_unlink.c
exit

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dufault 
Responsible-Changed-By: dufault 
Responsible-Changed-When: Fri Aug 1 05:03:56 PDT 1997 
Responsible-Changed-Why:  
Take over rtprio/p1003.4 reports 
State-Changed-From-To: open->closed 
State-Changed-By: nrahlstr 
State-Changed-When: Thu Jun 1 18:32:45 PDT 2000 
State-Changed-Why:  
Wollman committed an implementation to -current on 2000/04/22. 
See /usr/src/lib/libc/gen/posixshm.c.  Thanks for you patches. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=2604 
>Unformatted:
