This file is indexed.

/usr/share/pyshared/cpuset/main.py is in cpuset 1.5.6-2.

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

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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
"""Front end command line tool for Linux cpusets
"""

__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""

import sys, os
from optparse import OptionParser
from cpuset import config
import cpuset.commands
from cpuset.commands.common import CmdException
from cpuset.util import CpusetException

#
# The commands map
#
class Commands(dict):
    """Commands class. It performs on-demand module loading
    """
    def canonical_cmd(self, key):
        """Return the canonical name for a possibly-shortenned
        command name.
        """
        candidates = [cmd for cmd in self.keys() if cmd.startswith(key)]

        if not candidates:
            log.error('Unknown command: %s', key)
            log.error('Try "%s help" for a list of supported commands', prog)
            sys.exit(1)
        elif len(candidates) > 1:
            log.error('Ambiguous command: %s', key)
            log.error('Candidates are: %s', ', '.join(candidates))
            sys.exit(1)

        return candidates[0]
        
    def __getitem__(self, key):
        """Return the command python module name based.
        """
        global prog

        cmd_mod = self.get(key) or self.get(self.canonical_cmd(key))
            
        __import__('cpuset.commands.' + cmd_mod)
        return getattr(cpuset.commands, cmd_mod)

commands = Commands({
    'shield':       'shield',
    'set':          'set',
#    'mem':          'mem',
    'proc':         'proc',
    })

supercommands = (
    'shield',
    )

def _print_helpstring(cmd):
    print '  ' + cmd + ' ' * (12 - len(cmd)) + commands[cmd].help
    
def print_help():
    print 'Usage: %s [global options] <command> [command options]' % os.path.basename(sys.argv[0])
    print
    print 'Global options:'
    print '  -l/--log <fname>       output debugging log in fname'
    print '  -m/--machine           print machine readable output'
    print '  -x/--tohex <CPUSPEC>   convert a CPUSPEC to hex'
    print
    print 'Generic commands:'
    print '  help        print the detailed command usage'
    print '  version     display version information'
    print '  copyright   display copyright information'

    cmds = commands.keys()
    cmds.sort()
    print 
    print 'Super commands (high-level and multi-function):'
    for cmd in supercommands:
        _print_helpstring(cmd)
    print
    print 'Regular commands:'
    for cmd in cmds:
        if not cmd in supercommands:
            _print_helpstring(cmd)

def main():

    # handle pipes better
    import signal
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    global prog
    prog = os.path.basename(sys.argv[0])

    global logfile
    logfile = None

    if len(sys.argv) < 2:
        print >> sys.stderr, 'usage: %s <command>' % prog
        print >> sys.stderr, \
              '  Try "%s --help" for a list of supported commands' % prog
        sys.exit(1)
    
    # configure logging
    import logging
    console = logging.StreamHandler(sys.stdout)
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(prog + ': %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)
    global log
    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)

    try:
        debug_level = int(os.environ['CSET_DEBUG_LEVEL'])
    except KeyError:
        debug_level = 0
    except ValueError:
        log.error('Invalid CSET_DEBUG_LEVEL environment variable')
        sys.exit(1)

    while True:
        if len(sys.argv) == 1:
            log.error('no arguments, nothing to do!')
            sys.exit(2)
        cmd = sys.argv[1]
        if cmd in ['-l', '--log']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            # FIXME: very fragile
            logfile = sys.argv[2]
            #trace = logging.FileHandler('/var/log/cset.log', 'w')
            trace = logging.FileHandler(logfile, 'a')
            trace.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s %(name)-6s %(levelname)-8s %(message)s',
                                          '%y%m%d-%H:%M:%S')
            trace.setFormatter(formatter)
            logging.getLogger('').addHandler(trace)
            log.debug("---------- STARTING ----------")
            from cpuset.version import version
            log.debug('Cpuset (cset) %s' % version)
            del(sys.argv[2])
            del(sys.argv[1])
            continue
        if cmd in ['-h', '--help']:
           if len(sys.argv) >= 3:
               cmd = commands.canonical_cmd(sys.argv[2])
               sys.argv[2] = '--help'
           else:
               print_help()
               sys.exit(0)
        if cmd == 'help':
            if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
                cmd = commands.canonical_cmd(sys.argv[2])
                if not cmd in commands:
                    log.error('help: "%s" command unknown' % cmd)
                    sys.exit(1)

                sys.argv[0] += ' %s' % cmd
                command = commands[cmd]
                parser = OptionParser(usage = command.usage,
                                      option_list = command.options)
                from pydoc import pager
                pager(parser.format_help())
            else:
                print_help()
            sys.exit(0)
        if cmd in ['-v', '--version', 'version']:
            from cpuset.version import version
            log.info('Cpuset (cset) %s' % version)
            sys.exit(0)
        if cmd in ['-c', 'copyright', 'copying']:
            log.info(__copyright__)
            sys.exit(0)
        if cmd in ['-m', '--machine']:
            config.mread = True
            del(sys.argv[1])
            continue
        if cmd in ['-x', '--tohex']:
            if len(sys.argv) < 3:
                log.critical('not enough arguments')
                sys.exit(1)
            cpuspec = sys.argv[2]
            import cset
            try:
                print cset.cpuspec_to_hex(cpuspec)
            except (ValueError, OSError, IOError, CpusetException, CmdException), err:
                log.critical('**> ' + str(err))
                if debug_level:
                    raise
                else:
                    sys.exit(2)
            sys.exit(0)

        break

    # re-build the command line arguments
    cmd = commands.canonical_cmd(cmd)
    sys.argv[0] += ' %s' % cmd
    del(sys.argv[1])
    log.debug('cmdline: ' + ' '.join(sys.argv))

    try:
        # importing the cset class creates the model
        log.debug("creating cpuset model")
        import cpuset.cset
        command = commands[cmd]
        usage = command.usage.split('\n')[0].strip()
        parser = OptionParser(usage = usage, option_list = command.options)
        options, args = parser.parse_args()
        command.func(parser, options, args)
    except (ValueError, OSError, IOError, CpusetException, CmdException), err:
        log.critical('**> ' + str(err))
        if str(err).find('Permission denied') != -1:
            log.critical('insufficient permissions, you probably need to be root')
        if str(err).find('invalid literal') != -1:
            log.critical('option not understood')
        if debug_level:
            raise
        else:
            sys.exit(2)
    except KeyboardInterrupt:
        sys.exit(1)

    sys.exit(0)