VirtualBox

Ignore:
Timestamp:
Jan 10, 2017 4:07:42 PM (8 years ago)
Author:
vboxsync
Message:

testdriver: Implemented sudo kill for aborting VM processes.

File:
1 edited

Legend:

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

    r65209 r65230  
    178178    return sName;
    179179
    180 def processInterrupt(uPid):
     180def __processSudoKill(uPid, iSignal, fSudo):
     181    """
     182    Does the sudo kill -signal pid thing if fSudo is true, else uses os.kill.
     183    """
     184    try:
     185        if fSudo:
     186            return utils.sudoProcessCall(['/bin/kill', '-%s' % (iSignal,), str(uPid)]) == 0;
     187        os.kill(uPid, iSignal);
     188        return True;
     189    except:
     190        reporter.logXcpt('uPid=%s' % (uPid,));
     191    return False;
     192
     193def processInterrupt(uPid, fSudo = False):
    181194    """
    182195    Sends a SIGINT or equivalent to interrupt the specified process.
     
    189202        fRc = winbase.processInterrupt(uPid)
    190203    else:
    191         try:
    192             os.kill(uPid, signal.SIGINT);
    193             fRc = True;
    194         except:
    195             reporter.logXcpt('uPid=%s' % (uPid,));
    196             fRc = False;
     204        fRc = __processSudoKill(uPid, signal.SIGINT, fSudo);
    197205    return fRc;
    198206
    199 def sendUserSignal1(uPid):
     207def sendUserSignal1(uPid, fSudo = False):
    200208    """
    201209    Sends a SIGUSR1 or equivalent to nudge the process into shutting down
     
    209217        fRc = False;
    210218    else:
    211         try:
    212             os.kill(uPid, signal.SIGUSR1); # pylint: disable=E1101
    213             fRc = True;
    214         except:
    215             reporter.logXcpt('uPid=%s' % (uPid,));
    216             fRc = False;
     219        fRc = __processSudoKill(uPid, signal.SIGUSR1, fSudo); # pylint: disable=E1101
    217220    return fRc;
    218221
    219 def processTerminate(uPid):
     222def processTerminate(uPid, fSudo = False):
    220223    """
    221224    Terminates the process in a nice manner (SIGTERM or equivalent).
     
    226229        fRc = winbase.processTerminate(uPid);
    227230    else:
    228         try:
    229             os.kill(uPid, signal.SIGTERM);
    230             fRc = True;
    231         except:
    232             reporter.logXcpt('uPid=%s' % (uPid,));
     231        fRc = __processSudoKill(uPid, signal.SIGTERM, fSudo);
    233232    return fRc;
    234233
    235 def processKill(uPid):
     234def processKill(uPid, fSudo = False):
    236235    """
    237236    Terminates the process with extreme prejudice (SIGKILL).
     
    242241        fRc = winbase.processKill(uPid);
    243242    else:
    244         try:
    245             os.kill(uPid, signal.SIGKILL); # pylint: disable=E1101
    246             fRc = True;
    247         except:
    248             reporter.logXcpt('uPid=%s' % (uPid,));
     243        fRc = __processSudoKill(uPid, signal.SIGKILL, fSudo); # pylint: disable=E1101
    249244    return fRc;
    250245
     
    15361531            afnMethods = [ sendUserSignal1, processInterrupt, processTerminate, processKill ];
    15371532        for fnMethod in afnMethods:
    1538             ## @todo Handle SUDO processes.
    15391533            for iPid in dPids:
    1540                 fnMethod(iPid);
     1534                fnMethod(iPid, fSudo = dPids[iPid][1]);
    15411535
    15421536            for i in range(10):
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