init listener will now shutdown correctly
authorft
Fri, 06 Jun 2014 10:06:35 +0200
changeset 9d49050cfaab7
parent 8 4fd36a6f652a
child 10 b9b23dd0ba4d
init listener will now shutdown correctly
src/encryptionprovider.py
     1.1 --- a/src/encryptionprovider.py	Thu Jun 05 16:23:50 2014 +0200
     1.2 +++ b/src/encryptionprovider.py	Fri Jun 06 10:06:35 2014 +0200
     1.3 @@ -130,6 +130,25 @@
     1.4              LOG.error ("Stick \"%s\" removed -> exit" %(device,))
     1.5              sys.exit(1)
     1.6  
     1.7 +def isDeviceMountedAtMountpoint (device, mountpoint):
     1.8 +    command = ["/bin/df", mountpoint, "|", "/usr/bin/tail", "-1", "|", "awk", "'{print $1}'"]
     1.9 +    result = runExternalScripts(command)
    1.10 +    
    1.11 +    if (result["retcode"] != 0):
    1.12 +        LOG.error ("Retcode: %s" %(result["retcode"],))
    1.13 +        LOG.error ("stdout: %s" %(result["stdout"],))
    1.14 +        LOG.error ("stderr: %s" %(result["stderr"],))
    1.15 +        sys.stderr.write("%s" %(result["stderr"],))
    1.16 +        exit (1)
    1.17 +    
    1.18 +    if (result["stdout"] == device):
    1.19 +        LOG.debug ("Result stdout: %s" %(result["stdout"],))
    1.20 +        return True
    1.21 +    else:
    1.22 +        LOG.debug ("Result stdout: %s" %(result["stdout"],))
    1.23 +        return False
    1.24 +    
    1.25 +
    1.26  def initDevice (script, interface, port, device, mountpoint, keyfilepath):    
    1.27      listener = MyRestListener (opensecurity_urls, globals(), script = script, device = device, mountpoint = mountpoint, tries = 3, keyfilepath = keyfilepath)
    1.28      thread.start_new_thread(listener.run, (interface, port,))
    1.29 @@ -140,9 +159,13 @@
    1.30          if (os.path.exists(device) == False):
    1.31              close = True
    1.32              LOG.info ("Stick \"%s\" removed -> exit" %(device,))
    1.33 +            sys.exit(1)
    1.34 +            
    1.35 +        if ((os.path.ismount(mountpoint) == True) and (isDeviceMountedAtMountpoint(device, mountpoint) == False)):
    1.36 +            close = True
    1.37 +            LOG.info ("Stick \"%s\" init finished -> exit" %(device,))
    1.38              sys.exit(0)
    1.39  
    1.40 -
    1.41  if __name__ == "__main__":
    1.42      
    1.43      parser = argparse.ArgumentParser(epilog='--mount, --umount and --initialize are mutually exclusive')