client.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. # pylint: skip-file
  4. #
  5. # The Qubes OS Project, http://www.qubes-os.org
  6. #
  7. # Copyright (C) 2010 Rafal Wojtczuk <rafal@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. #
  24. import socket
  25. import fcntl
  26. class QMemmanClient:
  27. def request_memory(self, amount):
  28. self.sock = socket.socket(socket.AF_UNIX)
  29. flags = fcntl.fcntl(self.sock.fileno(), fcntl.F_GETFD)
  30. flags |= fcntl.FD_CLOEXEC
  31. fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, flags)
  32. self.sock.connect("/var/run/qubes/qmemman.sock")
  33. self.sock.send(str(amount)+"\n")
  34. self.received = self.sock.recv(1024).strip()
  35. if self.received == 'OK':
  36. return True
  37. else:
  38. return False
  39. def close(self):
  40. self.sock.close()