Commit cb42b967 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: allow snmpd to start without RTUd

Make possible to start snmpd without successful open of RTUd's shmem
(in other words having RTUd running). SNMPd shall start even on faulty system
since it is a way to report if and what is wrong.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent c380ffc0
...@@ -17,6 +17,8 @@ int *ppsi_ppi_nlinks; ...@@ -17,6 +17,8 @@ int *ppsi_ppi_nlinks;
/* RTUd */ /* RTUd */
struct wrs_shm_head *rtud_head; struct wrs_shm_head *rtud_head;
int shmem_open_rtud;
static void init_shm_hal(void) static void init_shm_hal(void)
{ {
int ret; int ret;
...@@ -110,26 +112,25 @@ static void init_shm_ppsi(void) ...@@ -110,26 +112,25 @@ static void init_shm_ppsi(void)
ppsi_ppi_nlinks = &(ppg->nlinks); ppsi_ppi_nlinks = &(ppg->nlinks);
} }
static void init_shm_rtud(void) static int init_shm_rtud(void)
{ {
int ret; int ret;
int n_wait = 0; static int n_wait = 0;
while ((ret = wrs_shm_get_and_check(wrs_shm_rtu, &rtud_head)) != 0) { ret = wrs_shm_get_and_check(wrs_shm_rtu, &rtud_head);
n_wait++; n_wait++;
if (n_wait > 10) { /* start printing error after 5 messages */
/* timeout! */ if (n_wait > 5) {
if (ret == 1) { if (ret == 1) {
snmp_log(LOG_ERR, "Unable to open shm for " snmp_log(LOG_ERR, "Unable to open shm for RTUd!\n");
"RTUd!\n");
}
if (ret == 2) {
snmp_log(LOG_ERR, "Unable to read RTUd's "
"version!\n");
}
exit(-1);
} }
sleep(1); if (ret == 2) {
snmp_log(LOG_ERR, "Unable to read RTUd's version!\n");
}
}
if (ret) {
/* return if error while opening shmem */
return ret;
} }
/* check rtud's shm version */ /* check rtud's shm version */
...@@ -137,12 +138,33 @@ static void init_shm_rtud(void) ...@@ -137,12 +138,33 @@ static void init_shm_rtud(void)
snmp_log(LOG_ERR, "unknown RTUd's shm version %i " snmp_log(LOG_ERR, "unknown RTUd's shm version %i "
"(known is %i)\n", rtud_head->version, "(known is %i)\n", rtud_head->version,
RTU_SHMEM_VERSION); RTU_SHMEM_VERSION);
exit(-1); return 3;
}
/* everything is ok */
return 0;
}
int shmem_ready_rtud(void)
{
if (shmem_open_rtud) {
return 1;
} }
shmem_open_rtud = !init_shm_rtud();
return shmem_open_rtud;
} }
void init_shm(void){ void init_shm(void){
int i;
init_shm_hal(); init_shm_hal();
init_shm_ppsi(); init_shm_ppsi();
init_shm_rtud(); for (i = 0; i < 10; i++) {
if (shmem_ready_rtud()) {
/* shmem opened successfully */
break;
}
/* wait 1 second before another try */
sleep(1);
}
} }
...@@ -23,5 +23,5 @@ extern int *ppsi_ppi_nlinks; ...@@ -23,5 +23,5 @@ extern int *ppsi_ppi_nlinks;
struct wrs_shm_head *rtud_head; struct wrs_shm_head *rtud_head;
void init_shm(); void init_shm();
int shmem_ready_rtud(void);
#endif /* WRS_SNMP_SHMEM_H */ #endif /* WRS_SNMP_SHMEM_H */
...@@ -55,7 +55,11 @@ time_t wrsStartCnt_data_fill(void){ ...@@ -55,7 +55,11 @@ time_t wrsStartCnt_data_fill(void){
/* get start counters from shmem's */ /* get start counters from shmem's */
wrsStartCnt_s.wrsStartCntHAL = hal_head->pidsequence; wrsStartCnt_s.wrsStartCntHAL = hal_head->pidsequence;
wrsStartCnt_s.wrsStartCntPTP = ppsi_head->pidsequence; wrsStartCnt_s.wrsStartCntPTP = ppsi_head->pidsequence;
wrsStartCnt_s.wrsStartCntRTUd = rtud_head->pidsequence; if (shmem_ready_rtud()) {
wrsStartCnt_s.wrsStartCntRTUd = rtud_head->pidsequence;
} else {
snmp_log(LOG_ERR, "Unable to read rtu's shmem\n");
}
read_start_count(START_CNT_SSHD, &wrsStartCnt_s.wrsStartCntSshd); read_start_count(START_CNT_SSHD, &wrsStartCnt_s.wrsStartCntSshd);
read_start_count(START_CNT_HTTPD, &wrsStartCnt_s.wrsStartCntHttpd); read_start_count(START_CNT_HTTPD, &wrsStartCnt_s.wrsStartCntHttpd);
......
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