ReactOS  0.4.11-dev-946-g431643b
job.c File Reference
#include "precomp.h"
Include dependency graph for job.c:

Go to the source code of this file.

Classes

struct  _SCHEDULE
 

Typedefs

typedef struct _SCHEDULE SCHEDULE
 
typedef struct _SCHEDULE PSCHEDULE
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (schedsvc)
 
DWORD GetNextJobTimeout (VOID)
 
static VOID ReScheduleJob (PJOB pJob)
 
VOID RunNextJob (VOID)
 
static VOID GetJobName (HKEY hJobsKey, PWSTR pszJobName)
 
LONG SaveJob (_In_ PJOB pJob)
 
LONG DeleteJob (_In_ PJOB pJob)
 
LONG LoadJobs (VOID)
 
static WORD DaysOfMonth (WORD wMonth, WORD wYear)
 
VOID CalculateNextStartTime (_In_ PJOB pJob)
 
VOID InsertJobIntoStartList (_In_ PLIST_ENTRY StartListHead, _In_ PJOB pJob)
 
VOID DumpStartList (_In_ PLIST_ENTRY StartListHead)
 

Variables

DWORD dwNextJobId = 0
 
DWORD dwJobCount = 0
 
LIST_ENTRY JobListHead
 
RTL_RESOURCE JobListLock
 
LIST_ENTRY StartListHead
 
RTL_RESOURCE StartListLock
 

Typedef Documentation

◆ PSCHEDULE

◆ SCHEDULE

Function Documentation

◆ CalculateNextStartTime()

VOID CalculateNextStartTime ( _In_ PJOB  pJob)

Definition at line 468 of file job.c.

Referenced by LoadJobs(), NetrJobAdd(), and ReScheduleJob().

470 {
472  FILETIME FileTime;
473  DWORD_PTR Now;
474 
475  TRACE("CalculateNextStartTime(%p)\n", pJob);
476 
477  GetLocalTime(&StartTime);
478 
479  Now = (DWORD_PTR)StartTime.wHour * 3600000 +
480  (DWORD_PTR)StartTime.wMinute * 60000;
481 
482  StartTime.wMilliseconds = 0;
483  StartTime.wSecond = 0;
484  StartTime.wHour = (WORD)(pJob->JobTime / 3600000);
485  StartTime.wMinute = (WORD)((pJob->JobTime % 3600000) / 60000);
486 
487  if (pJob->DaysOfMonth != 0)
488  {
489  FIXME("Support DaysOfMonth!\n");
490  }
491  else if (pJob->DaysOfWeek != 0)
492  {
493  FIXME("Support DaysOfWeek!\n");
494  }
495  else
496  {
497  /* Start the job tomorrow */
498  if (Now > pJob->JobTime)
499  {
500  if (StartTime.wDay + 1 > DaysOfMonth(StartTime.wMonth, StartTime.wYear))
501  {
502  if (StartTime.wMonth == 12)
503  {
504  StartTime.wDay = 1;
505  StartTime.wMonth = 1;
506  StartTime.wYear++;
507  }
508  else
509  {
510  StartTime.wDay = 1;
511  StartTime.wMonth++;
512  }
513  }
514  else
515  {
516  StartTime.wDay++;
517  }
518  }
519  }
520 
521  TRACE("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour,
522  StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear);
523 
524  SystemTimeToFileTime(&StartTime, &FileTime);
525  pJob->StartTime.u.LowPart = FileTime.dwLowDateTime;
526  pJob->StartTime.u.HighPart = FileTime.dwHighDateTime;
527 }
#define DWORD_PTR
Definition: treelist.c:76
WORD wMonth
Definition: winbase.h:871
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
DWORD dwHighDateTime
Definition: mapidefs.h:66
WORD wYear
Definition: winbase.h:870
#define FIXME(fmt,...)
Definition: debug.h:110
WORD wMinute
Definition: winbase.h:875
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
#define TRACE(s)
Definition: solgame.cpp:4
unsigned short WORD
Definition: ntddk_ex.h:93
WORD wSecond
Definition: winbase.h:876
WORD wMilliseconds
Definition: winbase.h:877
struct tm * Now
Definition: output.c:19
uint32_t DWORD_PTR
Definition: typedefs.h:63
WORD wDay
Definition: winbase.h:873
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:148
WORD wHour
Definition: winbase.h:874
static WORD DaysOfMonth(WORD wMonth, WORD wYear)
Definition: job.c:454
DWORD dwLowDateTime
Definition: mapidefs.h:65

◆ DaysOfMonth()

static WORD DaysOfMonth ( WORD  wMonth,
WORD  wYear 
)
static

Definition at line 454 of file job.c.

Referenced by PrintAllJobs().

457 {
458  WORD wDaysArray[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
459 
460  if (wMonth == 2 && wYear % 4 == 0 && wYear % 400 != 0)
461  return 29;
462 
463  return wDaysArray[wMonth];
464 }
unsigned short WORD
Definition: ntddk_ex.h:93

◆ DeleteJob()

LONG DeleteJob ( _In_ PJOB  pJob)

Definition at line 281 of file job.c.

Referenced by ReScheduleJob().

283 {
284  HKEY hJobsKey = NULL;
285  LONG lError;
286 
287  TRACE("DeleteJob()\n");
288 
290  L"System\\CurrentControlSet\\Services\\Schedule\\Jobs",
291  0,
292  NULL,
294  KEY_WRITE,
295  NULL,
296  &hJobsKey,
297  NULL);
298  if (lError != ERROR_SUCCESS)
299  goto done;
300 
301  lError = RegDeleteKey(hJobsKey,
302  pJob->Name);
303  if (lError != ERROR_SUCCESS)
304  goto done;
305 
306 done:
307  if (hJobsKey != NULL)
308  RegCloseKey(hJobsKey);
309 
310  return lError;
311 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR L[]
Definition: oid.c:1087
#define RegDeleteKey
Definition: winreg.h:502
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

◆ DumpStartList()

VOID DumpStartList ( _In_ PLIST_ENTRY  StartListHead)

Definition at line 582 of file job.c.

Referenced by LoadJobs(), NetrJobAdd(), NetrJobDel(), and ReScheduleJob().

584 {
585  PLIST_ENTRY CurrentEntry;
586  PJOB CurrentJob;
587 
588  CurrentEntry = StartListHead->Flink;
589  while (CurrentEntry != StartListHead)
590  {
591  CurrentJob = CONTAINING_RECORD(CurrentEntry, JOB, StartEntry);
592 
593  TRACE("%3lu: %016I64x\n", CurrentJob->JobId, CurrentJob->StartTime.QuadPart);
594 
595  CurrentEntry = CurrentEntry->Flink;
596  }
597 }
DWORD JobId
Definition: precomp.h:39
ULARGE_INTEGER StartTime
Definition: precomp.h:36
LIST_ENTRY StartListHead
Definition: job.c:32
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
Definition: typedefs.h:117
Definition: precomp.h:31

◆ GetJobName()

static VOID GetJobName ( HKEY  hJobsKey,
PWSTR  pszJobName 
)
static

Definition at line 176 of file job.c.

Referenced by SaveJob().

179 {
180  WCHAR szNameBuffer[JOB_NAME_LENGTH];
181  FILETIME SystemTime;
182  ULONG ulSeed, ulValue;
183  HKEY hKey;
184  LONG lError;
185 
186  GetSystemTimeAsFileTime(&SystemTime);
187  ulSeed = SystemTime.dwLowDateTime;
188  for (;;)
189  {
190  ulValue = RtlRandomEx(&ulSeed);
191  swprintf(szNameBuffer, L"%08lx", ulValue);
192 
193  hKey = NULL;
194  lError = RegOpenKeyEx(hJobsKey,
195  szNameBuffer,
196  0,
197  KEY_READ,
198  &hKey);
199  if (lError != ERROR_SUCCESS)
200  {
201  wcscpy(pszJobName, szNameBuffer);
202  return;
203  }
204 
205  RegCloseKey(hKey);
206  }
207 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
NTSYSAPI ULONG NTAPI RtlRandomEx(PULONG Seed)
#define RegOpenKeyEx
Definition: winreg.h:520
#define JOB_NAME_LENGTH
Definition: precomp.h:23
unsigned int ULONG
Definition: retypes.h:1
DWORD dwLowDateTime
Definition: mapidefs.h:65

◆ GetNextJobTimeout()

DWORD GetNextJobTimeout ( VOID  )

Definition at line 39 of file job.c.

Referenced by SchedServiceMain().

40 {
41  FILETIME FileTime;
42  SYSTEMTIME SystemTime;
43  ULARGE_INTEGER CurrentTime, Timeout;
44  PJOB pNextJob;
45 
47  {
48  TRACE("No job in list! Wait until next update.\n");
49  return INFINITE;
50  }
51 
52  pNextJob = CONTAINING_RECORD((&StartListHead)->Flink, JOB, StartEntry);
53 
54  FileTime.dwLowDateTime = pNextJob->StartTime.u.LowPart;
55  FileTime.dwHighDateTime = pNextJob->StartTime.u.HighPart;
56  FileTimeToSystemTime(&FileTime, &SystemTime);
57 
58  TRACE("Start next job (%lu) at %02hu:%02hu %02hu.%02hu.%hu\n",
59  pNextJob->JobId, SystemTime.wHour, SystemTime.wMinute,
60  SystemTime.wDay, SystemTime.wMonth, SystemTime.wYear);
61 
62  GetLocalTime(&SystemTime);
63  SystemTimeToFileTime(&SystemTime, &FileTime);
64 
65  CurrentTime.u.LowPart = FileTime.dwLowDateTime;
66  CurrentTime.u.HighPart = FileTime.dwHighDateTime;
67 
68  if (CurrentTime.QuadPart >= pNextJob->StartTime.QuadPart)
69  {
70  TRACE("Next event has already gone by!\n");
71  return 0;
72  }
73 
74  Timeout.QuadPart = (pNextJob->StartTime.QuadPart - CurrentTime.QuadPart) / 10000;
75  if (Timeout.u.HighPart != 0)
76  {
77  TRACE("Event happens too far in the future!\n");
78  return INFINITE;
79  }
80 
81  TRACE("Timeout: %lu\n", Timeout.u.LowPart);
82  return Timeout.u.LowPart;
83 }
DWORD JobId
Definition: precomp.h:39
ULARGE_INTEGER StartTime
Definition: precomp.h:36
WORD wMonth
Definition: winbase.h:871
LIST_ENTRY StartListHead
Definition: job.c:32
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
DWORD dwHighDateTime
Definition: mapidefs.h:66
WORD wYear
Definition: winbase.h:870
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
WORD wMinute
Definition: winbase.h:875
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _ULARGE_INTEGER::@3737 u
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:178
WORD wDay
Definition: winbase.h:873
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:148
static ULONG Timeout
Definition: ping.c:61
WORD wHour
Definition: winbase.h:874
#define INFINITE
Definition: serial.h:102
Definition: precomp.h:31
DWORD dwLowDateTime
Definition: mapidefs.h:65

◆ InsertJobIntoStartList()

VOID InsertJobIntoStartList ( _In_ PLIST_ENTRY  StartListHead,
_In_ PJOB  pJob 
)

Definition at line 531 of file job.c.

Referenced by LoadJobs(), NetrJobAdd(), and ReScheduleJob().

534 {
535  PLIST_ENTRY CurrentEntry, PreviousEntry;
536  PJOB CurrentJob;
537 
539  {
540  InsertHeadList(StartListHead, &pJob->StartEntry);
541  return;
542  }
543 
544  CurrentEntry = StartListHead->Flink;
545  while (CurrentEntry != StartListHead)
546  {
547  CurrentJob = CONTAINING_RECORD(CurrentEntry, JOB, StartEntry);
548 
549  if ((CurrentEntry == StartListHead->Flink) &&
550  (pJob->StartTime.QuadPart < CurrentJob->StartTime.QuadPart))
551  {
552  /* Insert before the first entry */
553  InsertHeadList(StartListHead, &pJob->StartEntry);
554  return;
555  }
556 
557  if (pJob->StartTime.QuadPart < CurrentJob->StartTime.QuadPart)
558  {
559  /* Insert between the previous and the current entry */
560  PreviousEntry = CurrentEntry->Blink;
561  pJob->StartEntry.Blink = PreviousEntry;
562  pJob->StartEntry.Flink = CurrentEntry;
563  PreviousEntry->Flink = &pJob->StartEntry;
564  CurrentEntry->Blink = &pJob->StartEntry;
565  return;
566  }
567 
568  if ((CurrentEntry->Flink == StartListHead) &&
569  (pJob->StartTime.QuadPart >= CurrentJob->StartTime.QuadPart))
570  {
571  /* Insert after the last entry */
572  InsertTailList(StartListHead, &pJob->StartEntry);
573  return;
574  }
575 
576  CurrentEntry = CurrentEntry->Flink;
577  }
578 }
ULARGE_INTEGER StartTime
Definition: precomp.h:36
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define InsertTailList(ListHead, Entry)
LIST_ENTRY StartListHead
Definition: job.c:32
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
Definition: precomp.h:31

◆ LoadJobs()

LONG LoadJobs ( VOID  )

Definition at line 315 of file job.c.

Referenced by ServiceInit().

316 {
317  SCHEDULE Schedule;
318  WCHAR szNameBuffer[JOB_NAME_LENGTH];
319  DWORD dwNameLength, dwIndex, dwSize;
320  HKEY hJobsKey = NULL, hJobKey = NULL;
321  PJOB pJob = NULL;
322  LONG lError;
323 
324  TRACE("LoadJobs()\n");
325 
327  L"System\\CurrentControlSet\\Services\\Schedule\\Jobs",
328  0,
329  NULL,
331  KEY_READ,
332  NULL,
333  &hJobsKey,
334  NULL);
335  if (lError != ERROR_SUCCESS)
336  goto done;
337 
338  for (dwIndex = 0; dwIndex < 1000; dwIndex++)
339  {
340  dwNameLength = JOB_NAME_LENGTH;
341  lError = RegEnumKeyEx(hJobsKey,
342  dwIndex,
343  szNameBuffer,
344  &dwNameLength,
345  NULL,
346  NULL,
347  NULL,
348  NULL);
349  if (lError != ERROR_SUCCESS)
350  {
351  lError = ERROR_SUCCESS;
352  break;
353  }
354 
355  TRACE("KeyName: %S\n", szNameBuffer);
356 
357  lError = RegOpenKeyEx(hJobsKey,
358  szNameBuffer,
359  0,
360  KEY_READ,
361  &hJobKey);
362  if (lError != ERROR_SUCCESS)
363  break;
364 
365  dwSize = sizeof(SCHEDULE);
366  lError = RegQueryValueEx(hJobKey,
367  L"Schedule",
368  NULL,
369  NULL,
370  (PBYTE)&Schedule,
371  &dwSize);
372  if (lError == ERROR_SUCCESS)
373  {
374  dwSize = 0;
375  RegQueryValueEx(hJobKey,
376  L"Command",
377  NULL,
378  NULL,
379  NULL,
380  &dwSize);
381  if (dwSize != 0)
382  {
383  /* Allocate a new job object */
384  pJob = HeapAlloc(GetProcessHeap(),
386  sizeof(JOB) + dwSize - sizeof(WCHAR));
387  if (pJob == NULL)
388  {
389  lError = ERROR_OUTOFMEMORY;
390  break;
391  }
392 
393  lError = RegQueryValueEx(hJobKey,
394  L"Command",
395  NULL,
396  NULL,
397  (PBYTE)pJob->Command,
398  &dwSize);
399  if (lError != ERROR_SUCCESS)
400  break;
401 
402  wcscpy(pJob->Name, szNameBuffer);
403  pJob->JobTime = Schedule.JobTime;
404  pJob->DaysOfMonth = Schedule.DaysOfMonth;
405  pJob->DaysOfWeek = Schedule.DaysOfWeek;
406  pJob->Flags = Schedule.Flags;
407 
408  /* Acquire the job list lock exclusively */
410 
411  /* Assign a new job ID */
412  pJob->JobId = dwNextJobId++;
413  dwJobCount++;
414 
415  /* Append the new job to the job list */
417 
418  /* Calculate the next start time */
420 
421  /* Insert the job into the start list */
423 #if 0
425 #endif
426 
427  /* Release the job list lock */
429 
430  pJob = NULL;
431  }
432  }
433 
434  RegCloseKey(hJobKey);
435  hJobKey = NULL;
436  }
437 
438 done:
439  if (pJob != NULL)
440  HeapFree(GetProcessHeap(), 0, pJob);
441 
442  if (hJobKey != NULL)
443  RegCloseKey(hJobKey);
444 
445  if (hJobsKey != NULL)
446  RegCloseKey(hJobsKey);
447 
448  return lError;
449 }
#define RegQueryValueEx
Definition: winreg.h:524
LIST_ENTRY JobEntry
Definition: precomp.h:33
RTL_RESOURCE JobListLock
Definition: job.c:30
DWORD JobId
Definition: precomp.h:39
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
VOID InsertJobIntoStartList(_In_ PLIST_ENTRY StartListHead, _In_ PJOB pJob)
Definition: job.c:531
#define KEY_READ
Definition: nt_native.h:1023
__wchar_t WCHAR
Definition: xmlstorage.h:180
UCHAR DaysOfWeek
Definition: job.c:22
WCHAR Name[JOB_NAME_LENGTH]
Definition: precomp.h:37
#define InsertTailList(ListHead, Entry)
LIST_ENTRY StartListHead
Definition: job.c:32
WCHAR Command[1]
Definition: precomp.h:44
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
LIST_ENTRY JobListHead
Definition: job.c:29
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
UCHAR Flags
Definition: precomp.h:43
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
DWORD_PTR JobTime
Definition: precomp.h:40
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
UCHAR DaysOfWeek
Definition: precomp.h:42
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
struct _SCHEDULE SCHEDULE
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
#define RegEnumKeyEx
Definition: winreg.h:510
UCHAR Flags
Definition: job.c:23
#define RegOpenKeyEx
Definition: winreg.h:520
DWORD JobTime
Definition: job.c:20
#define JOB_NAME_LENGTH
Definition: precomp.h:23
DWORD dwJobCount
Definition: job.c:28
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
Definition: job.c:18
VOID DumpStartList(_In_ PLIST_ENTRY StartListHead)
Definition: job.c:582
DWORD DaysOfMonth
Definition: precomp.h:41
DWORD dwNextJobId
Definition: job.c:27
VOID CalculateNextStartTime(_In_ PJOB pJob)
Definition: job.c:468
DWORD DaysOfMonth
Definition: job.c:21
BYTE * PBYTE
Definition: pedump.c:66
Definition: precomp.h:31
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

◆ ReScheduleJob()

static VOID ReScheduleJob ( PJOB  pJob)
static

Definition at line 88 of file job.c.

Referenced by RunNextJob().

90 {
91  /* Remove the job from the start list */
93 
94  /* Non-periodical job, remove it */
95  if ((pJob->Flags & JOB_RUN_PERIODICALLY) == 0)
96  {
97  /* Remove the job from the registry */
98  DeleteJob(pJob);
99 
100  /* Remove the job from the job list */
101  RemoveEntryList(&pJob->JobEntry);
102  dwJobCount--;
103 
104  /* Free the job object */
105  HeapFree(GetProcessHeap(), 0, pJob);
106  return;
107  }
108 
109  /* Calculate the next start time */
111 
112  /* Insert the job into the start list again */
114 #if 0
116 #endif
117 }
LIST_ENTRY JobEntry
Definition: precomp.h:33
VOID InsertJobIntoStartList(_In_ PLIST_ENTRY StartListHead, _In_ PJOB pJob)
Definition: job.c:531
LIST_ENTRY StartListHead
Definition: job.c:32
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR Flags
Definition: precomp.h:43
#define GetProcessHeap()
Definition: compat.h:395
LIST_ENTRY StartEntry
Definition: precomp.h:35
DWORD dwJobCount
Definition: job.c:28
LONG DeleteJob(_In_ PJOB pJob)
Definition: job.c:281
#define JOB_RUN_PERIODICALLY
Definition: lmat.h:7
VOID DumpStartList(_In_ PLIST_ENTRY StartListHead)
Definition: job.c:582
VOID CalculateNextStartTime(_In_ PJOB pJob)
Definition: job.c:468
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ RunNextJob()

VOID RunNextJob ( VOID  )

Definition at line 121 of file job.c.

Referenced by SchedServiceMain().

122 {
123  PROCESS_INFORMATION ProcessInformation;
124  STARTUPINFOW StartupInfo;
125  BOOL bRet;
126  PJOB pNextJob;
127 
129  {
130  ERR("No job in list!\n");
131  return;
132  }
133 
134  pNextJob = CONTAINING_RECORD((&StartListHead)->Flink, JOB, StartEntry);
135 
136  TRACE("Run job %ld: %S\n", pNextJob->JobId, pNextJob->Command);
137 
138  ZeroMemory(&StartupInfo, sizeof(StartupInfo));
139  StartupInfo.cb = sizeof(StartupInfo);
140  StartupInfo.lpTitle = pNextJob->Command;
141  StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
142  StartupInfo.wShowWindow = SW_SHOWDEFAULT;
143 
144  if ((pNextJob->Flags & JOB_NONINTERACTIVE) == 0)
145  {
146  StartupInfo.dwFlags |= STARTF_INHERITDESKTOP;
147  StartupInfo.lpDesktop = L"WinSta0\\Default";
148  }
149 
150  bRet = CreateProcessW(NULL,
151  pNextJob->Command,
152  NULL,
153  NULL,
154  FALSE,
156  NULL,
157  NULL,
158  &StartupInfo,
159  &ProcessInformation);
160  if (bRet == FALSE)
161  {
162  ERR("CreateProcessW() failed (Error %lu)\n", GetLastError());
163  }
164  else
165  {
166  CloseHandle(ProcessInformation.hThread);
167  CloseHandle(ProcessInformation.hProcess);
168  }
169 
170  ReScheduleJob(pNextJob);
171 }
DWORD JobId
Definition: precomp.h:39
#define SW_SHOWDEFAULT
Definition: winuser.h:774
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
LIST_ENTRY StartListHead
Definition: job.c:32
WCHAR Command[1]
Definition: precomp.h:44
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR Flags
Definition: precomp.h:43
LPWSTR lpDesktop
Definition: winbase.h:819
#define STARTF_INHERITDESKTOP
Definition: undocuser.h:162
smooth NULL
Definition: ftsmooth.c:416
LPWSTR lpTitle
Definition: winbase.h:820
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4623
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
DWORD cb
Definition: winbase.h:817
#define JOB_NONINTERACTIVE
Definition: lmat.h:11
static VOID ReScheduleJob(PJOB pJob)
Definition: job.c:88
static const WCHAR L[]
Definition: oid.c:1087
WORD wShowWindow
Definition: winbase.h:829
#define ERR(fmt,...)
Definition: debug.h:109
DWORD dwFlags
Definition: winbase.h:828
Definition: precomp.h:31

◆ SaveJob()

LONG SaveJob ( _In_ PJOB  pJob)

Definition at line 211 of file job.c.

Referenced by NetrJobAdd().

213 {
214  SCHEDULE Schedule;
215  HKEY hJobsKey = NULL, hJobKey = NULL;
216  LONG lError;
217 
218  TRACE("SaveJob()\n");
219 
221  L"System\\CurrentControlSet\\Services\\Schedule\\Jobs",
222  0,
223  NULL,
225  KEY_WRITE,
226  NULL,
227  &hJobsKey,
228  NULL);
229  if (lError != ERROR_SUCCESS)
230  goto done;
231 
232  GetJobName(hJobsKey, pJob->Name);
233 
234  lError = RegCreateKeyExW(hJobsKey,
235  pJob->Name,
236  0,
237  NULL,
239  KEY_WRITE,
240  NULL,
241  &hJobKey,
242  NULL);
243  if (lError != ERROR_SUCCESS)
244  goto done;
245 
246  Schedule.JobTime = pJob->JobTime;
247  Schedule.DaysOfMonth = pJob->DaysOfMonth;
248  Schedule.DaysOfWeek = pJob->DaysOfWeek;
249  Schedule.Flags = pJob->Flags;
250 
251  lError = RegSetValueEx(hJobKey,
252  L"Schedule",
253  0,
254  REG_BINARY,
255  (PBYTE)&Schedule,
256  sizeof(Schedule));
257  if (lError != ERROR_SUCCESS)
258  goto done;
259 
260  lError = RegSetValueEx(hJobKey,
261  L"Command",
262  0,
263  REG_SZ,
264  (PBYTE)pJob->Command,
265  (wcslen(pJob->Command) + 1) * sizeof(WCHAR));
266  if (lError != ERROR_SUCCESS)
267  goto done;
268 
269 done:
270  if (hJobKey != NULL)
271  RegCloseKey(hJobKey);
272 
273  if (hJobsKey != NULL)
274  RegCloseKey(hJobsKey);
275 
276  return lError;
277 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
__wchar_t WCHAR
Definition: xmlstorage.h:180
static VOID GetJobName(HKEY hJobsKey, PWSTR pszJobName)
Definition: job.c:176
UCHAR DaysOfWeek
Definition: job.c:22
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR L[]
Definition: oid.c:1087
UCHAR Flags
Definition: job.c:23
DWORD JobTime
Definition: job.c:20
Definition: job.c:18
DWORD DaysOfMonth
Definition: job.c:21
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RegSetValueEx
Definition: winreg.h:533
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( schedsvc  )

Variable Documentation

◆ dwJobCount

DWORD dwJobCount = 0

Definition at line 28 of file job.c.

Referenced by LoadJobs(), NetrJobAdd(), NetrJobDel(), NetrJobEnum(), and ReScheduleJob().

◆ dwNextJobId

DWORD dwNextJobId = 0

Definition at line 27 of file job.c.

Referenced by LoadJobs(), and NetrJobAdd().

◆ JobListHead

LIST_ENTRY JobListHead

Definition at line 29 of file job.c.

Referenced by NetrJobAdd(), NetrJobDel(), NetrJobEnum(), NetrJobGetInfo(), and ServiceInit().

◆ JobListLock

RTL_RESOURCE JobListLock

Definition at line 30 of file job.c.

Referenced by NetrJobAdd(), NetrJobDel(), NetrJobEnum(), NetrJobGetInfo(), SchedServiceMain(), and ServiceInit().

◆ StartListHead

LIST_ENTRY StartListHead

Definition at line 32 of file job.c.

Referenced by NetrJobAdd(), NetrJobDel(), and ServiceInit().

◆ StartListLock

RTL_RESOURCE StartListLock

Definition at line 33 of file job.c.

Referenced by ServiceInit().