Ticket #260: new.patch

File new.patch, 2.5 KB (added by sdhillon, 3 years ago)

New Patch, use this one.

  • framework/subsystems/ogsmd/helpers.py

    diff --git a/framework/subsystems/ogsmd/helpers.py b/framework/subsystems/ogsmd/helpers.py
    index 31a3e68..b89f332 100644
    a b class BiDict( object ): 
    110110            return self._d.keys() + self._back.keys() 
    111111 
    112112#=========================================================================# 
    113 def processIterator(): 
     113def processIterator(nameToFind): 
     114#=========================================================================#         
     115    for entry in os.listdir( "/proc" ):  
     116        fileName = os.path.join("/proc", entry, "cmdline") 
     117        if os.access(fileName, os.R_OK): 
     118            cmdline=file(fileName).read() 
     119            executablePath = cmdline.split("\x00")[0] 
     120            executableName = executablePath.split(os.path.sep)[-1] 
     121            #entry = pid, cmdline = cmdline file contents 
     122            yield (entry, cmdline, executablePath, executableName)  
     123 
    114124#=========================================================================# 
    115     for entry in os.listdir( "/proc" ): 
    116         try: 
    117             pid = int( entry ) 
    118         except ValueError: 
    119             continue 
    120         else: 
    121             name = open( "/proc/%s/cmdline" % pid ).read().split( '\0' )[0] 
    122             yield name, pid 
     125def processFinder(nameToFind, matchType): 
     126#=========================================================================# 
     127    for (entry, cmdline, executablePath, executableName) in processIterator(nameToFind): 
     128        if matchType=="posix": 
     129            if executableName == nameToFind: 
     130                yield entry 
     131        elif matchType=="weak": 
     132            if executablePath.find(nameToFind) != -1: 
     133                yield entry 
     134        elif matchType=="reallyweak": 
     135            if cmdline.find(nameToFind) != -1: 
     136                yield entry 
    123137 
    124138#=========================================================================# 
    125 def killall( nameToKill ): 
     139def killall( nameToKill, matchType="posix", killSignal=signal.SIGTERM): 
    126140#=========================================================================# 
    127     [ os.kill( pid, signal.SIGTERM ) for name, pid in processIterator() if name == nameToKill ] 
     141    killedPids=[] 
     142    for pid in processFinder(nameToKill, matchType): 
     143        try: 
     144            os.kill(int(pid), killSignal) 
     145            killedPids.append(int(pid)) 
     146        except OSError: #permission denied/bad signal/etc... 
     147            pass 
     148    return killedPids 
    128149 
    129150#=========================================================================# 
    130151if __name__ == "__main__":