changeset 891:8c850984c457

Upgrades to uClibc: add shm support (Coleman Brumley backported this) and futimes (patch by me).
author Rob Landley <rob@landley.net>
date Wed, 18 Nov 2009 18:36:53 -0600
parents 368cdbe5b0ee
children a3ab17ecff3f
files sources/patches/uClibc-add-shm.patch sources/patches/uClibc-futimes.patch
diffstat 2 files changed, 158 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/patches/uClibc-add-shm.patch	Wed Nov 18 18:36:53 2009 -0600
@@ -0,0 +1,108 @@
+librt/shm.c |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 files changed, 98 insertions(+), 0 deletions(-)
+ create mode 100644 librt/shm.c
+
+diff --git a/librt/shm.c b/librt/shm.c
+new file mode 100644
+index 0000000..637e945
+--- /dev/null
++++ b/librt/shm.c
+@@ -0,0 +1,98 @@
++/* Copyright (C) 2009 Bernhard Reutner-Fischer <uclibc at uclibc.org>
++ *
++ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
++ */
++
++#include <features.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <fcntl.h>
++#include <unistd.h>
++#include <stdlib.h>
++#include <stdio.h>
++
++#ifndef O_CLOEXEC
++#include <errno.h>
++#endif
++
++#ifndef _PATH_SHM
++#define _PATH_SHM "/dev/shm/"
++#endif
++
++#ifndef NAME_MAX
++#define NAME_MAX 255
++#endif
++
++/* Get name of dummy shm operation handle.
++ * Returns a malloc'ed buffer containing the OS specific path
++ * to the shm filename or NULL upon failure.
++ */
++static __attribute_noinline__ char* get_shm_name(const char*name) __nonnull((1));
++static char* get_shm_name(const char*name)
++{
++	char *path;
++	int i;
++
++	/* Skip leading slashes */
++	while (*name == '/')
++		++name;
++#ifdef __USE_GNU
++	i = asprintf(&path, _PATH_SHM "%s", name);
++	if (i < 0)
++		return NULL;
++#else
++	path = malloc(NAME_MAX);
++	if (path == NULL)
++		return NULL;
++	i = snprintf(path, NAME_MAX, _PATH_SHM "%s", name);
++	if (i < 0) {
++		free(path);
++		return NULL;
++	}
++#endif
++	return path;
++}
++
++int shm_open(const char *name, int oflag, mode_t mode)
++{
++	int fd, old_errno;
++	char *shm_name = get_shm_name(name);
++
++	/* Stripped multiple '/' from start; may have set errno properly */
++	if (shm_name == NULL)
++		return -1;
++	/* The FD_CLOEXEC file descriptor flag associated with the new
++	 * file descriptor is set.  */
++#ifdef O_CLOEXEC
++	 /* Just open it with CLOEXEC set, for brevity */
++	fd = open(shm_name, oflag | O_CLOEXEC, mode);
++#else
++	fd = open(shm_name, oflag, mode);
++	if (fd >= 0) {
++		int fdflags = fcntl(fd, F_GETFD, 0);
++		if (fdflags >= 0)
++			fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
++		if (fdflags < 0) {
++			close(fd);
++			fd = -1;
++		}
++	}
++#endif
++	old_errno = errno;
++	free(shm_name);
++	errno = old_errno;
++	return fd;
++}
++
++int shm_unlink(const char *name)
++{
++	char *shm_name = get_shm_name(name);
++	int ret;
++
++	/* Stripped multiple '/' from start; may have set errno properly */
++	if (shm_name == NULL)
++		return -1;
++	ret = unlink(shm_name);
++	free(shm_name);
++	return ret;
++}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/patches/uClibc-futimes.patch	Wed Nov 18 18:36:53 2009 -0600
@@ -0,0 +1,50 @@
+User Mode Linux needs futimes().
+
+--- uClibc/include/sys/time.h	2005-11-30 11:07:06.000000000 -0600
++++ uClibc2/include/sys/time.h	2009-11-14 04:55:32.000000000 -0600
+@@ -143,7 +143,9 @@
+ /* Same as `utimes', but does not follow symbolic links.  */
+ extern int lutimes (__const char *__file, __const struct timeval __tvp[2])
+      __THROW __nonnull ((1));
++#endif
+ 
++#ifdef __USE_BSD
+ /* Same as `utimes', but takes an open file descriptor instead of a name.  */
+ extern int futimes (int __fd, __const struct timeval __tvp[2]) __THROW;
+ #endif
+--- /dev/null	2009-08-01 20:56:12.000000000 -0500
++++ uClibc2/libc/sysdeps/linux/common/futimes.c	2009-11-14 04:53:49.000000000 -0600
+@@ -0,0 +1,33 @@
++/* vi: set sw=4 ts=4: */
++/*
++ * futimes() for uClibc
++ *
++ * Copyright (C) 2009 Rob Landley <rob@landley.net>
++ *
++ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
++ */
++
++#include <sys/syscall.h>
++#include <utime.h>
++#include <sys/time.h>
++
++#ifdef __NR_utimensat
++libc_hidden_proto(futimes)
++
++int futimes(const int fd, const struct timeval tvp[2])
++{
++	struct timespec ts[2], *pts = ts;
++
++	/* Convert timeval to timespec, for syscall */
++
++	if (tvp) {
++		TIMEVAL_TO_TIMESPEC(tvp, ts);
++		TIMEVAL_TO_TIMESPEC(tvp+1, ts+1);
++	} else pts = 0;
++
++	/* Make syscall */
++
++	return INLINE_SYSCALL(utimensat, 4, fd, 0, pts, 0);
++}
++libc_hidden_def(futimes)
++#endif