From b0b1a79aa572ba31b3aaaf9a511191bdca5fdcde Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 26 Feb 2024 11:24:48 +0100 Subject: [PATCH] statd: refactor to autotools, same as confd Fix issue #299 Signed-off-by: Joachim Wiberg --- .../rootfs/libexec/infix/ethtool-to-json | 36 --------- package/statd/statd.mk | 13 +--- src/klish-plugin-infix/xml/infix.xml | 12 +-- src/statd/.gitignore | 25 ++++++ src/statd/Makefile | 27 ------- src/statd/Makefile.am | 13 ++++ src/statd/autogen.sh | 3 + .../libexec/infix => src/statd}/cli-pretty | 0 src/statd/configure.ac | 76 +++++++++++++++++++ .../libexec/infix => src/statd}/ospf-status | 0 src/statd/statd.c | 2 +- .../rootfs/libexec/infix => src/statd}/yanger | 2 +- test/case/cli/run.sh | 2 +- test/case/cli/sysrepo-emulator.sh | 2 +- test/case/cli_pretty/run.sh | 2 +- 15 files changed, 131 insertions(+), 84 deletions(-) delete mode 100755 board/netconf/rootfs/libexec/infix/ethtool-to-json delete mode 100644 src/statd/Makefile create mode 100644 src/statd/Makefile.am create mode 100755 src/statd/autogen.sh rename {board/netconf/rootfs/libexec/infix => src/statd}/cli-pretty (100%) create mode 100644 src/statd/configure.ac rename {board/netconf/rootfs/libexec/infix => src/statd}/ospf-status (100%) rename {board/netconf/rootfs/libexec/infix => src/statd}/yanger (99%) diff --git a/board/netconf/rootfs/libexec/infix/ethtool-to-json b/board/netconf/rootfs/libexec/infix/ethtool-to-json deleted file mode 100755 index 63c10969..00000000 --- a/board/netconf/rootfs/libexec/infix/ethtool-to-json +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess -import sys -import json - -def get_ethtool_output(interface): - try: - output = subprocess.check_output(['ethtool', interface], stderr=subprocess.DEVNULL, text=True) - return output.splitlines() - except subprocess.CalledProcessError: - print("Error: Failed to run ethtool on interface", interface) - sys.exit(1) - -def parse_ethtool_output(lines, keys): - result = {} - for line in lines: - line = line.strip() - key = line.split(':', 1)[0].strip() - if key in keys: - key, value = line.split(':', 1) - result[key.strip()] = value.strip() - return result - -if __name__ == "__main__": - if len(sys.argv) != 2: - print(f"Usage: {sys.argv[0]} INTERFACE") - sys.exit(1) - - interface = sys.argv[1] - keys = ["Duplex", "Auto-negotiation"] - - lines = get_ethtool_output(interface) - parsed_data = parse_ethtool_output(lines, keys) - - print(json.dumps(parsed_data, indent=4)) diff --git a/package/statd/statd.mk b/package/statd/statd.mk index a4257486..cfec0a3a 100644 --- a/package/statd/statd.mk +++ b/package/statd/statd.mk @@ -11,20 +11,13 @@ STATD_LICENSE = BSD-3-Clause STATD_LICENSE_FILES = LICENSE STATD_REDISTRIBUTE = NO STATD_DEPENDENCIES = sysrepo libev libsrx jansson +STATD_AUTORECONF = YES define STATD_CONF_ENV CFLAGS="$(INFIX_CFLAGS)" endef -define STATD_BUILD_CMDS - $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) \ - LDFLAGS="$(TARGET_LDFLAGS)" -endef - -define STATD_INSTALL_TARGET_CMDS - $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) \ - DESTDIR="$(TARGET_DIR)" install -endef +STATD_CONF_OPTS = --prefix= --disable-silent-rules define STATD_INSTALL_EXTRA cp $(STATD_PKGDIR)/statd.conf $(FINIT_D)/available/ @@ -32,4 +25,4 @@ define STATD_INSTALL_EXTRA endef STATD_TARGET_FINALIZE_HOOKS += STATD_INSTALL_EXTRA -$(eval $(generic-package)) +$(eval $(autotools-package)) diff --git a/src/klish-plugin-infix/xml/infix.xml b/src/klish-plugin-infix/xml/infix.xml index 36ed6481..23e677a5 100644 --- a/src/klish-plugin-infix/xml/infix.xml +++ b/src/klish-plugin-infix/xml/infix.xml @@ -274,9 +274,9 @@ sysrepocfg -d operational -X -f json -x /ietf-system:system-state/infix-system:software | \ jq -r '.[][].slot |= sort_by(.name)' > "$tmp" if [ -n "$KLISH_PARAM_name" ]; then - cat "$tmp" | /libexec/infix/cli-pretty "infix-system" -n "$KLISH_PARAM_name" + cat "$tmp" | /usr/libexec/statd/cli-pretty "infix-system" -n "$KLISH_PARAM_name" else - cat "$tmp" | /libexec/infix/cli-pretty "infix-system" + cat "$tmp" | /usr/libexec/statd/cli-pretty "infix-system" fi rm "$tmp" @@ -323,14 +323,14 @@ fi fi sysrepocfg -f json -X -d operational -x "/ietf-routing:routing/ribs" | \ - /libexec/infix/cli-pretty "ietf-routing" -n "$KLISH_PARAM_name" + /usr/libexec/statd/cli-pretty "ietf-routing" -n "$KLISH_PARAM_name" sysrepocfg -f json -X -d operational -x "/ietf-hardware:hardware" | \ - /libexec/infix/cli-pretty "ietf-hardware" + /usr/libexec/statd/cli-pretty "ietf-hardware" @@ -346,10 +346,10 @@ if [ -n "$KLISH_PARAM_name" ]; then sysrepocfg -f json -X -d operational -x \ "/ietf-interfaces:interfaces/interface[name='$KLISH_PARAM_name']" | \ - /libexec/infix/cli-pretty "ietf-interfaces" -n "$KLISH_PARAM_name" + /usr/libexec/statd/cli-pretty "ietf-interfaces" -n "$KLISH_PARAM_name" else sysrepocfg -f json -X -d operational -m ietf-interfaces | \ - /libexec/infix/cli-pretty "ietf-interfaces" + /usr/libexec/statd/cli-pretty "ietf-interfaces" fi diff --git a/src/statd/.gitignore b/src/statd/.gitignore index fe2e9092..9834c978 100644 --- a/src/statd/.gitignore +++ b/src/statd/.gitignore @@ -1,3 +1,28 @@ *~ *.o statd + +/aclocal.m4 +/autom4te.cache/ +/aux +/clixon.xml +/compile +/config.h +/config.h.in +/config.guess +/config.log +/config.status +/config.sub +/configure +/depcomp +/install-sh +/libtool +/ltmain.sh +/m4 +/missing + +GPATH +GRTAGS +GTAGS +Makefile +Makefile.in diff --git a/src/statd/Makefile b/src/statd/Makefile deleted file mode 100644 index 2404e36b..00000000 --- a/src/statd/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -CFLAGS += -Wall -Wextra -Werror -CPPFLAGS += -D_GNU_SOURCE -LDLIBS += -lsysrepo -lev -lyang -ljansson -lsrx -lite - -TARGET = statd -HEADERS = shared.h -SRC = statd.c shared.c -OBJ = $(SRC:.c=.o) - -all: $(TARGET) - -.c.o: - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -$(OBJ): $(SRC) $(HEADERS) - -$(TARGET): $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -clean: - -rm -f $(TARGET) $(OBJ) - -distclean: clean - -rm *~ - -install: $(TARGET) - install -D $(TARGET) $(DESTDIR)/sbin/ diff --git a/src/statd/Makefile.am b/src/statd/Makefile.am new file mode 100644 index 00000000..aad94587 --- /dev/null +++ b/src/statd/Makefile.am @@ -0,0 +1,13 @@ +DISTCLEANFILES = *~ *.d +ACLOCAL_AMFLAGS = -I m4 + +pkglibexec_SCRIPTS = cli-pretty yanger ospf-status + +sbin_PROGRAMS = statd +statd_SOURCES = statd.c shared.c shared.h +statd_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE +statd_CFLAGS = -W -Wall -Wextra +statd_CFLAGS += $(jansson_CFLAGS) $(libite_CFLAGS) $(libyang_CFLAGS) +statd_CFLAGS += $(sysrepo_CFLAGS) $(libsrx_CFLAGS) +statd_LDADD = $(jansson_LIBS) $(libite_LIBS) $(libyang_LIBS) +statd_LDADD += $(sysrepo_LIBS) $(libsrx_LIBS) diff --git a/src/statd/autogen.sh b/src/statd/autogen.sh new file mode 100755 index 00000000..69ad0e18 --- /dev/null +++ b/src/statd/autogen.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +autoreconf -W portability -vifm diff --git a/board/netconf/rootfs/libexec/infix/cli-pretty b/src/statd/cli-pretty similarity index 100% rename from board/netconf/rootfs/libexec/infix/cli-pretty rename to src/statd/cli-pretty diff --git a/src/statd/configure.ac b/src/statd/configure.ac new file mode 100644 index 00000000..13a13e9e --- /dev/null +++ b/src/statd/configure.ac @@ -0,0 +1,76 @@ +AC_PREREQ(2.61) +AC_INIT([statd], [1.0.0], [https://github.com/kernelkit/infix/issues]) +AM_INIT_AUTOMAKE(1.11 foreign subdir-objects) +AM_SILENT_RULES(yes) + +AC_CONFIG_FILES([ + Makefile +]) + +AC_PROG_CC +AC_PROG_INSTALL + +# Check for pkg-config first, warn if it's not installed +PKG_PROG_PKG_CONFIG + +PKG_CHECK_MODULES([jansson], [jansson >= 2.0.0]) +PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) +PKG_CHECK_MODULES([libyang], [libyang >= 2.1.80]) +PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36]) +PKG_CHECK_MODULES([libsrx], [libsrx >= 1.0.0]) + +AC_CHECK_HEADER([ev.h], + [AC_CHECK_LIB([ev], [ev_loop_new], + [], + [AC_MSG_ERROR("libev not found")] )], + [AC_MSG_ERROR("ev.h not found")] +) + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DATAROOTDIR=`eval echo $datarootdir` +DATAROOTDIR=`eval echo $DATAROOTDIR` +AC_SUBST(DATAROOTDIR) + +LIBDIR=`eval echo $libdir` +LIBDIR=`eval echo $LIBDIR` +AC_SUBST(LIBDIR) + +LOCALSTATEDIR=`eval echo $localstatedir` +LOCALSTATEDIR=`eval echo $LOCALSTATEDIR` +AC_SUBST(LOCALSTATEDIR) + +RUNSTATEDIR=`eval echo $runstatedir` +RUNSTATEDIR=`eval echo $RUNSTATEDIR` +AC_SUBST(RUNSTATEDIR) + +SYSCONFDIR=`eval echo $sysconfdir` +SYSCONFDIR=`eval echo $SYSCONFDIR` +AC_SUBST(SYSCONFDIR) + +AC_OUTPUT + +cat <