Advertisement
abw

lsholders

abw
Jun 16th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3.   PLn () { printf '%s\n' "${@}" ; } # PLn
  4.  
  5.   MkLiteral () { # <string>
  6.     #   Make pattern for literal match of <string>
  7.     # in 'grep' or 'sed' regular expressions.
  8.     printf '%s' "${1}" | sed 's/./[&]/g ; s/\^/[.^.]/g'
  9.   } # MkLiteral
  10.  
  11.   #   А "node" is a string of any character, except null,
  12.   # space and newline characters.
  13.   #   An "arc" is a pair of "nodes", delimited with one or more spaces.
  14.   #   A "list" is sequence of something, delimited with newlines.
  15.  
  16.   GetArcs () { # <top node> <arc list>
  17.  
  18.     local Arcs="${2}" Visited=
  19.  
  20.     DFS () { # <source node>
  21.       # Deep-First Search
  22.  
  23.       local N="${1}" # nonlocal: Arcs, Visited
  24.  
  25.       Visited=$( PLn "${N}" "${Visited}" ) N=$( MkLiteral "${N}" )
  26.       N=$( PLn "${Arcs}" | grep "^${N} " ) && PLn "${N}"
  27.  
  28.       for N in $( PLn "${N}" | sed -n "s/^[^ ]*[ ][ ]*//p" ) ; do
  29.         PLn "${Visited}" | grep -F -x -q "${N}" || DFS "${N}"
  30.       done
  31.  
  32.     } # DFS
  33.  
  34.     DFS "${1}"
  35.  
  36.   } # GetArcs
  37.  
  38.   PutSortedModules () { # <source module name>
  39.  
  40.     local M="${1}"
  41.  
  42.     #   It's assumed here that the names of the modules
  43.     # don't contain spaces and newlines.
  44.  
  45.     GetHolders () {
  46.       local H ; for H in /sys/module/*/holders/* ; do
  47.         PLn "${H}" | sed 's|^/sys/module/|| ; s|/holders/| |'
  48.       done
  49.     } # GetHolders
  50.  
  51.     { PLn "${M} ${M}" ; GetArcs "${M}" "$( GetHolders )" ; } | tsort | tac
  52.  
  53.   } # PutSortedModules
  54.  
  55.   PutSortedModules "${1}"
  56.  
  57. exit # lsholders
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement