From 6075b68ea0e7a64aad39da0fcaf81d24b73c8192 Mon Sep 17 00:00:00 2001
From: Adam Wujek <adam.wujek@cern.ch>
Date: Mon, 13 Apr 2015 11:21:33 +0200
Subject: [PATCH] userspace/snmpd: add possibility of reading dot-config

use libwr's interface for dot-config

Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
---
 userspace/snmpd/Makefile     | 1 +
 userspace/snmpd/dot-config.c | 1 +
 userspace/snmpd/init.c       | 8 ++++++++
 3 files changed, 10 insertions(+)
 create mode 120000 userspace/snmpd/dot-config.c

diff --git a/userspace/snmpd/Makefile b/userspace/snmpd/Makefile
index 30b4a00dd..640dd9d58 100644
--- a/userspace/snmpd/Makefile
+++ b/userspace/snmpd/Makefile
@@ -26,6 +26,7 @@ CFLAGS += -DWRS_WITH_SNMP_HACKISH_LOG=0
 SHLIB = wrsSnmp.so
 SOURCES = \
 	shmem.c \
+	dot-config.c \
 	snmp_shmem.c \
 	snmp_mmap.c \
 	wrsScalar.c \
diff --git a/userspace/snmpd/dot-config.c b/userspace/snmpd/dot-config.c
new file mode 120000
index 000000000..5607b5f22
--- /dev/null
+++ b/userspace/snmpd/dot-config.c
@@ -0,0 +1 @@
+../libwr/dot-config.c
\ No newline at end of file
diff --git a/userspace/snmpd/init.c b/userspace/snmpd/init.c
index d994d3128..1b4f22287 100644
--- a/userspace/snmpd/init.c
+++ b/userspace/snmpd/init.c
@@ -8,6 +8,7 @@
 /* The sub-init functions */
 #include "wrsSnmp.h"
 #include "snmp_shmem.h"
+#include "libwr/config.h"
 #include "wrsGeneralStatusGroup.h"
 #include "wrsOSStatusGroup.h"
 #include "wrsNetworkingStatusGroup.h"
@@ -21,12 +22,19 @@
 #include "wrsPtpDataTable.h"
 #include "wrsPortStatusTable.h"
 
+#define DOTCONFIG_FILE "/wr/etc/dot-config"
 
 FILE *wrs_logf; /* for the local-hack messages */
 
 void init_wrsSnmp(void)
 {
 	init_shm();
+	if (libwr_cfg_read_file(DOTCONFIG_FILE)) {
+		/* unable to read dot-config,
+		 * don't crash SNMPd, it will be reported in SNMP objects */
+		snmp_log(LOG_ERR, "SNMP: unable to read dot-config file %s\n",
+			 DOTCONFIG_FILE);
+	}
 	init_wrsScalar();
 	init_wrsGeneralStatusGroup();
 	init_wrsOSStatusGroup();
-- 
GitLab