ReactOS  0.4.12-dev-43-g63b00d8
schedsvc.c File Reference
#include "precomp.h"
Include dependency graph for schedsvc.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (schedsvc)
 
static VOID UpdateServiceStatus (DWORD dwState)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
static DWORD ServiceInit (VOID)
 
VOID WINAPI SchedServiceMain (DWORD argc, LPTSTR *argv)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"Schedule"
 
static SERVICE_STATUS_HANDLE ServiceStatusHandle
 
static SERVICE_STATUS ServiceStatus
 
HANDLE Events [2] = {NULL, NULL}
 

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 260 of file schedsvc.c.

263 {
264  switch (fdwReason)
265  {
266  case DLL_PROCESS_ATTACH:
267  DisableThreadLibraryCalls(hinstDLL);
268  break;
269 
270  case DLL_PROCESS_DETACH:
271  break;
272  }
273 
274  return TRUE;
275 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_PROCESS_DETACH
Definition: compat.h:119

◆ SchedServiceMain()

VOID WINAPI SchedServiceMain ( DWORD  argc,
LPTSTR argv 
)

Definition at line 189 of file schedsvc.c.

190 {
191  DWORD dwWait, dwTimeout, dwError;
192 
195 
196  TRACE("SchedServiceMain()\n");
197 
200  NULL);
201  if (!ServiceStatusHandle)
202  {
203  ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
204  return;
205  }
206 
208 
209  dwError = ServiceInit();
210  if (dwError != ERROR_SUCCESS)
211  {
212  ERR("Service stopped (dwError: %lu\n", dwError);
214  return;
215  }
216 
218 
219  dwTimeout = GetNextJobTimeout();
220 
221  for (;;)
222  {
223  /* Wait for the next event */
224  TRACE("Wait for next event!\n");
225  dwWait = WaitForMultipleObjects(2, Events, FALSE, dwTimeout);
226  if (dwWait == WAIT_OBJECT_0)
227  {
228  TRACE("Stop event signaled!\n");
229  break;
230  }
231  else if (dwWait == WAIT_OBJECT_0 + 1)
232  {
233  TRACE("Update event signaled!\n");
234 
236  dwTimeout = GetNextJobTimeout();
238  }
239  else if (dwWait == WAIT_TIMEOUT)
240  {
241  TRACE("Timeout: Start the next job!\n");
242 
244  RunNextJob();
245  dwTimeout = GetNextJobTimeout();
247  }
248  }
249 
250  /* Close the start and update event handles */
251  CloseHandle(Events[0]);
252  CloseHandle(Events[1]);
253 
254  /* Stop the service */
256 }
RTL_RESOURCE JobListLock
Definition: job.c:30
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
VOID RunNextJob(VOID)
Definition: job.c:121
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_START_PENDING
Definition: winsvc.h:22
static WCHAR ServiceName[]
Definition: schedsvc.c:35
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
static char ** argv
Definition: ServiceArgs.c:11
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
DWORD GetNextJobTimeout(VOID)
Definition: job.c:39
HANDLE Events[2]
Definition: schedsvc.c:40
#define TRACE(s)
Definition: solgame.cpp:4
#define WAIT_OBJECT_0
Definition: winbase.h:387
unsigned long DWORD
Definition: ntddk_ex.h:95
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: schedsvc.c:37
#define WAIT_TIMEOUT
Definition: dderror.h:14
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:773
#define ERR(fmt,...)
Definition: debug.h:109
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6079
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: schedsvc.c:76
static DWORD ServiceInit(VOID)
Definition: schedsvc.c:130
static VOID UpdateServiceStatus(DWORD dwState)
Definition: schedsvc.c:46
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 76 of file schedsvc.c.

Referenced by SchedServiceMain().

80 {
81  TRACE("ServiceControlHandler()\n");
82 
83  switch (dwControl)
84  {
87  TRACE(" SERVICE_CONTROL_STOP/SERVICE_CONTROL_SHUTDOWN received\n");
89  /* Stop listening to incoming RPC messages */
91  if (Events[0] != NULL)
92  SetEvent(Events[0]);
93  return ERROR_SUCCESS;
94 
96  TRACE(" SERVICE_CONTROL_PAUSE received\n");
98  return ERROR_SUCCESS;
99 
101  TRACE(" SERVICE_CONTROL_CONTINUE received\n");
103  return ERROR_SUCCESS;
104 
106  TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
108  &ServiceStatus);
109  return ERROR_SUCCESS;
110 
111 #if 0
112  case 128:
113  TRACE(" Start Shell control received\n");
114  return ERROR_SUCCESS;
115 
116  case 129:
117  TRACE(" Logoff control received\n");
118  return ERROR_SUCCESS;
119 #endif
120 
121  default:
122  TRACE(" Control %lu received\n", dwControl);
124  }
125 }
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SERVICE_PAUSED
Definition: winsvc.h:27
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
static SERVICE_STATUS ServiceStatus
Definition: schedsvc.c:38
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
HANDLE Events[2]
Definition: schedsvc.c:40
#define TRACE(s)
Definition: solgame.cpp:4
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: schedsvc.c:37
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
static VOID UpdateServiceStatus(DWORD dwState)
Definition: schedsvc.c:46
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

◆ ServiceInit()

static DWORD ServiceInit ( VOID  )
static

Definition at line 130 of file schedsvc.c.

Referenced by SchedServiceMain().

131 {
132  HANDLE hThread;
133  DWORD dwError;
134 
135  /* Initialize the job list */
137 
138  /* Initialize the job list lock */
140 
141  /* Initialize the start list */
143 
144  /* Initialize the start list lock */
146 
147  /* Load stored jobs from the registry */
148  dwError = LoadJobs();
149  if (dwError != ERROR_SUCCESS)
150  return dwError;
151 
152  /* Start the RPC thread */
153  hThread = CreateThread(NULL,
154  0,
156  NULL,
157  0,
158  NULL);
159  if (!hThread)
160  {
161  ERR("Could not create the RPC thread\n");
162  return GetLastError();
163  }
164 
165  CloseHandle(hThread);
166 
167  /* Create the stop event */
169  if (Events[0] == NULL)
170  {
171  ERR("Could not create the stop event\n");
172  return GetLastError();
173  }
174 
175  /* Create the update event */
177  if (Events[1] == NULL)
178  {
179  ERR("Could not create the update event\n");
180  CloseHandle(Events[0]);
181  return GetLastError();
182  }
183 
184  return ERROR_SUCCESS;
185 }
#define CreateEvent
Definition: winbase.h:3562
RTL_RESOURCE JobListLock
Definition: job.c:30
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LIST_ENTRY StartListHead
Definition: job.c:32
LIST_ENTRY JobListHead
Definition: job.c:29
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpc.c:26
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:112
smooth NULL
Definition: ftsmooth.c:416
HANDLE Events[2]
Definition: schedsvc.c:40
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
unsigned long DWORD
Definition: ntddk_ex.h:95
RTL_RESOURCE StartListLock
Definition: job.c:33
#define ERR(fmt,...)
Definition: debug.h:109
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
HANDLE hThread
Definition: wizard.c:27
LONG LoadJobs(VOID)
Definition: job.c:315

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 46 of file schedsvc.c.

Referenced by SchedServiceMain(), and ServiceControlHandler().

47 {
49  ServiceStatus.dwCurrentState = dwState;
50 
51  if (dwState == SERVICE_PAUSED || dwState == SERVICE_RUNNING)
55  else
57 
61 
62  if (dwState == SERVICE_START_PENDING ||
63  dwState == SERVICE_STOP_PENDING ||
64  dwState == SERVICE_PAUSE_PENDING ||
65  dwState == SERVICE_CONTINUE_PENDING)
66  ServiceStatus.dwWaitHint = 10000;
67  else
69 
71  &ServiceStatus);
72 }
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
static SERVICE_STATUS ServiceStatus
Definition: schedsvc.c:38
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwServiceType
Definition: winsvc.h:99
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: schedsvc.c:37
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( schedsvc  )

Variable Documentation

◆ Events

HANDLE Events[2] = {NULL, NULL}

◆ ServiceName

WCHAR ServiceName[] = L"Schedule"
static

Definition at line 35 of file schedsvc.c.

Referenced by SchedServiceMain().

◆ ServiceStatus

SERVICE_STATUS ServiceStatus
static

Definition at line 38 of file schedsvc.c.

Referenced by SchedEventLogoff(), and SchedStartShell().

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle
static

Definition at line 37 of file schedsvc.c.

Referenced by SchedServiceMain(), ServiceControlHandler(), and UpdateServiceStatus().