firmware
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 Nov 18 18:36:53 2009 -0600 (9 months ago) |
| parents | 368cdbe5b0ee |
| children | a3ab17ecff3f |
| files | sources/patches/uClibc-add-shm.patch sources/patches/uClibc-futimes.patch |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sources/patches/uClibc-add-shm.patch Wed Nov 18 18:36:53 2009 -0600 1.3 @@ -0,0 +1,108 @@ 1.4 +librt/shm.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1.5 + 1 files changed, 98 insertions(+), 0 deletions(-) 1.6 + create mode 100644 librt/shm.c 1.7 + 1.8 +diff --git a/librt/shm.c b/librt/shm.c 1.9 +new file mode 100644 1.10 +index 0000000..637e945 1.11 +--- /dev/null 1.12 ++++ b/librt/shm.c 1.13 +@@ -0,0 +1,98 @@ 1.14 ++/* Copyright (C) 2009 Bernhard Reutner-Fischer <uclibc at uclibc.org> 1.15 ++ * 1.16 ++ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 1.17 ++ */ 1.18 ++ 1.19 ++#include <features.h> 1.20 ++#include <sys/types.h> 1.21 ++#include <sys/stat.h> 1.22 ++#include <fcntl.h> 1.23 ++#include <unistd.h> 1.24 ++#include <stdlib.h> 1.25 ++#include <stdio.h> 1.26 ++ 1.27 ++#ifndef O_CLOEXEC 1.28 ++#include <errno.h> 1.29 ++#endif 1.30 ++ 1.31 ++#ifndef _PATH_SHM 1.32 ++#define _PATH_SHM "/dev/shm/" 1.33 ++#endif 1.34 ++ 1.35 ++#ifndef NAME_MAX 1.36 ++#define NAME_MAX 255 1.37 ++#endif 1.38 ++ 1.39 ++/* Get name of dummy shm operation handle. 1.40 ++ * Returns a malloc'ed buffer containing the OS specific path 1.41 ++ * to the shm filename or NULL upon failure. 1.42 ++ */ 1.43 ++static __attribute_noinline__ char* get_shm_name(const char*name) __nonnull((1)); 1.44 ++static char* get_shm_name(const char*name) 1.45 ++{ 1.46 ++ char *path; 1.47 ++ int i; 1.48 ++ 1.49 ++ /* Skip leading slashes */ 1.50 ++ while (*name == '/') 1.51 ++ ++name; 1.52 ++#ifdef __USE_GNU 1.53 ++ i = asprintf(&path, _PATH_SHM "%s", name); 1.54 ++ if (i < 0) 1.55 ++ return NULL; 1.56 ++#else 1.57 ++ path = malloc(NAME_MAX); 1.58 ++ if (path == NULL) 1.59 ++ return NULL; 1.60 ++ i = snprintf(path, NAME_MAX, _PATH_SHM "%s", name); 1.61 ++ if (i < 0) { 1.62 ++ free(path); 1.63 ++ return NULL; 1.64 ++ } 1.65 ++#endif 1.66 ++ return path; 1.67 ++} 1.68 ++ 1.69 ++int shm_open(const char *name, int oflag, mode_t mode) 1.70 ++{ 1.71 ++ int fd, old_errno; 1.72 ++ char *shm_name = get_shm_name(name); 1.73 ++ 1.74 ++ /* Stripped multiple '/' from start; may have set errno properly */ 1.75 ++ if (shm_name == NULL) 1.76 ++ return -1; 1.77 ++ /* The FD_CLOEXEC file descriptor flag associated with the new 1.78 ++ * file descriptor is set. */ 1.79 ++#ifdef O_CLOEXEC 1.80 ++ /* Just open it with CLOEXEC set, for brevity */ 1.81 ++ fd = open(shm_name, oflag | O_CLOEXEC, mode); 1.82 ++#else 1.83 ++ fd = open(shm_name, oflag, mode); 1.84 ++ if (fd >= 0) { 1.85 ++ int fdflags = fcntl(fd, F_GETFD, 0); 1.86 ++ if (fdflags >= 0) 1.87 ++ fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); 1.88 ++ if (fdflags < 0) { 1.89 ++ close(fd); 1.90 ++ fd = -1; 1.91 ++ } 1.92 ++ } 1.93 ++#endif 1.94 ++ old_errno = errno; 1.95 ++ free(shm_name); 1.96 ++ errno = old_errno; 1.97 ++ return fd; 1.98 ++} 1.99 ++ 1.100 ++int shm_unlink(const char *name) 1.101 ++{ 1.102 ++ char *shm_name = get_shm_name(name); 1.103 ++ int ret; 1.104 ++ 1.105 ++ /* Stripped multiple '/' from start; may have set errno properly */ 1.106 ++ if (shm_name == NULL) 1.107 ++ return -1; 1.108 ++ ret = unlink(shm_name); 1.109 ++ free(shm_name); 1.110 ++ return ret; 1.111 ++}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/sources/patches/uClibc-futimes.patch Wed Nov 18 18:36:53 2009 -0600 2.3 @@ -0,0 +1,50 @@ 2.4 +User Mode Linux needs futimes(). 2.5 + 2.6 +--- uClibc/include/sys/time.h 2005-11-30 11:07:06.000000000 -0600 2.7 ++++ uClibc2/include/sys/time.h 2009-11-14 04:55:32.000000000 -0600 2.8 +@@ -143,7 +143,9 @@ 2.9 + /* Same as `utimes', but does not follow symbolic links. */ 2.10 + extern int lutimes (__const char *__file, __const struct timeval __tvp[2]) 2.11 + __THROW __nonnull ((1)); 2.12 ++#endif 2.13 + 2.14 ++#ifdef __USE_BSD 2.15 + /* Same as `utimes', but takes an open file descriptor instead of a name. */ 2.16 + extern int futimes (int __fd, __const struct timeval __tvp[2]) __THROW; 2.17 + #endif 2.18 +--- /dev/null 2009-08-01 20:56:12.000000000 -0500 2.19 ++++ uClibc2/libc/sysdeps/linux/common/futimes.c 2009-11-14 04:53:49.000000000 -0600 2.20 +@@ -0,0 +1,33 @@ 2.21 ++/* vi: set sw=4 ts=4: */ 2.22 ++/* 2.23 ++ * futimes() for uClibc 2.24 ++ * 2.25 ++ * Copyright (C) 2009 Rob Landley <rob@landley.net> 2.26 ++ * 2.27 ++ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 2.28 ++ */ 2.29 ++ 2.30 ++#include <sys/syscall.h> 2.31 ++#include <utime.h> 2.32 ++#include <sys/time.h> 2.33 ++ 2.34 ++#ifdef __NR_utimensat 2.35 ++libc_hidden_proto(futimes) 2.36 ++ 2.37 ++int futimes(const int fd, const struct timeval tvp[2]) 2.38 ++{ 2.39 ++ struct timespec ts[2], *pts = ts; 2.40 ++ 2.41 ++ /* Convert timeval to timespec, for syscall */ 2.42 ++ 2.43 ++ if (tvp) { 2.44 ++ TIMEVAL_TO_TIMESPEC(tvp, ts); 2.45 ++ TIMEVAL_TO_TIMESPEC(tvp+1, ts+1); 2.46 ++ } else pts = 0; 2.47 ++ 2.48 ++ /* Make syscall */ 2.49 ++ 2.50 ++ return INLINE_SYSCALL(utimensat, 4, fd, 0, pts, 0); 2.51 ++} 2.52 ++libc_hidden_def(futimes) 2.53 ++#endif
