7c38d4781fd4c5b146503b0dad7f0a2d58bfd00bTinderbox User * Copyright (C) 1999-2002, 2004, 2006, 2007, 2009, 2011, 2013-2017 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
23520508907e91343f52e3772bceec9d7855cd32Automatic Updater/* $Id: ntservice.c,v 1.16 2011/01/13 08:50:29 tbox Exp $ */
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer/* Handle to SCM for updating service status */
9bf5a10fbd38128613f86c9143ee8f8a38b06779Andreas Gustafssonstatic SERVICE_STATUS_HANDLE hServiceStatus = 0;
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer * Forward declarations
9bf5a10fbd38128613f86c9143ee8f8a38b06779Andreas Gustafsson * Initialize the Service by registering it.
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer /* Register handler with the SCM */
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer hServiceStatus = RegisterServiceCtrlHandler(BIND_SERVICE_NAME,
9bf5a10fbd38128613f86c9143ee8f8a38b06779Andreas Gustafsson "could not register service control handler");
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews strlcpy(ConsoleTitle, "BIND Version ", sizeof(ConsoleTitle));
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews strlcat(ConsoleTitle, VERSION, sizeof(ConsoleTitle));
0956e3d6074b197eb6aeadd6aa985e60e0dbd15dDanny Mayer * Routine to check if this is a service or a foreground program
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer * ServiceControl(): Handles requests from the SCM and passes them on
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer /* Handle the requested control code */
102e532c659cce054449b5df7850dccc1e8f0ebfDanny Mayer ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
9bf5a10fbd38128613f86c9143ee8f8a38b06779Andreas Gustafsson * Tell the Service Control Manager the state of the service.
8423783bd0292301d78ad19be580fbc4deafd441Danny Mayer ss.dwWaitHint = dwState == SERVICE_STOP_PENDING ? 10000 : 1000;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews/* unhook main */
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * This is the entry point for the executable
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * We can now call bindmain() explicitly or via StartServiceCtrlDispatcher()
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews * as we need to.
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /* Command line users should put -f in the options. */
5a505fc4c2e99842052d9409790c7da0b5663bceMukund Sivaraman while ((ch = isc_commandline_parse(argc, argv, NS_MAIN_ARGS)) != -1) {
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /* run in console window */
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /* Start up as service */
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews rc = StartServiceCtrlDispatcher(dispatchTable);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews "Use -f to run from the command line.\n");
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews /* will be 1063 when launched as a console app */