1#!/bin/sh 2ECM_MODULE=${1:-ecm_state} 3MOUNT_ROOT=/dev/ecm 4 5# 6# usage: ecm_dump.sh [module=ecm_db] 7# 8# with no parameters, ecm_dump.sh will attempt to mount the 9# ecm_db state file and cat its contents. 10# 11# example with a parameter: ecm_dump.sh ecm_classifier_default 12# 13# this will cause ecm_dump to attempt to find and mount the state 14# file for the ecm_classifier_default module, and if successful 15# cat the contents. 16# 17 18# this is one of the state files, which happens to be the 19# last module started in ecm 20ECM_STATE=/sys/kernel/debug/ecm/ecm_state/state_dev_major 21 22# tests to see if ECM is up and ready to receive commands. 23# returns 0 if ECM is fully up and ready, else 1 24ecm_is_ready() { 25 if [ ! -e "${ECM_STATE}" ] 26 then 27 return 1 28 fi 29 return 0 30} 31 32# 33# module_state_mount(module_name) 34# Mounts the state file of the module, if supported 35# 36module_state_mount() { 37 local module_name=$1 38 local mount_dir=$2 39 local state_file="/sys/kernel/debug/ecm/${module_name}/state_dev_major" 40 41 if [ -e "${mount_dir}/${module_name}" ] 42 then 43 # already mounted 44 return 0 45 fi 46 47 echo "Mount state file for $module_name ..." 48 if [ ! -e "$state_file" ] 49 then 50 echo "... $module_name does not support state" 51 return 1 52 fi 53 54 local major="`cat $state_file`" 55 #echo "... Mounting state $state_file with major: $major" 56 mknod "${mount_dir}/${module_name}" c $major 0 57} 58 59# 60# main 61# 62ecm_is_ready || { 63 echo "ECM is not running" 64 exit 1 65} 66 67# all state files are mounted under MOUNT_ROOT, so make sure it exists 68mkdir -p ${MOUNT_ROOT} 69 70# 71# attempt to mount state files for the requested module and cat it 72# if the mount succeeded 73# 74module_state_mount ${ECM_MODULE} ${MOUNT_ROOT} && { 75 echo "cat ${MOUNT_ROOT}/${ECM_MODULE}" 76 cat ${MOUNT_ROOT}/${ECM_MODULE} 77 exit 0 78} 79 80exit 2 81