This file is indexed.

/usr/share/jockey/handlers/fglrx.py is in jockey-common 0.9.7-0ubuntu7.16.

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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# -*- coding: utf-8 -*-
# (c) 2008 Canonical Ltd.
# Authors: Martin Pitt <martin.pitt@ubuntu.com>
#          Alberto Milone <alberto.milone@canonical.com>
# License: GPL v2 or later

import logging, os, os.path
import subprocess
import XKit.xorgparser

from jockey.handlers import KernelModuleHandler
from jockey.xorg_driver import XorgDriverHandler
from jockey.oslib import OSLib
from NvidiaDetector.alternatives import Alternatives
from NvidiaDetector.alternatives import MultiArchUtils

# dummy stub for xgettext
def _(x): return x

class FglrxDriver(XorgDriverHandler):
    def __init__(self, backend, package=None):
        self._free = False

        name=_('ATI/AMD proprietary FGLRX graphics driver')
        description=_('3D-accelerated proprietary graphics driver for '
                      'ATI cards.')
        rationale=_('This driver is required to fully utilise the 3D '
                    'potential of some ATI graphics cards, as well as provide '
                    '2D acceleration of newer cards.')
        if package and 'update' in package:
            name=_('ATI/AMD proprietary FGLRX graphics driver (post-release updates)')
        elif package and 'experimental' in package:
            name=_('ATI/AMD proprietary FGLRX graphics driver (**experimental** beta)')
            description = None
            rationale = None

        XorgDriverHandler.__init__(self, backend, (package and
            package.replace('-', '_') or 'fglrx'), (package and
            package or 'fglrx'), None, None, add_modules=['glx'],
            disable_modules=[], name=name,
            description=description,
            rationale=rationale)

        (self._alternatives, self._other_alternatives) = self._get_alternatives()
        self.needs_kernel_headers = True

    def _get_alternatives(self):
        '''Get multi-arch alternatives names'''
        arch_utils = MultiArchUtils()
        main_name = arch_utils.get_main_alternative_name()
        other_name = arch_utils.get_other_alternative_name()
        return Alternatives(main_name), Alternatives(other_name)

    def available(self):
        # we don't offer fglrx in a life CD environment, as we will run out of
        # RAM trying to download and install all the packages in the RAM disk.
        if os.path.isdir('/rofs'):
            logging.debug('Disabling fglrx driver on live system')
            return False

        if self.has_hybrid_graphics:
            # We disable Hybrid Graphics by default unless a specific
            # driver allows it
            logging.debug('Disabling %s on a hybrid graphics system'
                           % (self.package))
            return False

        logging.debug('fglrx.available: falling back to default')
        return XorgDriverHandler.available(self)

    def enable_config_hook(self):
        # TODO: this method should look for the right Screen section(s) and
        # if none can be found, use section 0. use get_devices_from_serverlayout()

        # X.org does not work otherwise
        if len(self.xorg_conf.globaldict['Screen']) == 0:
            self.xorg_conf.makeSection('Screen', identifier='Default Screen')
        
        self.xorg_conf.addOption('Screen', 'DefaultDepth', '24', position=0, prefix='')
        
        # make sure that RGB path is not in the xorg.conf otherwise xorg will crash
        it = 0
        for section in self.xorg_conf.globaldict['Files']:
            try:
                self.xorg_conf.removeOption('Files', 'RgbPath', position=it)
            except (XKit.xorgparser.OptionException):
                pass
            it += 1
        
        # remove any Disable "dri2" otherwise amdcccle will crash
        module_sections = self.xorg_conf.globaldict['Module']
        have_modules = len(module_sections) > 0
        
        if have_modules:
            for section in module_sections:
                self.xorg_conf.removeOption('Module', 'Disable', value='dri2', position=section)

    def enable(self):
        if self.has_hybrid_graphics:
            # Do not touch xorg.conf on hybrid graphics
            KernelModuleHandler.enable(self)
        else:
            XorgDriverHandler.enable(self)

        # Set the alternative to FGLRX
        fglrx_alternative = self._alternatives.get_alternative_by_name('fglrx', ignore_pattern='-updates')
        if not fglrx_alternative:
            logging.error('%s: get_alternative_by_name(%s) returned nothing' % (
                self.id(), self.package))
            return
        self._alternatives.set_alternative(fglrx_alternative)
        other_fglrx_alternative = self._other_alternatives.get_alternative_by_name('fglrx')
        if other_fglrx_alternative:
            self._other_alternatives.set_alternative(other_fglrx_alternative)
        subprocess.call(['update-initramfs', '-u'])
        subprocess.call(['update-initramfs', '-u', '-k', os.uname()[2]])

    def enabled(self):
        # See if fglrx is the current alternative
        target_alternatives = [alt for alt in
                               self._alternatives.list_alternatives()
                               if alt.split('/')[-2] in ('pxpress', 'fglrx')]
        current_alternative = self._alternatives.get_current_alternative()
        other_target_alternatives = [alt for alt in
                                    self._other_alternatives.list_alternatives()
                                    if alt.split('/')[-2] in ('pxpress', 'fglrx')]
        other_current_alternative = self._other_alternatives.get_current_alternative()

        logging.debug('fglrx.enabled(%s): target_alt %s current_alt %s other target alt %s other current alt %s',
                self.module, target_alternatives, current_alternative,
                other_target_alternatives, other_current_alternative)

        if current_alternative is None:
            logging.debug('current alternative of %s is None, not enabled', self.module)
            return False
        if current_alternative not in target_alternatives or \
           other_current_alternative not in other_target_alternatives:
            logging.debug('%s is not the alternative in use', self.module)
            return False

        if self.has_hybrid_graphics:
            # Do not touch xorg.conf on hybrid graphics
            return KernelModuleHandler.enabled(self)
        else:
            return XorgDriverHandler.enabled(self)

    def disable(self):
        if self.has_hybrid_graphics:
            # Do not touch xorg.conf on hybrid graphics
            KernelModuleHandler.disable(self)
        else:
            XorgDriverHandler.disable(self)

        # Set the alternative back to open drivers
        open_drivers = self._alternatives.get_open_drivers_alternative()
        logging.debug('fglrx.disable(%s): open_drivers: %s', self.module, open_drivers)
        if open_drivers:
            self._alternatives.set_alternative(open_drivers)
        other_open_drivers = self._other_alternatives.get_open_drivers_alternative()
        logging.debug('fglrx.disable(%s): other_open_drivers: %s', self.module, other_open_drivers)
        if other_open_drivers:
            self._other_alternatives.set_alternative(other_open_drivers)
        subprocess.call(['update-initramfs', '-u'])
        subprocess.call(['update-initramfs', '-u', '-k', os.uname()[2]])

        return False

    def enables_composite(self):
        '''Return whether this driver supports the composite extension.'''

        if not self.xorg_conf:
            return False

        # the radeon X.org driver supports composite nowadays, so don't force
        # installation of fglrx upon those users. Treat absent driver
        # configuration as radeon, since that's what X.org should autodetect.
        # Only suggest fglrx if people use something else, like vesa.
        try:
            if self.xorg_conf.getDriver('Device', 0) in ['fglrx', 'ati', 'radeon', None]:
                return False
        except (XKit.xorgparser.OptionException, XKit.xorgparser.SectionException) as error:
            return False # unconfigured driver -> defaults to ati

        return True


class FglrxDriverHybrid(FglrxDriver):
    '''Abstract base class for Fglrx drivers which support Hybrid graphics.'''

    def __init__(self, backend, package=None):
        FglrxDriver.__init__(self, backend, package)
        self.hybrid_gfx_pkg = 'fglrx-pxpress'

    def hybrid_available(self):
        '''See whether Hybrid Graphics should be enabled or not'''
        # Do not provide a driver if Hybrid graphics is available but
        # unsupported (we need at least the lts-raring stack)
        #if self.has_hybrid_graphics and not self.supports_hybrid_graphics:
        #    return False

        # Check that the extra package to enable Hybrid graphics is available
        if not OSLib.inst.package_available(self.hybrid_gfx_pkg):
            return False

        return True

    def available(self):
        # we don't offer this driver in a life CD environment, as we will run
        # out of RAM trying to download and install all the packages in the RAM
        # disk.
        if os.path.isdir('/rofs'):
            logging.debug('Disabling fglrx driver on live system')
            return False

        # See if it's all ready for Hybrid Graphics
        if self.has_hybrid_graphics and not self.hybrid_available():
            return False

        logging.debug('fglrx.available: falling back to default')
        return XorgDriverHandler.available(self)

    def enable(self):
        # First ensure that the package for Hybrid Graphics is
        # installed, if the system supports it
        if self.has_hybrid_graphics:
            try:
                self.backend.install_package(self.hybrid_gfx_pkg)
            except (ValueError, SystemError):
                # Package not available
                logging.error('%s: Unable to install the %s package. '
                              'Hybrid graphics won\'t work.',
                        self.id(), self.hybrid_gfx_pkg)
                return

        FglrxDriver.enable(self)

    def enabled(self):
        # Check that the extra package to enable Hybrid graphics is
        # installed
        if (self.has_hybrid_graphics and
            not OSLib.inst.package_installed(self.hybrid_gfx_pkg)):
            return False

        return FglrxDriver.enabled(self)

    def enable_config_hook(self):
        # Do not touch xorg.conf
        pass

    def enables_composite(self):
        '''Return whether this driver supports the composite extension.'''
        return True

    def disable(self):
        # Try to remove the package for Hybrid Graphics if any
        if self.has_hybrid_graphics:
            try:
                self.backend.remove_package(self.hybrid_gfx_pkg)
            except (ValueError, SystemError):
                pass

        FglrxDriver.disable(self)


class FglrxDriverUpdate(FglrxDriver):
    def __init__(self, backend):
        FglrxDriver.__init__(self, backend, 'fglrx-updates')

class FglrxDriverExperimental9(FglrxDriver):
    def __init__(self, backend):
        FglrxDriver.__init__(self, backend, 'fglrx-experimental-9')

class FglrxDriverExperimental12(FglrxDriver):
    def __init__(self, backend):
        FglrxDriver.__init__(self, backend, 'fglrx-experimental-12')

class FglrxDriverExperimental13(FglrxDriverHybrid):
    def __init__(self, backend):
        FglrxDriverHybrid.__init__(self, backend, 'fglrx-experimental-13')