Commit 72b8cdfd authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: allow custom path for shmem files

It allows to analyze shmem dumps with existing programs.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 3521d348
......@@ -6,7 +6,8 @@
#define __WRS_SHM_H__
#include <stdint.h>
#define WRS_SHM_FILE "/dev/shm/wrs-shmem-%i"
#define WRS_SHM_DEFAULT_PATH "/dev/shm"
#define WRS_SHM_FILE "wrs-shmem-%i"
#define WRS_SHM_MIN_SIZE (4*1024)
#define WRS_SHM_MAX_SIZE (512*1024)
......@@ -40,6 +41,9 @@ struct wrs_shm_head {
#define WRS_SHM_WRITE 0x0001
#define WRS_SHM_LOCKED 0x0002 /* at init time: writers locks, readers wait */
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path);
/* get vs. put, like in the kernel. Errors are in errno (see source) */
void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags);
int wrs_shm_put(void *headptr);
......
......@@ -12,7 +12,17 @@
#include <libwr/shmem.h>
#include <libwr/util.h>
#define SHM_LOCK_TIMEOUT_MS 50 /* in ms */
static char wrs_shm_path[50] = WRS_SHM_DEFAULT_PATH;
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path)
{
strncpy(wrs_shm_path, new_path, 50);
}
/* Get wrs shared memory */
/* return NULL and set errno on error */
void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
......@@ -30,7 +40,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
return NULL;
}
sprintf(fname, WRS_SHM_FILE, name_id);
sprintf(fname, "%.50s/"WRS_SHM_FILE, wrs_shm_path, name_id);
fd = open(fname, O_RDWR | O_CREAT | O_SYNC, 0644);
if (fd < 0)
return NULL; /* keep errno */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment