version 1.2, 2015/06/30 11:46:47 |
version 1.3, 2015/07/08 07:14:38 |
Line 57 __RCSID("$NetBSD$"); |
|
Line 57 __RCSID("$NetBSD$"); |
|
|
|
#define MOUNT_SHMFS MOUNT_TMPFS |
#define MOUNT_SHMFS MOUNT_TMPFS |
|
|
static const char * _shmfs_path = NULL; |
static bool shm_ok = false; |
static char _shmfs_path_buf[PATH_MAX]; |
|
|
|
static bool |
static bool |
_shm_check_fs(void) |
_shm_check_fs(void) |
{ |
{ |
const char *shmfs = SHMFS_DIR_PATH; |
int fd; |
struct statvfs sv; |
struct statvfs sv; |
struct stat st; |
struct stat st; |
char buf[PATH_MAX]; |
|
ssize_t cnt; |
|
|
|
if ((cnt = readlink(shmfs, buf, sizeof(buf))) > 0) { |
fd = open(SHMFS_DIR_PATH, O_DIRECTORY|O_RDONLY); |
if ((size_t)cnt >= sizeof(buf)) |
if (fd == -1) |
return false; |
|
buf[cnt] = 0; |
|
shmfs = buf; |
|
} |
|
if (statvfs1(shmfs, &sv, ST_NOWAIT) == -1) { |
|
return false; |
|
} |
|
if (strncmp(sv.f_fstypename, MOUNT_SHMFS, sizeof(sv.f_fstypename))) { |
|
return false; |
return false; |
} |
|
|
|
if (lstat(shmfs, &st) == -1) { |
if (fstatvfs1(fd, &sv, ST_NOWAIT) == -1) |
return false; |
goto out; |
} |
|
if ((st.st_mode & SHMFS_DIR_MODE) != SHMFS_DIR_MODE) { |
|
return false; |
|
} |
|
|
|
if (shmfs == buf) { |
if (strncmp(sv.f_fstypename, MOUNT_SHMFS, sizeof(sv.f_fstypename))) |
strcpy(_shmfs_path_buf, buf); |
goto out; |
_shmfs_path = _shmfs_path_buf; |
|
} else { |
if (fstat(fd, &st) == -1) |
_shmfs_path = shmfs; |
goto out; |
} |
|
return true; |
if ((st.st_mode & SHMFS_DIR_MODE) != SHMFS_DIR_MODE) |
|
goto out; |
|
|
|
shm_ok = true; |
|
|
|
out: |
|
close(fd); |
|
return shm_ok; |
} |
} |
|
|
static bool |
static bool |
Line 103 _shm_get_path(char *buf, size_t len, con |
|
Line 94 _shm_get_path(char *buf, size_t len, con |
|
{ |
{ |
int ret; |
int ret; |
|
|
if (__predict_false(!_shmfs_path) && !_shm_check_fs()) { |
if (__predict_false(!shm_ok) && !_shm_check_fs()) { |
errno = ENOTSUP; |
errno = ENOTSUP; |
return false; |
return false; |
} |
} |
Line 117 _shm_get_path(char *buf, size_t len, con |
|
Line 108 _shm_get_path(char *buf, size_t len, con |
|
return false; |
return false; |
} |
} |
|
|
ret = snprintf(buf, len, "%s/%s%s", |
ret = snprintf(buf, len, SHMFS_DIR_PATH "/" SHMFS_OBJ_PREFIX "%s", |
_shmfs_path, SHMFS_OBJ_PREFIX, name); |
name); |
|
|
if ((size_t)ret >= PATH_MAX) { |
if ((size_t)ret >= len) { |
errno = ENAMETOOLONG; |
errno = ENAMETOOLONG; |
return false; |
return false; |
} |
} |
Line 130 _shm_get_path(char *buf, size_t len, con |
|
Line 121 _shm_get_path(char *buf, size_t len, con |
|
int |
int |
shm_open(const char *name, int oflag, mode_t mode) |
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)) { |
if (!_shm_get_path(path, sizeof(path), name)) { |
return -1; |
return -1; |
Line 141 shm_open(const char *name, int oflag, mo |
|
Line 132 shm_open(const char *name, int oflag, mo |
|
int |
int |
shm_unlink(const char *name) |
shm_unlink(const char *name) |
{ |
{ |
char path[PATH_MAX + 1]; |
char path[PATH_MAX]; |
|
|
if (!_shm_get_path(path, sizeof(path), name)) { |
if (!_shm_get_path(path, sizeof(path), name)) { |
return -1; |
return -1; |