Exemple #1
0
def _createControlSocket():
    ''' Create the client control socket.
    '''
    socketFile = hlm_paths.controlSocket()

    try:
        # We first try to connect to the socket. If noone answers (file not found / connection refused)
        # then we can safely assume it is a stale file.
        clientSocket = None
        try:
            clientSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            clientSocket.settimeout(None)
            clientSocket.connect(hlm_paths.controlSocket())
            raise FatalError(
                _('The HLM system daemon seems to be already running.'))
        except SystemExit:
            raise
        except socket.error as exc:
            if exc.errno == 2:  # File not found
                pass
            elif exc.errno == 111:  # Connection refused
                # This is a stale file, just delete it
                if __DEBUG__:
                    logDebug(
                        'Control socket file {0} already exists but is a stale file. Deleting it.'
                        .format(quote(socketFile)))
                os.remove(socketFile)
            else:
                raise
        clientSocket.shutdown(socket.SHUT_RDWR)
        clientSocket.close()

        # If we got this far then the socket file is available for us.
        global _controlSocket
        _controlSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        _controlSocket.settimeout(None)
        _controlSocket.bind(socketFile)
        os.chmod(socketFile, 0o666)
        atexit.register(_closeControlSocket)
        if __DEBUG__:
            logDebug('Created control socket file {0}.'.format(
                quote(socketFile)))
    except SystemExit:
        raise
    except BaseException as exc:
        raise FatalError(
            _('Unable to create the socket file {0}: {1}').format(
                quote(socketFile), exc))
def _createControlSocket():
    ''' Create the client control socket.
    '''
    socketFile = hlm_paths.controlSocket()

    try:
        # We first try to connect to the socket. If noone answers (file not found / connection refused)
        # then we can safely assume it is a stale file.
        clientSocket = None
        try:
            clientSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            clientSocket.settimeout(None)
            clientSocket.connect(hlm_paths.controlSocket())
            raise FatalError(_('The HLM system daemon seems to be already running.'))
        except SystemExit:
            raise
        except socket.error as exc:
            if exc.errno == 2: # File not found
                pass
            elif exc.errno == 111: # Connection refused
                # This is a stale file, just delete it
                if __DEBUG__: logDebug('Control socket file {0} already exists but is a stale file. Deleting it.'.format(quote(socketFile)))
                os.remove(socketFile)
            else:
                raise
        clientSocket.shutdown(socket.SHUT_RDWR)
        clientSocket.close()

        # If we got this far then the socket file is available for us.
        global _controlSocket
        _controlSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        _controlSocket.settimeout(None)
        _controlSocket.bind(socketFile)
        os.chmod(socketFile, 0o666)
        atexit.register(_closeControlSocket)
        if __DEBUG__: logDebug('Created control socket file {0}.'.format(quote(socketFile)))
    except SystemExit:
        raise
    except BaseException as exc:
        raise FatalError(_('Unable to create the socket file {0}: {1}').format(quote(socketFile), exc))
Exemple #3
0
def _closeControlSocket():
    try:
        global _controlSocket
        _controlSocket.close()
    except SystemExit:
        raise
    except BaseException:
        pass
    try:
        socketFile = hlm_paths.controlSocket()
        os.remove(socketFile)
    except SystemExit:
        raise
    except BaseException:
        pass
def _closeControlSocket():
    try:
        global _controlSocket
        _controlSocket.close()
    except SystemExit:
        raise
    except BaseException:
        pass
    try:
        socketFile = hlm_paths.controlSocket()
        os.remove(socketFile)
    except SystemExit:
        raise
    except BaseException:
        pass
Exemple #5
0
 def __init__(self):
     try:
         self.__socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
         self.__socket.settimeout(None)
         self.__socket.connect(hlm_paths.controlSocket())
         self.__file = self.__socket.makefile(mode = 'rw')
         if __DEBUG__: logDebug('Created client socket #{0}.'.format(self.__socket.fileno()))
     except SystemExit:
         raise
     except socket.error as exc:
         if exc.errno == 2: # File not found
             pass
         elif exc.errno == 111: # Connection refused
             pass
         else:
             _socketError(exc, 'connect()')
         raise FatalError(_('Could not connect to the HLM system daemon. Is it running?'))
     except BaseException as exc:
         _socketError(exc, 'connect()')