From 6f3f3fd51fe39d917e88eae80b5b431499de3ea7 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 11 Aug 2016 05:09:15 -0400 Subject: daemon initialization routines: support daemon loop termination. --- src/daemon/ntapi_dsr_internal_connection.c | 56 ++++++++++-------------------- 1 file changed, 19 insertions(+), 37 deletions(-) (limited to 'src/daemon/ntapi_dsr_internal_connection.c') diff --git a/src/daemon/ntapi_dsr_internal_connection.c b/src/daemon/ntapi_dsr_internal_connection.c index 1ff0846..df80d46 100644 --- a/src/daemon/ntapi_dsr_internal_connection.c +++ b/src/daemon/ntapi_dsr_internal_connection.c @@ -15,7 +15,6 @@ int32_t __stdcall __ntapi_dsr_connect_internal_client(nt_daemon_params * params) { int32_t * pstatus; - intptr_t port_id; nt_port_message port_msg; nt_large_integer timeout; @@ -26,45 +25,31 @@ int32_t __stdcall __ntapi_dsr_connect_internal_client(nt_daemon_params * params) /* timeout-enabled first connection */ timeout.quad = NT_DSR_INIT_MAX_WAIT; - *pstatus = __ntapi->zw_reply_wait_receive_port_ex( - params->hport_daemon, - &port_id, - (nt_port_message *)0, - (nt_port_message *)&port_msg, - &timeout); - - if (*pstatus != NT_STATUS_SUCCESS) - __ntapi->zw_terminate_thread( - NT_CURRENT_THREAD_HANDLE, - *pstatus); + if ((*pstatus = __ntapi->zw_reply_wait_receive_port_ex( + params->hport_daemon, + &port_id, + (nt_port_message *)0, + (nt_port_message *)&port_msg, + &timeout))) + return *pstatus; /* the internal client must be first */ if (port_msg.client_id.process_id != pe_get_current_process_id()) - __ntapi->zw_terminate_thread( - NT_CURRENT_THREAD_HANDLE, - NT_STATUS_PORT_CONNECTION_REFUSED); + return NT_STATUS_PORT_CONNECTION_REFUSED; /* accept connection request */ - *pstatus = __ntapi->zw_accept_connect_port( - &_hport_client, - port_msg.client_id.process_id, - (nt_port_message *)&port_msg, - NT_LPC_ACCEPT_CONNECTION, - (nt_port_section_write *)0, - (nt_port_section_read *)0); - - if (*pstatus != NT_STATUS_SUCCESS) - __ntapi->zw_terminate_thread( - NT_CURRENT_THREAD_HANDLE, - *pstatus); + if ((*pstatus = __ntapi->zw_accept_connect_port( + &_hport_client, + port_msg.client_id.process_id, + (nt_port_message *)&port_msg, + NT_LPC_ACCEPT_CONNECTION, + (nt_port_section_write *)0, + (nt_port_section_read *)0))) + return *pstatus; /* finalize connection */ - *pstatus = __ntapi->zw_complete_connect_port(_hport_client); - - if (*pstatus != NT_STATUS_SUCCESS) - __ntapi->zw_terminate_thread( - NT_CURRENT_THREAD_HANDLE, - *pstatus); + *pstatus = __ntapi->zw_complete_connect_port( + _hport_client); return *pstatus; } @@ -122,10 +107,7 @@ int32_t __stdcall __ntapi_dsr_internal_client_connect(nt_daemon_params * params) 0); /* exit the task-specific thread */ - __ntapi->zw_terminate_thread( + return __ntapi->zw_terminate_thread( NT_CURRENT_THREAD_HANDLE, *pstatus); - - /* (no return) */ - return NT_STATUS_INTERNAL_ERROR; } -- cgit v1.2.3