Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/lib/librt Pull up following revision(s) (requested by mar...
details: https://anonhg.NetBSD.org/src/rev/c3c2b2ce42b3
branches: netbsd-7
changeset: 799866:c3c2b2ce42b3
user: snj <snj%NetBSD.org@localhost>
date: Tue Mar 22 09:04:19 2016 +0000
description:
Pull up following revision(s) (requested by martin in ticket #1144):
lib/librt/shm.c: revisions 1.2, 1.3
Allow /var/shm to be a symlink to a properly set up directory.
--
Simplify previous by just doing an open() on the directory and then using
the fstat* family to test for all relevant details.
Clean up buffer sizes and clarify a length check. Based on input from dholland.
diffstat:
lib/librt/shm.c | 51 ++++++++++++++++++++++++++++-----------------------
1 files changed, 28 insertions(+), 23 deletions(-)
diffs (111 lines):
diff -r 53c6f5c7ffb9 -r c3c2b2ce42b3 lib/librt/shm.c
--- a/lib/librt/shm.c Sun Mar 13 12:16:40 2016 +0000
+++ b/lib/librt/shm.c Tue Mar 22 09:04:19 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: shm.c,v 1.1 2013/12/19 19:11:50 rmind Exp $ */
+/* $NetBSD: shm.c,v 1.1.6.1 2016/03/22 09:04:19 snj Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: shm.c,v 1.1 2013/12/19 19:11:50 rmind Exp $");
+__RCSID("$NetBSD: shm.c,v 1.1.6.1 2016/03/22 09:04:19 snj Exp $");
#include <sys/mman.h>
#include <sys/mount.h>
@@ -57,31 +57,36 @@
#define MOUNT_SHMFS MOUNT_TMPFS
-static const char * _shmfs_path = NULL;
+static bool shm_ok = false;
static bool
_shm_check_fs(void)
{
- const char *shmfs = SHMFS_DIR_PATH;
+ int fd;
struct statvfs sv;
struct stat st;
- if (statvfs1(shmfs, &sv, ST_NOWAIT) == -1) {
+ fd = open(SHMFS_DIR_PATH, O_DIRECTORY|O_RDONLY);
+ if (fd == -1)
return false;
- }
- if (strncmp(sv.f_fstypename, MOUNT_SHMFS, sizeof(sv.f_fstypename))) {
- return false;
- }
+
+ if (fstatvfs1(fd, &sv, ST_NOWAIT) == -1)
+ goto out;
+
+ if (strncmp(sv.f_fstypename, MOUNT_SHMFS, sizeof(sv.f_fstypename)))
+ goto out;
- if (lstat(shmfs, &st) == -1) {
- return false;
- }
- if ((st.st_mode & SHMFS_DIR_MODE) != SHMFS_DIR_MODE) {
- return false;
- }
+ if (fstat(fd, &st) == -1)
+ goto out;
+
+ if ((st.st_mode & SHMFS_DIR_MODE) != SHMFS_DIR_MODE)
+ goto out;
- _shmfs_path = shmfs;
- return true;
+ shm_ok = true;
+
+out:
+ close(fd);
+ return shm_ok;
}
static bool
@@ -89,7 +94,7 @@
{
int ret;
- if (__predict_false(!_shmfs_path) && !_shm_check_fs()) {
+ if (__predict_false(!shm_ok) && !_shm_check_fs()) {
errno = ENOTSUP;
return false;
}
@@ -103,10 +108,10 @@
return false;
}
- ret = snprintf(buf, len, "%s/%s%s",
- _shmfs_path, SHMFS_OBJ_PREFIX, name);
+ ret = snprintf(buf, len, SHMFS_DIR_PATH "/" SHMFS_OBJ_PREFIX "%s",
+ name);
- if ((size_t)ret >= PATH_MAX) {
+ if ((size_t)ret >= len) {
errno = ENAMETOOLONG;
return false;
}
@@ -116,7 +121,7 @@
int
shm_open(const char *name, int oflag, mode_t mode)
{
- char path[PATH_MAX + 1];
+ char path[PATH_MAX];
if (!_shm_get_path(path, sizeof(path), name)) {
return -1;
@@ -127,7 +132,7 @@
int
shm_unlink(const char *name)
{
- char path[PATH_MAX + 1];
+ char path[PATH_MAX];
if (!_shm_get_path(path, sizeof(path), name)) {
return -1;
Home |
Main Index |
Thread Index |
Old Index