shmpipe: Simplify handling of random paths
This commit is contained in:
parent
23414310a6
commit
8f8b50a88e
@ -224,7 +224,6 @@ sp_open_shm (char *path, int id, int writer, mode_t perms, size_t size)
|
|||||||
ShmArea *area = spalloc_new (ShmArea);
|
ShmArea *area = spalloc_new (ShmArea);
|
||||||
char tmppath[PATH_MAX];
|
char tmppath[PATH_MAX];
|
||||||
int flags;
|
int flags;
|
||||||
int has_path = (path != NULL) ? 1 : 0;
|
|
||||||
int prot;
|
int prot;
|
||||||
|
|
||||||
memset (area, 0, sizeof (ShmArea));
|
memset (area, 0, sizeof (ShmArea));
|
||||||
@ -240,25 +239,24 @@ sp_open_shm (char *path, int id, int writer, mode_t perms, size_t size)
|
|||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
|
|
||||||
area->shm_fd = -1;
|
area->shm_fd = -1;
|
||||||
if (!path)
|
|
||||||
path = tmppath;
|
|
||||||
|
|
||||||
do {
|
if (path) {
|
||||||
if (path == tmppath) {
|
area->shm_fd = shm_open (path, flags, perms);
|
||||||
path = tmppath;
|
} else {
|
||||||
|
do {
|
||||||
snprintf (tmppath, PATH_MAX, "/%X%X%X%X%X.shmpipe",
|
snprintf (tmppath, PATH_MAX, "/%X%X%X%X%X.shmpipe",
|
||||||
rand (), rand (), rand (), rand (), rand ());
|
rand (), rand (), rand (), rand (), rand ());
|
||||||
}
|
area->shm_fd = shm_open (tmppath, flags, perms);
|
||||||
area->shm_fd = shm_open (path, flags, perms);
|
} while (area->shm_fd < 0 && errno == EEXIST);
|
||||||
} while (path == tmppath && area->shm_fd < 0 && errno == EEXIST);
|
|
||||||
|
|
||||||
if (area->shm_fd < 0) {
|
|
||||||
RETURN_ERROR ("shm_open failed on %s (%d): %s\n", path, errno,
|
|
||||||
strerror (errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_path)
|
if (area->shm_fd < 0) {
|
||||||
area->shm_area_name = strdup (path);
|
RETURN_ERROR ("shm_open failed on %s (%d): %s\n",
|
||||||
|
path ? path : tmppath, errno, strerror (errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
area->shm_area_name = strdup (tmppath);
|
||||||
|
|
||||||
if (writer) {
|
if (writer) {
|
||||||
if (ftruncate (area->shm_fd, size)) {
|
if (ftruncate (area->shm_fd, size)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user