From owner-freebsd-bugs Tue Jan 28 02:00:08 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id CAA03593 for bugs-outgoing; Tue, 28 Jan 1997 02:00:08 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id CAA03574; Tue, 28 Jan 1997 02:00:05 -0800 (PST) Resent-Date: Tue, 28 Jan 1997 02:00:05 -0800 (PST) Resent-Message-Id: <199701281000.CAA03574@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, jau@jau.thunderbolt.fi 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 ; 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 Reply-To: jau@jau.thunderbolt.fi To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/2604: Added POSIX.4/POSIX.1b shm_open()/shm_unlink() Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 2604 >Category: bin >Synopsis: Added POSIX.4/POSIX.1b shm_open()/shm_unlink() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Jan 28 02:00:04 PST 1997 >Last-Modified: >Originator: Jukka Ukkonen >Organization: Private person >Release: FreeBSD 2.1-STABLE i386 >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 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 X#include X#include X#include X#include 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 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 X#include X#include X#include X#include 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 >Audit-Trail: >Unformatted: