rpcss: Remove lazy timeout mechanism and use __wine_make_system_process instead.
This commit is contained in:
parent
0f826e7cc1
commit
b9a6825927
|
@ -4,7 +4,7 @@ SRCDIR = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
MODULE = rpcss.exe
|
||||
APPMODE = -mconsole
|
||||
IMPORTS = kernel32
|
||||
IMPORTS = kernel32 ntdll
|
||||
|
||||
C_SRCS = \
|
||||
epmap_server.c \
|
||||
|
|
|
@ -38,56 +38,22 @@ LONG RPCSS_SrvThreadCount(void)
|
|||
|
||||
BOOL RPCSS_UnBecomePipeServer(void)
|
||||
{
|
||||
BOOL rslt = TRUE;
|
||||
DWORD wait_result;
|
||||
HANDLE master_mutex = RPCSS_GetMasterMutex();
|
||||
|
||||
WINE_TRACE("\n");
|
||||
|
||||
wait_result = WaitForSingleObject(master_mutex, MASTER_MUTEX_TIMEOUT);
|
||||
WINE_TRACE("shutting down pipe.\n");
|
||||
server_live = FALSE;
|
||||
if (!CloseHandle(np_server_end))
|
||||
WINE_WARN("Failed to close named pipe.\n");
|
||||
if (!CloseHandle(np_server_work_event))
|
||||
WINE_WARN("Failed to close the event handle.\n");
|
||||
DeleteCriticalSection(&np_server_cs);
|
||||
|
||||
switch (wait_result) {
|
||||
case WAIT_ABANDONED: /* ? */
|
||||
case WAIT_OBJECT_0:
|
||||
/* we have ownership */
|
||||
break;
|
||||
case WAIT_FAILED:
|
||||
case WAIT_TIMEOUT:
|
||||
default:
|
||||
WINE_ERR("This should never happen: couldn't enter mutex.\n");
|
||||
/* this is totally unacceptable. no graceful out exists */
|
||||
assert(FALSE);
|
||||
}
|
||||
|
||||
/* now that we have the master mutex, we can safely stop
|
||||
listening on the pipe. Before we proceed, we do a final
|
||||
check that it's OK to shut down to ensure atomicity */
|
||||
|
||||
if (!RPCSS_ReadyToDie())
|
||||
rslt = FALSE;
|
||||
else {
|
||||
WINE_TRACE("shutting down pipe.\n");
|
||||
server_live = FALSE;
|
||||
if (!CloseHandle(np_server_end))
|
||||
WINE_WARN("Failed to close named pipe.\n");
|
||||
if (!CloseHandle(np_server_work_event))
|
||||
WINE_WARN("Failed to close the event handle.\n");
|
||||
DeleteCriticalSection(&np_server_cs);
|
||||
}
|
||||
|
||||
if (!ReleaseMutex(master_mutex))
|
||||
WINE_ERR("Unable to leave master mutex!??\n");
|
||||
|
||||
return rslt;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void RPCSS_ServerProcessRANMessage(PRPCSS_NP_MESSAGE pMsg, PRPCSS_NP_REPLY pReply)
|
||||
{
|
||||
WINE_TRACE("\n");
|
||||
/* we do absolutely nothing, but on the server end,
|
||||
the lazy timeout is reset as a result of our connection. */
|
||||
RPCSS_SetMaxLazyTimeout(pMsg->message.ranmsg.timeout);
|
||||
RPCSS_SetLazyTimeRemaining(RPCSS_GetMaxLazyTimeout());
|
||||
pReply->as_uint = 0;
|
||||
}
|
||||
|
||||
|
@ -471,7 +437,7 @@ BOOL RPCSS_BecomePipeServer(void)
|
|||
|
||||
if ((client_handle = RPCSS_NPConnect()) != INVALID_HANDLE_VALUE) {
|
||||
msg.message_type = RPCSS_NP_MESSAGE_TYPEID_RANMSG;
|
||||
msg.message.ranmsg.timeout = RPCSS_GetMaxLazyTimeout();
|
||||
msg.message.ranmsg.timeout = 1000;
|
||||
msg.vardata_payload_size = 0;
|
||||
if (!RPCSS_SendReceiveNPMsg(client_handle, &msg, &reply))
|
||||
WINE_ERR("Something is amiss: RPC_SendReceive failed.\n");
|
||||
|
@ -543,12 +509,15 @@ BOOL RPCSS_BecomePipeServer(void)
|
|||
return rslt;
|
||||
}
|
||||
|
||||
BOOL RPCSS_NPDoWork(void)
|
||||
{
|
||||
DWORD waitresult = WaitForSingleObject(np_server_work_event, 1000);
|
||||
BOOL RPCSS_NPDoWork(HANDLE exit_handle)
|
||||
{
|
||||
HANDLE handles[2];
|
||||
DWORD waitresult;
|
||||
|
||||
handles[0] = np_server_work_event;
|
||||
handles[1] = exit_handle;
|
||||
waitresult = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
|
||||
|
||||
if (waitresult == WAIT_TIMEOUT)
|
||||
return FALSE;
|
||||
if (waitresult == WAIT_OBJECT_0)
|
||||
return TRUE;
|
||||
|
||||
|
|
|
@ -29,15 +29,10 @@
|
|||
|
||||
/* rpcss_main.c */
|
||||
HANDLE RPCSS_GetMasterMutex(void);
|
||||
BOOL RPCSS_ReadyToDie(void);
|
||||
void RPCSS_SetLazyTimeRemaining(long);
|
||||
long RPCSS_GetLazyTimeRemaining(void);
|
||||
void RPCSS_SetMaxLazyTimeout(long);
|
||||
long RPCSS_GetMaxLazyTimeout(void);
|
||||
|
||||
/* epmap_server.c */
|
||||
BOOL RPCSS_EpmapEmpty(void);
|
||||
BOOL RPCSS_NPDoWork(void);
|
||||
BOOL RPCSS_NPDoWork(HANDLE exit_event);
|
||||
void RPCSS_RegisterRpcEndpoints(RPC_SYNTAX_IDENTIFIER iface, int object_count,
|
||||
int binding_count, int no_replace, char *vardata, long vardata_size);
|
||||
void RPCSS_UnregisterRpcEndpoints(RPC_SYNTAX_IDENTIFIER iface, int object_count,
|
||||
|
|
|
@ -67,120 +67,26 @@
|
|||
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
||||
|
||||
static HANDLE master_mutex;
|
||||
static long max_lazy_timeout = RPCSS_DEFAULT_MAX_LAZY_TIMEOUT;
|
||||
static HANDLE exit_event;
|
||||
|
||||
extern HANDLE __wine_make_process_system(void);
|
||||
|
||||
HANDLE RPCSS_GetMasterMutex(void)
|
||||
{
|
||||
return master_mutex;
|
||||
}
|
||||
|
||||
void RPCSS_SetMaxLazyTimeout(long mlt)
|
||||
static BOOL RPCSS_work(HANDLE exit_event)
|
||||
{
|
||||
/* FIXME: this max ensures that no caller will decrease our wait time,
|
||||
but could have other bad results. fix: Store "next_max_lazy_timeout"
|
||||
and install it as necessary next time we "do work"? */
|
||||
max_lazy_timeout = max(RPCSS_GetLazyTimeRemaining(), mlt);
|
||||
}
|
||||
|
||||
long RPCSS_GetMaxLazyTimeout(void)
|
||||
{
|
||||
return max_lazy_timeout;
|
||||
}
|
||||
|
||||
/* when do we just give up and bail? (UTC) */
|
||||
static SYSTEMTIME lazy_timeout_time;
|
||||
|
||||
#if defined(NONAMELESSSTRUCT)
|
||||
# define FILETIME_TO_ULARGEINT(filetime, ularge) \
|
||||
( ularge.u.LowPart = filetime.dwLowDateTime, \
|
||||
ularge.u.HighPart = filetime.dwHighDateTime )
|
||||
# define ULARGEINT_TO_FILETIME(ularge, filetime) \
|
||||
( filetime.dwLowDateTime = ularge.u.LowPart, \
|
||||
filetime.dwHighDateTime = ularge.u.HighPart )
|
||||
#else
|
||||
# define FILETIME_TO_ULARGEINT(filetime, ularge) \
|
||||
( ularge.LowPart = filetime.dwLowDateTime, \
|
||||
ularge.HighPart = filetime.dwHighDateTime )
|
||||
# define ULARGEINT_TO_FILETIME(ularge, filetime) \
|
||||
( filetime.dwLowDateTime = ularge.LowPart, \
|
||||
filetime.dwHighDateTime = ularge.HighPart )
|
||||
#endif /* NONAMELESSSTRUCT */
|
||||
|
||||
#define TEN_MIL ((ULONGLONG)10000000)
|
||||
|
||||
/* returns time remaining in seconds */
|
||||
long RPCSS_GetLazyTimeRemaining(void)
|
||||
{
|
||||
SYSTEMTIME st_just_now;
|
||||
FILETIME ft_jn, ft_ltt;
|
||||
ULARGE_INTEGER ul_jn, ul_ltt;
|
||||
|
||||
GetSystemTime(&st_just_now);
|
||||
SystemTimeToFileTime(&st_just_now, &ft_jn);
|
||||
FILETIME_TO_ULARGEINT(ft_jn, ul_jn);
|
||||
|
||||
SystemTimeToFileTime(&lazy_timeout_time, &ft_ltt);
|
||||
FILETIME_TO_ULARGEINT(ft_ltt, ul_ltt);
|
||||
|
||||
if (ul_jn.QuadPart > ul_ltt.QuadPart)
|
||||
return 0;
|
||||
else
|
||||
return (ul_ltt.QuadPart - ul_jn.QuadPart) / TEN_MIL;
|
||||
}
|
||||
|
||||
void RPCSS_SetLazyTimeRemaining(long seconds)
|
||||
{
|
||||
SYSTEMTIME st_just_now;
|
||||
FILETIME ft_jn, ft_ltt;
|
||||
ULARGE_INTEGER ul_jn, ul_ltt;
|
||||
|
||||
WINE_TRACE("(seconds == %ld)\n", seconds);
|
||||
|
||||
assert(seconds >= 0); /* negatives are not allowed */
|
||||
|
||||
GetSystemTime(&st_just_now);
|
||||
SystemTimeToFileTime(&st_just_now, &ft_jn);
|
||||
FILETIME_TO_ULARGEINT(ft_jn, ul_jn);
|
||||
|
||||
/* we want to find the time ltt, s.t. ltt = just_now + seconds */
|
||||
ul_ltt.QuadPart = ul_jn.QuadPart + seconds * TEN_MIL;
|
||||
|
||||
/* great. just remember it */
|
||||
ULARGEINT_TO_FILETIME(ul_ltt, ft_ltt);
|
||||
if (! FileTimeToSystemTime(&ft_ltt, &lazy_timeout_time))
|
||||
assert(FALSE);
|
||||
}
|
||||
|
||||
#undef FILETIME_TO_ULARGEINT
|
||||
#undef ULARGEINT_TO_FILETIME
|
||||
#undef TEN_MIL
|
||||
|
||||
static BOOL RPCSS_work(void)
|
||||
{
|
||||
return RPCSS_NPDoWork();
|
||||
}
|
||||
|
||||
static BOOL RPCSS_Empty(void)
|
||||
{
|
||||
BOOL rslt = TRUE;
|
||||
|
||||
rslt = RPCSS_EpmapEmpty();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
BOOL RPCSS_ReadyToDie(void)
|
||||
{
|
||||
long ltr = RPCSS_GetLazyTimeRemaining();
|
||||
LONG stc = RPCSS_SrvThreadCount();
|
||||
BOOL empty = RPCSS_Empty();
|
||||
return ( empty && (ltr <= 0) && (stc == 0) );
|
||||
return RPCSS_NPDoWork(exit_event);
|
||||
}
|
||||
|
||||
static BOOL RPCSS_Initialize(void)
|
||||
{
|
||||
WINE_TRACE("\n");
|
||||
|
||||
exit_event = __wine_make_process_system();
|
||||
|
||||
master_mutex = CreateMutexA( NULL, FALSE, RPCSS_MASTER_MUTEX_NAME);
|
||||
if (!master_mutex) {
|
||||
WINE_ERR("Failed to create master mutex\n");
|
||||
|
@ -211,106 +117,30 @@ static BOOL RPCSS_Shutdown(void)
|
|||
|
||||
master_mutex = NULL;
|
||||
|
||||
CloseHandle(exit_event);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void RPCSS_MainLoop(void)
|
||||
{
|
||||
BOOL did_something_new;
|
||||
|
||||
WINE_TRACE("\n");
|
||||
|
||||
for (;;) {
|
||||
did_something_new = FALSE;
|
||||
|
||||
while ( (! did_something_new) && (! RPCSS_ReadyToDie()) )
|
||||
did_something_new = (RPCSS_work() || did_something_new);
|
||||
|
||||
if ((! did_something_new) && RPCSS_ReadyToDie())
|
||||
break; /* that's it for us */
|
||||
|
||||
if (did_something_new)
|
||||
RPCSS_SetLazyTimeRemaining(max_lazy_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL RPCSS_ProcessArgs( int argc, char **argv )
|
||||
{
|
||||
int i;
|
||||
char *c,*c1;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
c = argv[i];
|
||||
while (*c == ' ') c++;
|
||||
if ((*c != '-') && (*c != '/'))
|
||||
return FALSE;
|
||||
c++;
|
||||
switch (*(c++)) {
|
||||
case 't':
|
||||
case 'T':
|
||||
while (*c == ' ') c++;
|
||||
if (*c == '\0') {
|
||||
/* next arg */
|
||||
if (++i >= argc)
|
||||
return FALSE;
|
||||
c = argv[i];
|
||||
while (*c == ' ') c++;
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
} else
|
||||
return FALSE;
|
||||
max_lazy_timeout = strtol(c, &c1, 0);
|
||||
if (c == c1)
|
||||
return FALSE;
|
||||
c = c1;
|
||||
if (max_lazy_timeout <= 0)
|
||||
return FALSE;
|
||||
if (max_lazy_timeout == LONG_MAX)
|
||||
return FALSE;
|
||||
WINE_TRACE("read timeout argument: %ld\n", max_lazy_timeout);
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
while (*c == ' ') c++;
|
||||
if (*c != '\0') return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void RPCSS_Usage(void)
|
||||
{
|
||||
printf("\nWine RPCSS\n");
|
||||
printf("\nsyntax: rpcss [-t timeout]\n\n");
|
||||
printf(" -t: rpcss (or the running rpcss process) will\n");
|
||||
printf(" execute with at least the specified timeout.\n");
|
||||
printf("\n");
|
||||
while ( RPCSS_work(exit_event) )
|
||||
;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
/*
|
||||
* We are invoked as a standard executable; we act in a
|
||||
* "lazy" manner. We open up our pipe, and hang around until we have
|
||||
* nothing left to do, and then silently terminate. When we're needed
|
||||
* again, rpcrt4.dll.so will invoke us automatically.
|
||||
* "lazy" manner. We open up our pipe, and hang around until we all
|
||||
* user processes exit, and then silently terminate.
|
||||
*/
|
||||
|
||||
if (!RPCSS_ProcessArgs(argc, argv)) {
|
||||
RPCSS_Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* we want to wait for something to happen, and then
|
||||
timeout when no activity occurs. */
|
||||
RPCSS_SetLazyTimeRemaining(max_lazy_timeout);
|
||||
|
||||
if (RPCSS_Initialize()) {
|
||||
do
|
||||
RPCSS_MainLoop();
|
||||
while (!RPCSS_Shutdown());
|
||||
RPCSS_MainLoop();
|
||||
RPCSS_Shutdown();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue