Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.7 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1996 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // MODULE: simple.c
  9. //
  10. // PURPOSE: Implements the body of the service.
  11. // The default behavior is to open a
  12. // named pipe, \\.\pipe\simple, and read
  13. // from it. It the modifies the data and
  14. // writes it back to the pipe.
  15. //
  16. // FUNCTIONS:
  17. // ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv);
  18. // ServiceStop( );
  19. //
  20. // COMMENTS: The functions implemented in simple.c are
  21. // prototyped in service.h
  22. //
  23. //
  24. // AUTHOR: Craig Link - Microsoft Developer Support
  25. //
  26. #include <windows.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <process.h>
  30. #include <tchar.h>
  31. #include "service.h"
  32. #include "bootexp.hxx"
  33. // this event is signalled when the
  34. // service should end
  35. //
  36. HANDLE hServerStopEvent = NULL;
  37. //
  38. // FUNCTION: ServiceStart
  39. //
  40. // PURPOSE: Actual code of the service
  41. // that does the work.
  42. //
  43. // PARAMETERS:
  44. // dwArgc - number of command line arguments
  45. // lpszArgv - array of command line arguments
  46. //
  47. // RETURN VALUE:
  48. // none
  49. //
  50. // COMMENTS:
  51. //
  52. VOID
  53. ServiceStart(
  54. DWORD dwArgc,
  55. LPTSTR* lpszArgv
  56. )
  57. {
  58. HANDLE hEvents[2] = {NULL, NULL};
  59. BOOL bRet;
  60. DWORD dwWait;
  61. ///////////////////////////////////////////////////
  62. //
  63. // Service initialization
  64. //
  65. // report the status to the service control manager.
  66. //
  67. if (!ReportStatusToSCMgr(
  68. SERVICE_START_PENDING, // service state
  69. NO_ERROR, // exit code
  70. SERVICE_UPDATE_WAIT_HINT)) // wait hint
  71. goto cleanup;
  72. // create the event object. The control handler function signals
  73. // this event when it receives the "stop" control code.
  74. //
  75. hServerStopEvent = CreateEvent(
  76. NULL, // no security attributes
  77. TRUE, // manual reset event
  78. FALSE, // not-signalled
  79. NULL); // no name
  80. if ( hServerStopEvent == NULL)
  81. goto cleanup;
  82. hEvents[0] = hServerStopEvent;
  83. // report the status to the service control manager.
  84. //
  85. if (!ReportStatusToSCMgr(
  86. SERVICE_START_PENDING, // service state
  87. NO_ERROR, // exit code
  88. SERVICE_UPDATE_WAIT_HINT)) // wait hint
  89. goto cleanup;
  90. InitComLb();
  91. // report the status to the service control manager.
  92. //
  93. if (!ReportStatusToSCMgr(
  94. SERVICE_RUNNING, // service state
  95. NO_ERROR, // exit code
  96. 0)) // wait hint
  97. goto cleanup;
  98. //
  99. // End of initialization
  100. //
  101. ////////////////////////////////////////////////////////
  102. ////////////////////////////////////////////////////////
  103. //
  104. // Service is now running, perform work until shutdown
  105. //
  106. dwWait = WaitForMultipleObjects( 1, hEvents, FALSE, INFINITE );
  107. cleanup:
  108. if (hServerStopEvent)
  109. CloseHandle(hServerStopEvent);
  110. TerminateComLb();
  111. }
  112. //
  113. // FUNCTION: ServiceStop
  114. //
  115. // PURPOSE: Stops the service
  116. //
  117. // PARAMETERS:
  118. // none
  119. //
  120. // RETURN VALUE:
  121. // none
  122. //
  123. // COMMENTS:
  124. // If a ServiceStop procedure is going to
  125. // take longer than 3 seconds to execute,
  126. // it should spawn a thread to execute the
  127. // stop code, and return. Otherwise, the
  128. // ServiceControlManager will believe that
  129. // the service has stopped responding.
  130. //
  131. VOID ServiceStop()
  132. {
  133. if ( hServerStopEvent )
  134. SetEvent(hServerStopEvent);
  135. }