This file is indexed.

/usr/bin/hwloc-gather-topology is in hwloc-nox 1.8-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
#-*-sh-*-

#
# Copyright © 2009 CNRS
# Copyright © 2009-2013 Inria.  All rights reserved.
# Copyright © 2009-2012 Université Bordeaux 1
# See COPYING in top-level directory.
#

prefix="/usr"
exec_prefix="${prefix}"
bindir="${exec_prefix}/bin"
# this will be changed into $bindir/lstopo during make install
lstopo="$bindir/lstopo-no-graphics"

# make sure we use default numeric formats
LANG=C
LC_ALL=C
export LANG LC_ALL

gatherio=0

error()
{
    echo $@ 2>&1
}

usage()
{
   echo "$0 [options] <savepath>"
   echo "  Saves the Linux topology files (/sys, /proc, ...) under <savepath>.tar.bz2"
   echo "  and the corresponding lstopo verbose output under <savepath>.output"
   echo "Options:"
   echo "  --io   Gather I/O files (takes much longer and generates much larger tarball)"
   echo "Example:"
   echo "  $0 /tmp/\$(uname -n)"
}

while [ x`echo "$1" | cut -c1` = x- ] ; do
  case $1 in
  --io) gatherio=1;;
  *) echo "Unrecognized option: $1"; usage; exit 1;;
  esac
  shift
done

if test $# -lt 1 -o x$1 = x; then
  usage
  exit 1
fi
name="$1"
basename=`basename "$name"`
dirname=`dirname "$name"`

if ! mkdir -p "$dirname" ; then
    error "Failed to create directory $dirname."
    exit 1
fi

if [ ! -w  "$dirname" ] ; then
    echo "$dirname is not writable."
    exit 1
fi

destdir=`mktemp -d`

# Use cat so that we properly get proc/sys files even if their
# file length is wrong
savefile() {
  local dest="$1"
  local file="$2"
  dir=`dirname "$file"`
  mkdir -p "$dest/$dir" 2>/dev/null
  cat "$file" > "$dest/$file" 2>/dev/null
}

savelink() {
  local dest="$1"
  local file="$2"
  dir=`dirname "$file"`
  mkdir -p "$dest/$dir" 2>/dev/null
  cp -P "$file" "$dest/$file"
}

# Gather the following list of files
cat << EOF | while read -r path ; do savefile "$destdir/$basename" "$path" ; done
/proc/cpuinfo
/proc/meminfo
/proc/mounts
/proc/stat
/proc/self/cpuset
EOF

# Get all files from the given directory
# Ignore errors since some files may be missing, and some may be
# restricted to root (but we don't need them).
savedir() {
  local dest="$1"
  local path="$2"
  # gather all directories, including empty ones
  find "$path" -type d 2>/dev/null | while read -r dir ; do
    mkdir -p "$dest/$dir" 2>/dev/null
  done
  # gather all files now
  find "$path" -type f 2>/dev/null | while read -r file ; do
    savefile "$dest" "$file"
  done
  # gather symlinks
  find "$path" -type l 2>/dev/null | while read -r link ; do
    savelink "$dest" "$link"
  done
}

# Gather the following list of directories
cat << EOF | while read -r path ; do savedir "$destdir/$basename" "$path" ; done
/sys/devices/system/cpu/
/sys/devices/system/node/
/sys/bus/cpu/devices/
/sys/bus/node/devices/
/sys/class/dmi/id/
/sys/devices/virtual/dmi/id/
/sys/kernel/mm/hugepages/
/proc/device-tree/cpus/
EOF

# Optionally gather I/O directories too
if [ x$gatherio = x1 ]; then
  cat << EOF | while read -r path ; do savedir "$destdir/$basename" "$path" ; done
/sys/bus/pci/devices/
/sys/block/
/sys/class/block/
/sys/class/dma/
/sys/class/drm/
/sys/class/infiniband/
/sys/class/net/
/sys/class/mic/
EOF
 ls -d /sys/devices/pci* | sed -e 's@$@/@' | while read -r path ; do savedir "$destdir/$basename" "$path" ; done
fi

# Get an entire mount point, after decoding its path
# we don't support path with \n since it would break in 'find ... | while read ..." above
savemntpnt() {
  local encodedpath=$1
  if echo "$1" | grep "\\012" ; then
    echo "Ignoring mount point whose filename contains an end of line."
    return
  fi
  local path=$(echo "$1" | sed -e 's@\\134@\\@g' -e 's@\\040@ @g' -e 's@\\011@	@g')
  savedir "$destdir/$basename" "${path}/"
}

# Gather cgroup/cpuset mntpnts
cat /proc/mounts | while read -r dummy1 mntpath mnttype mntopts dummy2 ; do
  [ x$mnttype = xcpuset ] && savemntpnt "$mntpath"
  [ x$mnttype = xcgroup ] && echo $mntopts | grep -w cpuset >/dev/null && savemntpnt "$mntpath"
done

# Create the archive and keep the tree in /tmp for testing
( cd "$destdir/" && tar cfj "$basename.tar.bz2" "$basename" )
mv "$destdir/$basename.tar.bz2" "$dirname/$basename.tar.bz2"
echo "Hierarchy gathered in $dirname/$basename.tar.bz2 and kept in $destdir/$basename/"

# Generate the output as well
if [ ! -x "$lstopo" ]
then
    error "Could not find lstopo executable in the install or build dir."
    exit 1
fi
# we need "Topology not from this system" in the output so as to make test-topology.sh happy
export HWLOC_THISSYSTEM=0
"$lstopo" - -v > "$dirname/$basename.output"
echo "Expected topology output stored in $dirname/$basename.output"

exit 0