main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2007 Jacek Caban for CodeWeavers
  3. * Copyright 2016 Michael Müller
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  18. */
  19. #define WIN32_LEAN_AND_MEAN
  20. #include <windows.h>
  21. #include <winsvc.h>
  22. #include "wine/debug.h"
  23. WINE_DEFAULT_DEBUG_CHANNEL(wuauserv);
  24. static WCHAR wuauservW[] = {'w','u','a','u','s','e','r','v',0};
  25. static SERVICE_STATUS_HANDLE service_handle;
  26. static HANDLE stop_event;
  27. static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
  28. {
  29. SERVICE_STATUS status;
  30. status.dwServiceType = SERVICE_WIN32;
  31. status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
  32. status.dwWin32ExitCode = 0;
  33. status.dwServiceSpecificExitCode = 0;
  34. status.dwCheckPoint = 0;
  35. status.dwWaitHint = 0;
  36. switch(ctrl)
  37. {
  38. case SERVICE_CONTROL_STOP:
  39. case SERVICE_CONTROL_SHUTDOWN:
  40. WINE_TRACE( "shutting down\n" );
  41. status.dwCurrentState = SERVICE_STOP_PENDING;
  42. status.dwControlsAccepted = 0;
  43. SetServiceStatus( service_handle, &status );
  44. SetEvent( stop_event );
  45. return NO_ERROR;
  46. default:
  47. WINE_FIXME( "got service ctrl %x\n", ctrl );
  48. status.dwCurrentState = SERVICE_RUNNING;
  49. SetServiceStatus( service_handle, &status );
  50. return NO_ERROR;
  51. }
  52. }
  53. static void WINAPI serv_main(DWORD argc, LPWSTR *argv)
  54. {
  55. SERVICE_STATUS status;
  56. WINE_TRACE( "starting service\n" );
  57. stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
  58. service_handle = RegisterServiceCtrlHandlerExW( wuauservW, service_handler, NULL );
  59. if (!service_handle)
  60. return;
  61. status.dwServiceType = SERVICE_WIN32;
  62. status.dwCurrentState = SERVICE_RUNNING;
  63. status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
  64. status.dwWin32ExitCode = 0;
  65. status.dwServiceSpecificExitCode = 0;
  66. status.dwCheckPoint = 0;
  67. status.dwWaitHint = 10000;
  68. SetServiceStatus( service_handle, &status );
  69. WaitForSingleObject( stop_event, INFINITE );
  70. status.dwCurrentState = SERVICE_STOPPED;
  71. status.dwControlsAccepted = 0;
  72. SetServiceStatus( service_handle, &status );
  73. WINE_TRACE( "service stopped\n" );
  74. }
  75. int __cdecl main(int argc, char **argv)
  76. {
  77. static const SERVICE_TABLE_ENTRYW servtbl[] =
  78. {
  79. {wuauservW, serv_main},
  80. {NULL, NULL}
  81. };
  82. WINE_TRACE( "(%d %p)\n", argc, argv );
  83. StartServiceCtrlDispatcherW( servtbl );
  84. return 0;
  85. }