From: Vincent Hanquez Date: Mon, 9 Feb 2009 17:21:46 +0000 (+0000) Subject: add-shm_open-shm_unlink.patch X-Git-Url: http://xenbits.xen.org/gitweb?a=commitdiff_plain;h=46d0665a320c0cecdea6f98ca83577dfd729f4b0;p=xenclient%2Fuclibc.git add-shm_open-shm_unlink.patch --- diff --git a/librt/sh_open.c b/librt/sh_open.c new file mode 100644 index 0000000..cb92c3a --- /dev/null +++ b/librt/sh_open.c @@ -0,0 +1,48 @@ +/* shm_open - open a shared memory file */ + +/* Copyright 2002, Red Hat Inc. */ + +#include +#include +#include +#include +#include +#include + +int +shm_open (const char *name, int oflag, mode_t mode) +{ + int fd; + char shm_name[PATH_MAX+20] = "/dev/shm/"; + + /* skip opening slash */ + if (*name == '/') + ++name; + + /* create special shared memory file name and leave enough space to + cause a path/name error if name is too long */ + strlcpy (shm_name + 9, name, PATH_MAX + 10); + + fd = open (shm_name, oflag, mode); + + if (fd != -1) + { + /* once open we must add FD_CLOEXEC flag to file descriptor */ + int flags = fcntl (fd, F_GETFD, 0); + + if (flags >= 0) + { + flags |= FD_CLOEXEC; + flags = fcntl (fd, F_SETFD, flags); + } + + /* on failure, just close file and give up */ + if (flags == -1) + { + close (fd); + fd = -1; + } + } + + return fd; +} diff --git a/librt/sh_unlink.c b/librt/sh_unlink.c new file mode 100644 index 0000000..cf259c6 --- /dev/null +++ b/librt/sh_unlink.c @@ -0,0 +1,28 @@ +/* shm_unlink - remove a shared memory file */ + +/* Copyright 2002, Red Hat Inc. */ + +#include +#include +#include +#include +#include + +int +shm_unlink (const char *name) +{ + int rc; + char shm_name[PATH_MAX+20] = "/dev/shm/"; + + /* skip opening slash */ + if (*name == '/') + ++name; + + /* create special shared memory file name and leave enough space to + cause a path/name error if name is too long */ + strlcpy (shm_name + 9, name, PATH_MAX + 10); + + rc = unlink (shm_name); + + return rc; +}