Commit 8c774fdd authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-shmem_custom_path'

Allow wrs_dump_shmem and wr_mon to work on binary dumps of shmem.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parents 3521d348 84ade34e
......@@ -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,15 @@ 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);
/* Allow to ignore the flag WRS_SHM_LOCKED
* If this flag is not ignored then function wrs_shm_get_and_check is not able
* to open shmem successfully due to lack of process running with the given pid
*/
void wrs_shm_ignore_flag_locked(int ignore_flag);
/* 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,30 @@
#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;
static int wrs_shm_locked = WRS_SHM_LOCKED;
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path)
{
strncpy(wrs_shm_path, new_path, 50);
}
/* Allow to ignore the flag WRS_SHM_LOCKED
* If this flag is not ignored then function wrs_shm_get_and_check is not able
* to open shmem successfully due to lack of process running with the given pid
*/
void wrs_shm_ignore_flag_locked(int ignore_flag)
{
if (ignore_flag)
wrs_shm_locked = 0;
else
wrs_shm_locked = WRS_SHM_LOCKED;
}
/* 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 +53,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 */
......@@ -52,7 +75,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
if (!write_access) {
/* This is a reader: if locked, wait for a writer */
if (!(flags & WRS_SHM_LOCKED))
if (!(flags & wrs_shm_locked))
return map;
tv1 = get_monotonic_tics();
......@@ -87,7 +110,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
head->stamp = 0;
head->data_off = sizeof(*head);
head->data_size = 0;
if (flags & WRS_SHM_LOCKED)
if (flags & wrs_shm_locked)
head->sequence = 1; /* a sort of lock */
else
head->sequence = 0;
......
......@@ -54,6 +54,8 @@ static struct hal_temp_sensors temp_sensors_local;
static uint64_t seconds;
static uint32_t nanoseconds;
/* ignore checking if process is alive */
static int ignore_alive;
void help(char *prgname)
{
......@@ -72,6 +74,7 @@ void help(char *prgname)
" -a show all (same as -i -m -s -o -e -t options)\n"
" -b black and white output\n"
" -w web interface mode\n"
" -H <dir> Open shmem dumps from the given directory\n"
"\n"
"During execution the user can enter 'q' to exit the program\n"
"and 't' to toggle printing of state information on/off\n");
......@@ -524,8 +527,10 @@ void show_all(void)
__GIT_VER__);
}
hal_alive = (hal_head->pid && (kill(hal_head->pid, 0) == 0));
ppsi_alive = (ppsi_head->pid && (kill(ppsi_head->pid, 0) == 0));
hal_alive = (hal_head->pid && (kill(hal_head->pid, 0) == 0))
+ ignore_alive;
ppsi_alive = (ppsi_head->pid && (kill(ppsi_head->pid, 0) == 0))
+ ignore_alive;
if (mode & SHOW_WR_TIME) {
if (ppsi_alive)
......@@ -574,7 +579,7 @@ int main(int argc, char *argv[])
wrs_msg_init(argc, argv);
while ((opt = getopt(argc, argv, "himsoetabwqv")) != -1) {
while ((opt = getopt(argc, argv, "himsoetabwqvH:")) != -1) {
switch(opt)
{
case 'h':
......@@ -606,6 +611,12 @@ int main(int argc, char *argv[])
case 'w':
mode |= WEB_INTERFACE;
break;
case 'H':
wrs_shm_set_path(optarg);
/* ignore WRS_SHM_LOCKED flag */
wrs_shm_ignore_flag_locked(1);
ignore_alive = 1;
break;
case 'q': break; /* done in wrs_msg_init() */
case 'v': break; /* done in wrs_msg_init() */
default:
......
......@@ -675,6 +675,7 @@ void print_info(char *prgname)
" -a Dump all rtu entries. By default only valid\n"
" entries are printed. Note there are 2048 htab\n"
" and 4096 vlan entries!\n"
" -H <dir> Open shmem dumps from the given directory\n"
" -h Show this message\n");
}
......@@ -687,11 +688,14 @@ int main(int argc, char **argv)
int i;
int c;
while ((c = getopt(argc, argv, "ah")) != -1) {
while ((c = getopt(argc, argv, "ahH:")) != -1) {
switch (c) {
case 'a':
dump_all_rtu_entries = 1;
break;
case 'H':
wrs_shm_set_path(optarg);
break;
case 'h':
default:
print_info(argv[0]);
......
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