ntservice.c revision 8423783bd0292301d78ad19be580fbc4deafd441
/*
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: ntservice.c,v 1.1 2001/07/18 03:43:18 mayer Exp $ */
#include <config.h>
#include <stdio.h>
#include <named/ntservice.h>
/* Handle to SCM for updating service status */
static SERVICE_STATUS_HANDLE hServiceStatus = 0;
static int foreground = FALSE;
static char ConsoleTitle[128];
/*
* Forward declarations
*/
void GetArgs(int *, char ***, char ***);
/*
* Here we change the entry point for the executable to bindmain() from main()
* This allows us to invoke as a service or from the command line easily.
*/
/*
* This is the entry point for the executable
* We can now call main() explicitly or via StartServiceCtrlDispatcher()
* as we need to.
*/
int bindmain()
{
int rc,
i = 1;
int argc;
/*
* We changed the entry point function, so we must initialize argv,
* etc. ourselves. Ick.
*/
/* Command line users should put -f in the options */
while (argv[i]) {
foreground = TRUE;
break;
}
i++;
}
if (foreground) {
/* run in console window */
}
else {
/* Start up as service */
char *SERVICE_NAME = BIND_SERVICE_NAME;
{
};
if (!rc)
{
exit(GetLastError());
}
}
exit(0);
}
/*
* Initialize the Service by registering it
*/
void
ntservice_init() {
if (!foreground) {
/* Register handler with the SCM */
if (!hServiceStatus) {
"Could not register service control handler");
exit(1);
}
}
else {
}
}
void
}
/*
* ServiceControl(): Handles requests from the SCM and passes them on
* to named via signals
*/
void
/* Handle the requested control code */
switch(dwCtrlCode) {
UpdateSCM(0);
break;
case SERVICE_CONTROL_STOP:
break;
default:
break;
}
}
/*
* Tell the Service Control Manager the state of the service
*/
if (hServiceStatus) {
if (state)
ss.dwCheckPoint = 0;
}
}
}
/*
* C-runtime stuff used to initialize the app and
* get argv, argc, envp
*/
typedef struct
{
int newmode;
} _startupinfo;
_startupinfo *);
#ifdef _M_IX86
/* Pentium FDIV adjustment */
extern int _adjust_fdiv;
extern int * _imp___adjust_fdiv;
/* Floating point precision */
extern void _setdefaultprecision();
#endif
extern int _newmode; /* malloc new() handler mode */
extern int _dowildcard; /* passed to __getmainargs() */
extern _PVFV *__onexitbegin;
extern _PVFV *__onexitend;
/*
* Do the work that mainCRTStartup() would normally do
*/
{
/*
* Set the app type to Console (check CRT/SRC/INTERNAL.H:
* #define _CONSOLE_APP 1)
*/
__set_app_type(1);
/* Mark this module as an EXE file */
#ifdef _M_IX86
#endif
}