qmemman_client.py 594 B

123456789101112131415161718192021
  1. import socket
  2. import fcntl
  3. class QMemmanClient:
  4. def request_memory(self, amount):
  5. self.sock = socket.socket(socket.AF_UNIX)
  6. flags = fcntl.fcntl(self.sock.fileno(), fcntl.F_GETFD)
  7. flags |= fcntl.FD_CLOEXEC
  8. fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, flags)
  9. self.sock.connect("/var/run/qubes/qmemman.sock")
  10. self.sock.send(str(amount)+"\n")
  11. self.received = self.sock.recv(1024).strip()
  12. if self.received == 'OK':
  13. return True
  14. else:
  15. return False
  16. def close(self):
  17. self.sock.close()