~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy-proposed

« back to all changes in this revision

Viewing changes to build_tools/dump_sys_state

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2013-08-25 12:48:37 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130825124837-wtefi7f9dsihg8is
Tags: 1:2.7.0-1ubuntu1
* Merge from debian. Remaining changes:
  - debian/control: Added gawk as dependency for dkms build
  - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
  - debian/control: Set ubuntu maintainer    
  - added debian/dahdi.postinst
  - debian/control: Removed Uploaders field.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
 
3
3
# dump_sys_state: dump some /sys and /proc files to a directory.
4
 
# $Id: dump_sys_state 8211 2010-03-02 14:55:22Z tzafrir $
 
4
# $Id$
5
5
#
6
6
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
7
7
# Copyright (C) 2009, Xorcom
31
31
#  # And then later:
32
32
#  DAHDI_VIRT_TOP="$PWD/my_sys_state" dahdi_genconf
33
33
 
34
 
name=dahdi_sys_state_dump
35
 
 
36
 
usage() {
37
 
  echo "$0: dump system data for Dahdi-Perl"
38
 
  echo "Usage: $0 [<name>]]"
39
 
  echo ""
40
 
  echo "<name>: name of directory/tarball to create. Default: $name"
41
 
}
42
 
 
43
 
output_tar() {
44
 
  gzip -9 >$name.tar.gz
45
 
}
46
 
 
47
 
output_cpio() {
48
 
  gzip -9 >$name.cpio.gz
49
 
}
50
 
 
51
 
output_dir() {
52
 
  rm -rf $name
53
 
  mkdir -p $name
54
 
  cd $name
55
 
  #tar xf -
56
 
  cpio -id
57
 
}
 
34
mydir=`dirname $0`
 
35
dahdi_sysfs_copy="$mydir/dahdi_sysfs_copy"
58
36
 
59
37
# Give usage message on expected texts
60
 
case $1 in 
61
 
  help | -* ) usage; exit 1;;
62
 
esac
63
 
 
64
 
if [ "$1" != '' ]; then
65
 
  name="$1"
66
 
fi
67
 
 
68
 
# funky permissions on procfs. Sadly rm -f does not kill them.
69
 
if [ -d "$name" ]; then
70
 
  chmod -R u+w "$name"
71
 
fi
72
 
rm -rf "$name"
73
 
mkdir -p "$name"
74
 
 
75
 
# delete a (potentially empty) list of files
76
 
rm_files() {
77
 
        xargs rm -f rm_files_non_existing_file
78
 
}
 
38
 
 
39
if [ "$#" -ne 0 ]; then
 
40
        echo >&2 "Usage: $0"
 
41
        exit 1
 
42
fi
 
43
 
 
44
id="sys_dump.`hostname`_`date +%F_%H.%M.%S`"
 
45
tarball="$id.tar.gz"
 
46
 
 
47
tmpdir=`mktemp -td 'dahdi_dump.XXXXXX'`
 
48
echo -n >&2 "Creating ... "
 
49
trap "[ -d '$tmpdir' ] && rm -rf '$tmpdir'" 0 1 2 15
 
50
 
 
51
topdir="$tmpdir/$id"
79
52
 
80
53
if [ -r /proc/bus/usb/devices ]; then
81
 
        mkdir -p "$name/proc/bus/usb"
82
 
        cp -a /proc/bus/usb/devices "$name/proc/bus/usb/"
 
54
        mkdir -p "$topdir/proc/bus/usb"
 
55
        cp -a /proc/bus/usb/devices "$topdir/proc/bus/usb/"
83
56
fi
84
57
 
85
58
if [ -d /proc/dahdi ]; then
86
 
        mkdir -p "$name/proc/dahdi"
 
59
        mkdir -p "$topdir/proc/dahdi"
87
60
        if find /proc/dahdi -type f >/dev/null; then
88
 
                cp -a /proc/dahdi/* "$name/proc/dahdi/" 
 
61
                cp -a /proc/dahdi/* "$topdir/proc/dahdi/"
89
62
        fi
90
63
fi
91
64
 
92
65
if [ -d /proc/xpp ]; then
93
 
        mkdir -p "$name/proc/xpp"
 
66
        mkdir -p "$topdir/proc/xpp"
94
67
        if find /proc/xpp -type f >/dev/null; then
95
 
                cp -a /proc/xpp/* "$name/proc/xpp/" 
96
 
                find "$name/proc/xpp" -type f -name command | rm_files
 
68
                cp -a /proc/xpp/* "$topdir/proc/xpp/"
 
69
                find "$topdir/proc/xpp" -type f -name command -exec rm -f '{}' ';'
97
70
        fi
98
71
fi
99
72
 
100
 
# FIXME: the following grab tons of files from sysfs. Any way to do with
101
 
# less information?
102
 
pci_dev_pat='/sys/devices/pci*'
103
 
mkdir -p "$name/sys/devices"
104
 
cp -a $pci_dev_pat "$name/sys/devices/" 2>/dev/null
105
 
 
106
 
for bus in astribanks xpds pci pci_express usb; do
107
 
        if [ -d /sys/bus/$bus ]; then
108
 
                mkdir -p "$name/sys/bus/"
109
 
                cp -a /sys/bus/$bus "$name/sys/bus/" 2>/dev/null
110
 
        fi
111
 
done
112
 
 
113
 
# Remove PCI devices of irelevan classes:
114
 
irrelevant_devs() {
115
 
        grep . "$name"/$pci_dev_pat/0*/class "$name"/$pci_dev_pat/0*/0*/class \
116
 
        | perl -n -e '# Perl provides commented regexes:
117
 
                next unless m{/class:( # The following is a list of device classes
118
 
                        # that can be safely removed:
119
 
                        0x060000 | # Host bridge
120
 
                        0x030000 | # VGA compatible controller
121
 
                        0x038000 | # Display controller
122
 
                        0x040300 | # Audio device
123
 
                        0x060401 | # PCI bridge
124
 
                        0x060100 | # ISA bridge
125
 
                        0x01018a | # IDE interface
126
 
                        0x01018f | # IDE interface
127
 
                        0x0c0500 | # SMBus
128
 
                        0x060700 | # CardBus bridge
129
 
                        0x0c0010 | # FireWire (IEEE 1394)
130
 
                        # The following are not to be removed:
131
 
                        #0x0c0300 | # USB Controller (UHCI?)
132
 
                        #0x060400 | # PCI bridge
133
 
                        #0x0c0320 | # USB Controller (EHCI?)
134
 
                        #0x020000 | # Ethernet controller
135
 
                        #0x0c0010 | # Network controller: (Wifi?)
136
 
                )$}x;
137
 
                # Leave out just the name of the node:
138
 
                s{/[^/]*$}{};
139
 
                print;
140
 
                print "\n"
141
 
        '
142
 
}
143
 
 
144
 
# FIXME: deleting those seems to remove common 'vendor' directories
145
 
# and mess things up. Skip it for now.
146
 
#rm -rf `irrelevant_devs`
147
 
 
 
73
"$dahdi_sysfs_copy" "$topdir"
 
74
echo -n >&2 "tarball ... "
 
75
( cd "$tmpdir" && tar czf - . ) > "$tarball";
 
76
echo >&2 "ready in '$tarball'"