@@ -48,6 +48,7 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
@@ -57,8 +58,9 @@
#include <sys/mman.h>
#include <sys/wait.h>
-#define FDSERVER_SOCKPATH_MAXLEN 32
-#define FDSERVER_SOCKPATH_FORMAT "/dev/shm/odp-%d-fdserver"
+#define FDSERVER_SOCKPATH_MAXLEN 255
+#define FDSERVER_SOCK_FORMAT "/dev/shm/%s/odp-%d-fdserver"
+#define FDSERVER_SOCKDIR_FORMAT "/dev/shm/%s"
#define FDSERVER_BACKLOG 5
#ifndef MAP_ANONYMOUS
@@ -238,7 +240,8 @@ static int get_socket(void)
int len;
/* construct the named socket path: */
- snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT,
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+ odp_global_data.uid,
odp_global_data.main_pid);
s_sock = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -581,8 +584,14 @@ int _odp_fdserver_init_global(void)
odp_spinlock_init(client_lock);
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT,
+ odp_global_data.uid);
+
+ mkdir(sockpath, 0744);
+
/* construct the server named socket path: */
- snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT,
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+ odp_global_data.uid,
odp_global_data.main_pid);
/* create UNIX domain socket: */
@@ -663,11 +672,17 @@ int _odp_fdserver_term_global(void)
wait(&status);
/* construct the server named socket path: */
- snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKPATH_FORMAT,
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+ odp_global_data.uid,
odp_global_data.main_pid);
/* delete the UNIX domain socket: */
unlink(sockpath);
+ /* delete shm files directory */
+ snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT,
+ odp_global_data.uid);
+ unlink(sockpath);
+
return 0;
}
@@ -86,7 +86,7 @@
* Maximum internal shared memory block name length in chars
* probably taking the same number as SHM name size make sense at this stage
*/
-#define ISHM_NAME_MAXLEN 32
+#define ISHM_NAME_MAXLEN 128
/*
* Linux underlying file name: <directory>/odp-<odp_pid>-ishm-<name>
@@ -106,7 +106,7 @@
* export file is created describing the exported memory: this defines the
* location and the filename format of this description file
*/
-#define ISHM_EXPTNAME_FORMAT "/dev/shm/odp-%d-shm-%s"
+#define ISHM_EXPTNAME_FORMAT "/dev/shm/%s/odp-%d-shm-%s"
/*
* At worse case the virtual space gets so fragmented that there is
@@ -417,6 +417,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
* /mnt/huge */
int oflag = O_RDWR | O_CREAT | O_TRUNC; /* flags for open */
FILE *export_file;
+ char dir[ISHM_FILENAME_MAXLEN];
new_block = &ishm_tbl->block[block_index];
name = new_block->name;
@@ -431,17 +432,21 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
return -1;
if (huge == HUGE)
- snprintf(filename, ISHM_FILENAME_MAXLEN,
- ISHM_FILENAME_FORMAT,
+ snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s",
odp_global_data.hugepage_info.default_huge_page_dir,
- odp_global_data.main_pid,
- (name && name[0]) ? name : seq_string);
+ odp_global_data.uid);
else
- snprintf(filename, ISHM_FILENAME_MAXLEN,
- ISHM_FILENAME_FORMAT,
+ snprintf(dir, ISHM_FILENAME_MAXLEN, "%s/%s",
ISHM_FILENAME_NORMAL_PAGE_DIR,
- odp_global_data.main_pid,
- (name && name[0]) ? name : seq_string);
+ odp_global_data.uid);
+
+ snprintf(filename, ISHM_FILENAME_MAXLEN,
+ ISHM_FILENAME_FORMAT,
+ dir,
+ odp_global_data.main_pid,
+ (name && name[0]) ? name : seq_string);
+
+ mkdir(dir, 0744);
fd = open(filename, oflag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
@@ -471,6 +476,7 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
ISHM_FILENAME_MAXLEN - 1);
snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN,
ISHM_EXPTNAME_FORMAT,
+ odp_global_data.uid,
odp_global_data.main_pid,
(name && name[0]) ? name : seq_string);
export_file = fopen(new_block->exptname, "w");
@@ -949,6 +955,7 @@ int _odp_ishm_find_exported(const char *remote_name, pid_t external_odp_pid,
/* try to read the block description file: */
snprintf(export_filename, ISHM_FILENAME_MAXLEN,
ISHM_EXPTNAME_FORMAT,
+ odp_global_data.uid,
external_odp_pid,
remote_name);
@@ -25,6 +25,7 @@ extern "C" {
#include <sys/types.h>
#define MAX_CPU_NUMBER 128
+#define UID_MAXLEN 30
typedef struct {
uint64_t cpu_hz_max[MAX_CPU_NUMBER];
@@ -42,6 +43,7 @@ typedef struct {
struct odp_global_data_s {
pid_t main_pid;
+ char uid[UID_MAXLEN];
odp_log_func_t log_fn;
odp_abort_func_t abort_fn;
system_info_t system_info;
@@ -17,6 +17,8 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <sys/types.h>
+#include <pwd.h>
#define _ODP_FILES_FMT "odp-%d-"
#define _ODP_TMPDIR "/dev/shm"
@@ -28,13 +30,16 @@ static int cleanup_files(const char *dirpath, int odp_pid)
{
struct dirent *e;
DIR *dir;
+ char userdir[PATH_MAX];
char prefix[PATH_MAX];
char *fullpath;
int d_len = strlen(dirpath);
int p_len;
int f_len;
- dir = opendir(dirpath);
+ snprintf(userdir, PATH_MAX, "%s/%s", dirpath, odp_global_data.uid);
+
+ dir = opendir(userdir);
if (!dir) {
/* ok if the dir does not exist. no much to delete then! */
ODP_DBG("opendir failed for %s: %s\n",
@@ -70,10 +75,15 @@ int odp_init_global(odp_instance_t *instance,
const odp_platform_init_t *platform_params ODP_UNUSED)
{
char *hpdir;
+ uid_t uid;
memset(&odp_global_data, 0, sizeof(struct odp_global_data_s));
odp_global_data.main_pid = getpid();
+ uid = getuid();
+ snprintf(odp_global_data.uid, UID_MAXLEN, "%d",
+ uid);
+
enum init_stage stage = NO_INIT;
odp_global_data.log_fn = odp_override_log;
odp_global_data.abort_fn = odp_override_abort;
@@ -8,7 +8,7 @@
#define _COMMON_TEST_SHMEM_H_
#define ODP_SHM_NAME "odp_linux_shared_mem"
-#define FIFO_NAME_FMT "/tmp/shmem_test_fifo-%d"
+#define FIFO_NAME_FMT "/dev/shm/%d/shmem_test_fifo-%d"
#define ALIGN_SIZE (128)
#define TEST_SHARE_FOO (0xf0f0f0f0)
#define TEST_SHARE_BAR (0xf0f0f0f)
@@ -8,7 +8,7 @@
* flag is visible under linux, and checks that memory created with the
* ODP_SHM_EXPORT flag is visible by other ODP instances.
* It therefore checks both that the link
- * name under /tmp is correct, and also checks that the memory contents
+ * name under /dev/shm is correct, and also checks that the memory contents
* is indeed shared.
* we want:
* -the odp test to run using C UNIT
@@ -69,6 +69,7 @@
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include <linux/limits.h>
#include <stdio.h>
@@ -77,12 +78,14 @@
#include <libgen.h>
#include <linux/limits.h>
#include <inttypes.h>
+#include <pwd.h>
#include "shmem_linux.h"
#include "shmem_common.h"
#define ODP_APP1_NAME "shmem_odp1" /* name of the odp1 program, in this dir */
#define ODP_APP2_NAME "shmem_odp2" /* name of the odp2 program, in this dir */
-#define DEVNAME_FMT "/tmp/odp-%" PRIu64 "-shm-%s" /* odp-<pid>-shm-<name> */
+/* odp-<pid>-shm-<name> */
+#define DEVNAME_FMT "/dev/shm/%d/odp-%" PRIu64 "-shm-%s"
#define MAX_FIFO_WAIT 30 /* Max time waiting for the fifo (sec) */
/*
@@ -108,7 +111,8 @@ static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname,
char shm_attr_filename[PATH_MAX];
FILE *export_file;
- sprintf(shm_attr_filename, DEVNAME_FMT, ext_odp_pid, blockname);
+ sprintf(shm_attr_filename, DEVNAME_FMT, getuid(),
+ ext_odp_pid, blockname);
/* O_CREAT flag not given => failure if shm_attr_filename does not
* already exist */
@@ -205,6 +209,7 @@ int main(int argc __attribute__((unused)), char *argv[])
int shm_fd;
test_shared_linux_data_t *addr;
int app2_status;
+ uid_t uid = getuid();
/* odp_app1 is in the same directory as this file: */
strncpy(prg_name, argv[0], PATH_MAX - 1);
@@ -223,7 +228,7 @@ int main(int argc __attribute__((unused)), char *argv[])
/* wait max 30 sec for the fifo to be created by the ODP side.
* Just die if time expire as there is no fifo to communicate
* through... */
- sprintf(fifo_name, FIFO_NAME_FMT, odp_app1);
+ sprintf(fifo_name, FIFO_NAME_FMT, uid, odp_app1);
for (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {
fifo_fd = open(fifo_name, O_WRONLY);
if (fifo_fd >= 0)
@@ -244,7 +249,7 @@ int main(int argc __attribute__((unused)), char *argv[])
&user_len, &user_flags, &align) != 0)
test_failure(fifo_name, fifo_fd, odp_app1);
- /* open the shm filename (which is either on /tmp or on hugetlbfs)
+ /* open the shm filename (which is either on /dev/shm/ or on hugetlbfs)
* O_CREAT flag not given => failure if shm_devname does not already
* exist */
shm_fd = open(shm_filename, O_RDONLY,
@@ -41,7 +41,7 @@ void shmem_test_odp_shm_proc(void)
/* open the fifo: this will indicate to linux process that it can
* start the shmem lookups and check if it sees the data */
- sprintf(fifo_name, FIFO_NAME_FMT, getpid());
+ sprintf(fifo_name, FIFO_NAME_FMT, getuid(), getpid());
CU_ASSERT_FATAL(mkfifo(fifo_name, 0666) == 0);
/* read from the fifo: the linux process result: */