General function to use for sending signals for data collection from ptp4l program.
Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- snmpd.c | 37 +++++++++++++++++++++++++++++++++++++ snmpd_mib.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 snmpd_mib.h diff --git a/snmpd.c b/snmpd.c index 1718b07..bff31be 100644 --- a/snmpd.c +++ b/snmpd.c @@ -17,6 +17,9 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include <errno.h> +#include <poll.h> + #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> @@ -24,10 +27,44 @@ #include "config.h" #include "pmc_common.h" #include "print.h" +#include "snmpd_mib.h" #include "util.h" +#define SNMP_NFD 1 static struct pmc *pmc; +struct ptp_message* snmpd_run_pmc(char *cmd) +{ + struct pollfd pollfd[SNMP_NFD]; + int cnt, tmo = 100; + + pollfd[0].fd = pmc_get_transport_fd(pmc); + pollfd[0].events = POLLIN | POLLPRI; + + if (pmc_do_command(pmc, cmd)) { + pr_err("bad command: %s", cmd); + } + + while (is_running()) { + cnt = poll(pollfd, SNMP_NFD, tmo); + if (cnt < 0) { + if (EINTR == errno) { + continue; + } else { + pr_emerg("poll failed"); + break; + } + } else if (!cnt) { + break; + } + + if (pollfd[0].revents & (POLLIN|POLLPRI)) { + return pmc_recv(pmc); + } + } + return NULL; +} + static int open_pmc(struct config *cfg) { char uds_local[MAX_IFNAME_SIZE + 1]; diff --git a/snmpd_mib.h b/snmpd_mib.h new file mode 100644 index 0000000..fff4144 --- /dev/null +++ b/snmpd_mib.h @@ -0,0 +1,30 @@ +/** + * @file snmpd_mib.h + * @brief Common header file for all supported mibs in linuxptp + * @note Copyright (C) 2018 Anders Selhammer <anders.selham...@est.tech> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef SNMPDMIB_H +#define SNMPDMIB_H + +#include "msg.h" + +/* + * function declarations + */ +struct ptp_message* snmpd_run_pmc(char *cmd); + +#endif /* SNMPDMIB_H */ -- 1.8.3.1 --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel