VirtualBox

Ignore:
Timestamp:
Mar 21, 2023 12:43:25 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156451
Message:

ValidationKit/{common/utils.py,testdriver/base.py}: Rework the
Solaris-specific core file configuration code to back up any existing
coreadm(8) changes before modifying the system-wide core file
configuration and then restore the original coreadm(8) setup afterwards.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/base.py

    r98655 r99086  
    717717        self.sKindCrashDump   = sKindCrashDump;
    718718
    719         sCorePath = None;
    720719        sOs       = utils.getHostOs();
    721720        if sOs == 'solaris':
    722             if sKindCrashDump is not None: # Enable.
    723                 sCorePath = getDirEnv('TESTBOX_PATH_SCRATCH', sAlternative = '/var/cores', fTryCreate = False);
    724                 (iExitCode, _, sErr) = utils.processOutputUnchecked([ 'coreadm', '-e', 'global', '-e', 'global-setid', \
    725                                                                       '-e', 'process', '-e', 'proc-setid', \
    726                                                                       '-g', os.path.join(sCorePath, '%f.%p.core')]);
    727             else: # Disable.
    728                 (iExitCode, _, sErr) = utils.processOutputUnchecked([ 'coreadm', \
    729                                                                       '-d', 'global', '-d', 'global-setid', \
    730                                                                       '-d', 'process', '-d', 'proc-setid' ]);
    731             if iExitCode != 0: # Don't report an actual error, just log this.
    732                 reporter.log('%s coreadm failed: %s' % ('Enabling' if sKindCrashDump else 'Disabling', sErr));
    733 
    734         if sKindCrashDump is not None:
    735             if sCorePath is not None:
    736                 reporter.log('Crash dumps enabled -- path is "%s"' % (sCorePath,));
    737         else:
    738             reporter.log('Crash dumps disabled');
     721            # Both 'coreadm -e ...' and 'svccfg apply' only work if running with all privileges.
     722            fIsRoot = os.getuid() == 0;
     723            if fIsRoot is False:
     724                return True;
     725
     726            sScratchPath = os.environ.get('TESTBOX_PATH_SCRATCH', '/var/tmp');
     727            sCoreadmXmlFile = os.path.join(sScratchPath, 'coreadm.xml');
     728            if sKindCrashDump is not None:
     729                # If the current core file configuration has been modified from the system default
     730                # then save the configuration to coreadm.xml so it can be restored afterwards.
     731                (iExitCode, sStdOut, sStdErr) = utils.processOutputUnchecked([ 'svcprop', '-p', 'config_params', \
     732                                                                               '-l', 'admin', 'svc:/system/coreadm:default' ]);
     733                if iExitCode == 0 and sStdOut != '':
     734                    (iExitCode, _, sStdErr) = utils.processOutputUnchecked([ 'svccfg', 'extract', '-l', 'admin', \
     735                                                                             'svc:/system/coreadm:default', '>', \
     736                                                                             sCoreadmXmlFile ]);
     737                # Annoyingly svccfg(1M) returns zero for both success and failure but if the
     738                # command fails errors are written to stderr.
     739                if iExitCode != 0 or sStdErr != '':
     740                    reporter.error('Failed to backup current system-wide core dump configuration: %s' % sStdErr);
     741                    return False;
     742
     743                # Configure all core dumps, including those of setuid and setgid binaries, to be
     744                # written to /var/cores using the naming pattern of core.argv0.process-ID, e.g.
     745                # core.VBoxSVC.12345.
     746                (iExitCode, _, sStdErr) = utils.processOutputUnchecked([ 'coreadm', '-e', 'global', '-e', 'global-setid', \
     747                                                                         '-e', 'log', '-G', 'all', \
     748                                                                         '-g', '/var/cores/core.%f.%p' ]);
     749                if iExitCode != 0:
     750                    reporter.error('Failed to update system-wide core dump configuration: %s' % sStdErr);
     751                    return False;
     752
     753                reporter.log('Core file configuration successfully updated: All core files will be written to /var/cores.');
     754            else:
     755                # Restore the core file configuration to what it was before making the
     756                # changes above.
     757                (iExitCode, _, sStdErr) = utils.processOutputUnchecked([ 'svccfg', '-s', 'svc:/system/coreadm:default', \
     758                                                                         'delcust' ]);
     759                # Annoyingly svccfg(1M) returns zero for both success and failure but if the
     760                # command fails errors are written to stderr.
     761                if sStdErr == '' and os.path.exists(sCoreadmXmlFile):
     762                    (iExitCode, _, sStdErr) = utils.processOutputUnchecked([ 'svccfg', 'apply', sCoreadmXmlFile ]);
     763
     764                if sStdErr != '':
     765                    reporter.error('Failed to restore system-wide core dump configuration: %s' % sStdErr);
     766                    return False;
     767
     768                reporter.log('Core file configuration successfully restored to previous state.');
    739769
    740770        return True;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette