From d4f8c95dea3b819e6b605adb7988ba090fe0ad0b Mon Sep 17 00:00:00 2001 From: vdutta Date: Mon, 29 Aug 2022 19:45:13 +0530 Subject: [PATCH] swmodd: Added cgroup mount handler swmodd-cgroup pkg --- swmodd/Makefile | 22 +++++++++-- swmodd/files/etc/init.d/swmodd_cgroup | 56 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 swmodd/files/etc/init.d/swmodd_cgroup diff --git a/swmodd/Makefile b/swmodd/Makefile index e0d9bae0a..153fe2780 100755 --- a/swmodd/Makefile +++ b/swmodd/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=swmodd -PKG_VERSION:=2.1.7 +PKG_VERSION:=2.1.8 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) @@ -30,15 +30,23 @@ define Package/swmodd SUBMENU:=TRx69 TITLE:= Software Modules Daemon DEPENDS:=+libuci +libubox +ubus +libuuid +opkg +libcurl \ - +PACKAGE_liblxc:liblxc +cgroupfs-mount \ - +@BUSYBOX_CONFIG_BUSYBOX +@BUSYBOX_CONFIG_FEATURE_SHOW_SCRIPT \ - +@BUSYBOX_CONFIG_SCRIPT + +PACKAGE_liblxc:liblxc +@BUSYBOX_CONFIG_BUSYBOX \ + +@BUSYBOX_CONFIG_FEATURE_SHOW_SCRIPT +@BUSYBOX_CONFIG_SCRIPT \ + +swmodd-cgroup endef define Package/swmodd/description Software module daemon to manage software/deployment units using TR181 datamodel. endef +define Package/swmodd-cgroup + SECTION:=utils + CATEGORY:=Utilities + SUBMENU:=TRx69 + TITLE:= Cgroup mount handler for Software modules daemon + DEPENDS:=+@CONFIG_KERNEL_CGROUPS +endef + TARGET_CFLAGS += \ -D_GNU_SOURCE \ -Wall -Werror @@ -85,4 +93,10 @@ ifeq ($(CONFIG_PACKAGE_crun),y) endif endef +define Package/swmodd-cgroup/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/etc/init.d/swmodd_cgroup $(1)/etc/init.d/swmodd_cgroup +endef + +$(eval $(call BuildPackage,swmodd-cgroup)) $(eval $(call BuildPackage,swmodd)) diff --git a/swmodd/files/etc/init.d/swmodd_cgroup b/swmodd/files/etc/init.d/swmodd_cgroup new file mode 100644 index 000000000..dc020523c --- /dev/null +++ b/swmodd/files/etc/init.d/swmodd_cgroup @@ -0,0 +1,56 @@ +#!/bin/sh /etc/rc.common + +START=01 + +log() { + echo "swmodd_cgroup: ${@}" >/dev/console +} + +cgroup_remounting_required() +{ + if ! mount |grep -q '/sys/fs/cgroup '; then + return 1; + fi + + if grep -v '^#' /etc/fstab | grep -q cgroup; then + log "fstab mounted system, remounting of cgroup not required" + return 1 + fi + + if [ ! -d /sys/fs/cgroup ] && [ ! -e /proc/cgroups ]; then + log "cgroup fs not found" + return 1 + fi + + umount /sys/fs/cgroup + return 0; +} + +mount_cgroup() +{ + + if ! cgroup_remounting_required; then + log "cgroup remounting not required" + return 1 + fi + + mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup + cd /sys/fs/cgroup + for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do + mkdir -p $sys + if ! mountpoint -q $sys; then + if ! mount -n -t cgroup -o $sys cgroup $sys; then + rm -f $sys || true + fi + fi + done + + if [ -e /sys/fs/cgroup/memory/memory.use_hierarchy ]; then + echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy + fi +} + +boot() +{ + mount_cgroup +}