mingw work.

git-svn-id: file:///svn/unbound/trunk@1506 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2009-03-02 16:43:10 +00:00
parent 97a3830515
commit eafa979e0f
16 changed files with 5636 additions and 6717 deletions

View file

@ -122,12 +122,22 @@ ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.lo) \
$(addprefix compat/,$(LIBOBJS:.o=.lo))) $(COMPAT_OBJ)
ifeq "$(UB_ON_WINDOWS)" "yes"
DAEMON_SRC+=$(patsubst $(srcdir)/%,%, $(wildcard $(srcdir)/winrc/*.c))
DAEMON_SRC+=winrc/win_svc.c
DAEMON_OBJ+=$(BUILD)winrc/rsrc_unbound.o $(BUILD)winrc/win_svc.lo
HOST_OBJ+=$(BUILD)winrc/rsrc_unbound_host.o
CONTROL_OBJ+=$(BUILD)winrc/rsrc_unbound_control.o
CHECKCONF_OBJ+=$(BUILD)winrc/rsrc_unbound_checkconf.o
WINAPPS=unbound-service-install unbound-service-remove
SVCINST_SRC=winrc/unbound-service-install.c
SVCINST_OBJ=$(addprefix $(BUILD),$(SVCINST_SRC:.c=.lo)) $(COMPAT_OBJ) \
$(BUILD)winrc/rsrc_svcinst.o
SVCUNINST_SRC=winrc/unbound-service-remove.c
SVCUNINST_OBJ=$(addprefix $(BUILD),$(SVCUNINST_SRC:.c=.lo)) $(COMPAT_OBJ) \
$(BUILD)winrc/rsrc_svcinst.o
ALL_SRC:=$(sort $(ALL_SRC) $(SVCINST_SRC) $(SVCUNINST_SRC))
ALL_OBJ:=$(sort $(ALL_OBJ) $(SVCINST_OBJ) $(SVCUNINST_OBJ))
$(BUILD)%.o: $(srcdir)/%.rc $(srcdir)/config.h
$(INFO) Resource $<
@if test ! -z "$(ldnsdir)" -a ! -e $(ldnsdir)/include/ldns/ldns.h; \
@ -149,7 +159,7 @@ $(BUILD)%.lo: $(srcdir)/%.c
@-if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi
$Q$(COMPILE) -c $< -o $@
all: $(COMMON_OBJ) unbound unbound-checkconf lib unbound-host unbound-control unbound-control-setup
all: $(COMMON_OBJ) unbound unbound-checkconf lib unbound-host unbound-control unbound-control-setup $(WINAPPS)
TEST_BIN=asynclook delayer harvest lock-verify memstats perf pktview signit \
streamtcp testbound unittest
@ -189,6 +199,14 @@ unbound-host: $(HOST_OBJ) libunbound.la $(ldnslib)
$(INFO) Link $@
$Q$(LINK) -o $@ $(sort $(HOST_OBJ)) -L. -L.libs -lunbound $(LIBS)
unbound-service-install: $(SVCINST_OBJ)
$(INFO) Link $@
$Q$(LINK) -o $@ $(sort $(SVCINST_OBJ)) $(LIBS)
unbound-service-remove: $(SVCUNINST_OBJ)
$(INFO) Link $@
$Q$(LINK) -o $@ $(sort $(SVCUNINST_OBJ)) $(LIBS)
unittest: $(UNITTEST_OBJ) $(ldnslib)
$(INFO) Link $@
$Q$(LINK) -o $@ $(sort $(UNITTEST_OBJ)) $(LIBS)

11895
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.56)
AC_INIT(unbound, 1.3.0, unbound-bugs@nlnetlabs.nl, unbound)
AC_INIT(unbound, 1.3.0_20090302, unbound-bugs@nlnetlabs.nl, unbound)
LIBUNBOUND_CURRENT=1
LIBUNBOUND_REVISION=0

View file

@ -45,6 +45,9 @@
#include "util/locks.h"
#include "util/alloc.h"
#include "services/modstack.h"
#ifdef UB_ON_WINDOWS
# include "util/winsock_event.h"
#endif
struct config_file;
struct worker;
struct listen_port;
@ -96,6 +99,12 @@ struct daemon {
struct timeval time_last_stat;
/** time when daemon started */
struct timeval time_boot;
#ifdef UB_ON_WINDOWS
/** stop signaling event - not owned by this structure */
WSAEVENT stop_event;
/** event structure for callback */
struct event stop_ev;
#endif
};
/**

View file

@ -579,6 +579,7 @@ main(int argc, char* argv[])
{
int c;
const char* cfgfile = CONFIGFILE;
const char* winopt = NULL;
int cmdline_verbose = 0;
int debug_mode = 0;
@ -602,11 +603,7 @@ main(int argc, char* argv[])
debug_mode = 1;
break;
case 'w':
#ifdef UB_ON_WINDOWS
wsvc_command_option(optarg);
#else
fatal_exit("option not supported");
#endif
winopt = optarg;
break;
case '?':
case 'h':
@ -618,6 +615,14 @@ main(int argc, char* argv[])
argc -= optind;
argv += optind;
if(winopt) {
#ifdef UB_ON_WINDOWS
wsvc_command_option(winopt, cfgfile, cmdline_verbose);
#else
fatal_exit("option not supported");
#endif
}
if(argc != 0) {
usage();
return 1;

View file

@ -997,6 +997,17 @@ worker_create(struct daemon* daemon, int id, int* ports, int n)
return worker;
}
#ifdef UB_ON_WINDOWS
static void
ub_win_stop(int ATTR_UNUSED(fd), short ATTR_UNUSED(ev), void* arg)
{
struct worker* worker = (struct worker*)arg;
verbose(VERB_QUERY, "caught stop signal (wsaevent)");
worker->need_to_exit = 1;
comm_base_exit(worker->base);
}
#endif /* UB_ON_WINDOWS */
int
worker_init(struct worker* worker, struct config_file *cfg,
struct listen_port* ports, int do_sigs)
@ -1044,6 +1055,15 @@ worker_init(struct worker* worker, struct config_file *cfg,
worker_delete(worker);
return 0;
}
#ifdef UB_ON_WINDOWS
if(!winsock_register_wsaevent(comm_base_internal(worker->base),
&worker->daemon->stop_ev, worker->daemon->stop_event,
ub_win_stop, worker)) {
log_err("could not register wsaevent");
worker_delete(worker);
return 0;
}
#endif /* UB_ON_WINDOWS */
} else { /* !do_sigs */
worker->comsig = NULL;
worker->rc = NULL;

View file

@ -5,6 +5,7 @@
- iana portlist updated.
- document FAQ entry on stub/forward zones and default blocking.
- fix asynclook test app for libunbound not exporting symbols.
- service install and remove utils that work with vista UAC.
27 February 2009: Wouter
- Fixup lexer, to not give warnings about fwrite. Appeared in

View file

@ -149,8 +149,13 @@ done
if [ "$DOWIN" = "yes" ]; then
version=`./configure --version | head -1 | awk '{ print $3 }'` \
|| error_cleanup "Cannot determine version number."
if [ "$RC" != "no" ]; then
version2=`echo $version | sed -e 's/rc.*//'`"rc$RC"
if [ "$RC" != "no" -o "$SNAPSHOT" != "no" ]; then
if [ "$RC" != "no" ]; then
version2=`echo $version | sed -e 's/rc.*//'`"rc$RC"
fi
if [ "$SNAPSHOT" != "no" ]; then
version2="${version}_`date +%Y%m%d`"
fi
replace_text "configure.ac" "AC_INIT(unbound, $version" "AC_INIT(unbound, $version2"
version="$version2"
info "Rebuilding configure script (autoconf) snapshot."
@ -176,14 +181,9 @@ if [ "$DOWIN" = "yes" ]; then
mkdir tmp.$$
cd tmp.$$
cp ../doc/example.conf example.conf
cp ../unbound.exe unbound.exe
cp ../unbound-host.exe unbound-host.exe
cp ../unbound-control.exe unbound-control.exe
cp ../unbound-checkconf.exe unbound-checkconf.exe
cp ../LICENSE LICENSE
cp ../winrc/unbound-website.url unbound-website.url
cp ../winrc/service.conf service.conf
zip ../$file LICENSE unbound.exe unbound-host.exe unbound-control.exe unbound-checkconf.exe example.conf service.conf unbound-website.url
cp ../unbound.exe ../unbound-host.exe ../unbound-control.exe ../unbound-checkconf.exe ../unbound-service-install.exe ../unbound-service-remove.exe ../LICENSE ../winrc/unbound-website.url ../winrc/service.conf .
strip *.exe
zip ../$file LICENSE unbound.exe unbound-host.exe unbound-control.exe unbound-checkconf.exe unbound-service-install.exe unbound-service-remove.exe example.conf service.conf unbound-website.url
info "Testing $file"
cd ..
rm -rf tmp.$$

View file

@ -319,7 +319,8 @@ int remote_control_callback(struct comm_point* ATTR_UNUSED(c),
return 0;
}
void wsvc_command_option(const char* ATTR_UNUSED(opt))
void wsvc_command_option(const char* ATTR_UNUSED(wopt),
const char* ATTR_UNUSED(cfgfile), int ATTR_UNUSED(v))
{
log_assert(0);
}

48
winrc/rsrc_svcinst.rc Normal file
View file

@ -0,0 +1,48 @@
/*
Unbound resource file for windows. For use with windres
*/
#include "winver.h"
#include "config.h"
1 ICON "winrc/unbound64.ico"
2 ICON "winrc/unbound48.ico"
3 ICON "winrc/unbound32.ico"
4 ICON "winrc/unbound16.ico"
1 VERSIONINFO
FILEVERSION RSRC_PACKAGE_VERSION
PRODUCTVERSION RSRC_PACKAGE_VERSION
FILEFLAGSMASK 0
FILEFLAGS 0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "NLnet Labs"
VALUE "FileDescription", "Unbound Service Install Util"
VALUE "FileVersion", PACKAGE_VERSION
VALUE "InternalName", "unbound-service-install"
VALUE "OriginalFilename", "unbound-service-install.exe"
VALUE "ProductName", "unbound"
VALUE "ProductVersion", PACKAGE_VERSION
VALUE "LegalCopyright", "(C) 2009 NLnet Labs. Source is BSD licensed."
END
END
BLOCK "VarFileInfo"
BEGIN
/* English(409), windows ANSI codepage (1252) */
VALUE "Translation", 0x409, 0x1252
END
END
/* error message formats */
LANGUAGE 0x9,0x1
1 11 "winrc/gen_msg.bin"
/* vista administrator access, show UAC prompt */
1 RT_MANIFEST "winrc/vista_admin.manifest"

View file

@ -39,5 +39,6 @@ BEGIN
END
END
/* error message formats */
LANGUAGE 0x9,0x1
1 11 "winrc/gen_msg.bin"

View file

@ -0,0 +1,142 @@
/*
* winrc/unbound-service-install.c - windows services installation util
*
* Copyright (c) 2009, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
*
* This file contains functions to integrate with the windows services API.
* This means it handles the commandline switches to install and remove
* the service (via CreateService and DeleteService), it handles
* the ServiceMain() main service entry point when started as a service,
* and it handles the Handler[_ex]() to process requests to the service
* (such as start and stop and status).
*/
#include "config.h"
#include "winrc/win_svc.h"
/** service name for unbound (internal to ServiceManager) */
#define SERVICE_NAME "unbound"
/** output for diagnostics */
static FILE *out;
/** exit with windows error */
static void
fatal_win(const char* str)
{
fprintf(out, "%s (%d)\n", str, (int)GetLastError());
exit(1);
}
/** put quotes around string. Needs one space in front
* @param str: to be quoted.
* @param maxlen: max length of the string buffer.
*/
static void
quote_it(char* str, size_t maxlen)
{
if(strlen(str) == maxlen) {
fprintf(out, "string too long %s", str);
exit(1);
}
str[0]='"';
str[strlen(str)+1]=0;
str[strlen(str)]='"';
}
/** change suffix */
static void
change(char* path, size_t max, const char* from, const char* to)
{
size_t fromlen = strlen(from);
size_t tolen = strlen(to);
size_t pathlen = strlen(path);
if(pathlen - fromlen + tolen >= max) {
fprintf(out, "string too long %s", path);
exit(1);
}
snprintf(path+pathlen-fromlen, max-(pathlen-fromlen), "%s", to);
}
/** Install service in servicecontrolmanager */
static void
wsvc_install(void)
{
SC_HANDLE scm;
SC_HANDLE sv;
TCHAR path[MAX_PATH+2+256];
fprintf(out, "installing unbound service\n");
if(!GetModuleFileName(NULL, path+1, MAX_PATH))
fatal_win("could not GetModuleFileName");
/* change 'unbound-service-install' to 'unbound' */
change(path, sizeof(path), "-service-install.exe", ".exe");
/* have to quote it because of spaces in directory names */
/* could append arguments to be sent to ServiceMain */
quote_it(path, sizeof(path));
strcat(path, " -w service");
scm = OpenSCManager(NULL, NULL, (int)SC_MANAGER_CREATE_SERVICE);
if(!scm) fatal_win("could not OpenSCManager");
sv = CreateService(
scm,
SERVICE_NAME, /* name of service */
"Unbound DNS validator", /* display name */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */
SERVICE_ERROR_NORMAL, /* error control type */
path, /* path to service's binary */
NULL, /* no load ordering group */
NULL, /* no tag identifier */
NULL, /* no deps */
NULL, /* on LocalSystem */
NULL /* no password */
);
if(!sv) {
CloseServiceHandle(scm);
fatal_win("could not CreateService");
}
CloseServiceHandle(sv);
CloseServiceHandle(scm);
fprintf(out, "unbound service installed\n");
}
/** Install service main */
int main(int ATTR_UNUSED(argc), char** ATTR_UNUSED(argv))
{
out = fopen("unbound-service-install.log", "w");
wsvc_install();
return 0;
}

View file

@ -0,0 +1,91 @@
/*
* winrc/unbound-service-install.c - windows services installation util
*
* Copyright (c) 2009, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
*
* This file contains functions to integrate with the windows services API.
* This means it handles the commandline switches to install and remove
* the service (via CreateService and DeleteService), it handles
* the ServiceMain() main service entry point when started as a service,
* and it handles the Handler[_ex]() to process requests to the service
* (such as start and stop and status).
*/
#include "config.h"
#include "winrc/win_svc.h"
/** service name for unbound (internal to ServiceManager) */
#define SERVICE_NAME "unbound"
/** output file for diagnostics */
static FILE* out = NULL;
/** exit with windows error */
static void
fatal_win(const char* str)
{
fprintf(out, "%s (%d)\n", str, (int)GetLastError());
exit(1);
}
/** Remove installed service from servicecontrolmanager */
static void
wsvc_remove(void)
{
SC_HANDLE scm;
SC_HANDLE sv;
fprintf(out, "removing unbound service\n");
scm = OpenSCManager(NULL, NULL, (int)SC_MANAGER_ALL_ACCESS);
if(!scm) fatal_win("could not OpenSCManager");
sv = OpenService(scm, SERVICE_NAME, DELETE);
if(!sv) {
CloseServiceHandle(scm);
fatal_win("could not OpenService");
}
if(!DeleteService(sv)) {
fatal_win("could not DeleteService");
}
CloseServiceHandle(sv);
CloseServiceHandle(scm);
fprintf(out, "unbound service removed\n");
}
/** Install service main */
int main(int ATTR_UNUSED(argc), char** ATTR_UNUSED(argv))
{
out = fopen("unbound-service-remove.log", "w");
wsvc_remove();
return 0;
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86" name="unbound-service-install.exe" type="win32"/>
<description>Installs or removes the unbound service in the services control panel</description>
<!-- Identify the application security requirements. -->
<ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
<ms_asmv2:security>
<ms_asmv2:requestedPrivileges>
<ms_asmv2:requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</ms_asmv2:requestedPrivileges>
</ms_asmv2:security>
</ms_asmv2:trustInfo>
</assembly>

View file

@ -65,7 +65,11 @@ SERVICE_STATUS service_status;
/** global service status handle */
SERVICE_STATUS_HANDLE service_status_handle;
/** global service stop event */
HANDLE service_stop_event = NULL;
WSAEVENT service_stop_event = NULL;
/** config file to open. global communication to service_main() */
const char* service_cfgfile = CONFIGFILE;
/** commandline verbosity. global communication to service_main() */
int service_cmdline_verbose = 0;
/** exit with windows error */
static void
@ -182,7 +186,9 @@ hdlr(DWORD ctrl)
if(ctrl == SERVICE_CONTROL_STOP) {
report_status(SERVICE_STOP_PENDING, NO_ERROR, 0);
/* send signal to stop */
SetEvent(service_stop_event);
if(!WSASetEvent(service_stop_event))
log_err("Could not WSASetEvent: %s",
wsa_strerror(WSAGetLastError()));
return;
} else {
/* ctrl == SERVICE_CONTROL_INTERROGATE or whatever */
@ -231,7 +237,9 @@ service_init(struct daemon** d, struct config_file** c)
{
struct config_file* cfg = NULL;
struct daemon* daemon = NULL;
const char* cfgfile = CONFIGFILE;
const char* logfile= "C:\\unbound.log";
verbosity=4; service_cmdline_verbose=4;
log_init(logfile, 0, NULL); /* DEBUG logfile */
/* create daemon */
daemon = daemon_init();
@ -241,7 +249,7 @@ service_init(struct daemon** d, struct config_file** c)
/* read config */
cfg = config_create();
if(!cfg) return 0;
if(!config_read(cfg, cfgfile, daemon->chroot)) {
if(!config_read(cfg, service_cfgfile, daemon->chroot)) {
if(errno != ENOENT) {
/* could not read config file */
return 0;
@ -251,12 +259,12 @@ service_init(struct daemon** d, struct config_file** c)
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
/* apply settings and init */
verbosity = cfg->verbosity;
verbosity = cfg->verbosity + service_cmdline_verbose;
if(cfg->directory && cfg->directory[0]) {
if(chdir(cfg->directory)) return 0;
verbose(VERB_QUERY, "chdir to %s", cfg->directory);
}
log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
/* log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir); DEBUG*/
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
daemon_apply_cfg(daemon, cfg);
@ -304,30 +312,24 @@ service_main(DWORD ATTR_UNUSED(argc), LPTSTR* ATTR_UNUSED(argv))
/* event that gets signalled when we want to quit; it
* should get registered in the worker-0 waiting loop. */
service_stop_event = CreateEvent(NULL, 1, 0, NULL);
if(!service_stop_event) {
reportev("Could not CreateEvent");
service_stop_event = WSACreateEvent();
if(service_stop_event == WSA_INVALID_EVENT) {
log_err("WSACreateEvent: %s", wsa_strerror(WSAGetLastError()));
reportev("Could not WSACreateEvent");
report_status(SERVICE_STOPPED, NO_ERROR, 0);
return;
}
daemon->stop_event = service_stop_event;
/* SetServiceStatus SERVICE_RUNNING;*/
report_status(SERVICE_RUNNING, NO_ERROR, 0);
/* daemon_fork(daemon) , but wait on stop event ! */
/* instead of this while loop */
/* wait until exit */
while(1) {
WaitForSingleObject(service_stop_event, INFINITE);
report_status(SERVICE_STOPPED, NO_ERROR, 0);
FILE* out = fopen("C:\\output.txt", "a");
fprintf(out, "stopped!\n");
fclose(out);
return;
}
/* daemon performs work */
daemon_fork(daemon);
/* exit */
verbose(VERB_ALGO, "cleanup.");
report_status(SERVICE_STOP_PENDING, NO_ERROR, 0);
daemon_cleanup(daemon);
config_delete(cfg);
daemon_delete(daemon);
@ -336,11 +338,15 @@ service_main(DWORD ATTR_UNUSED(argc), LPTSTR* ATTR_UNUSED(argv))
/** start the service */
static void
service_start()
service_start(const char* cfgfile, int v)
{
SERVICE_TABLE_ENTRY myservices[2] = {
{SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)service_main},
{NULL, NULL} };
log_init("C:\\unbound.log", 0, 0);
log_info("open logfile");
service_cfgfile = cfgfile;
service_cmdline_verbose = v;
/* this call returns when service has stopped. */
if(!StartServiceCtrlDispatcher(myservices)) {
reportev("Could not StartServiceCtrlDispatcher");
@ -348,14 +354,14 @@ service_start()
}
void
wsvc_command_option(const char* str)
wsvc_command_option(const char* wopt, const char* cfgfile, int v)
{
if(strcmp(str, "install") == 0)
if(strcmp(wopt, "install") == 0)
wsvc_install();
else if(strcmp(str, "remove") == 0)
else if(strcmp(wopt, "remove") == 0)
wsvc_remove();
else if(strcmp(str, "service") == 0)
service_start();
else fatal_exit("unknown option: %s", str);
else if(strcmp(wopt, "service") == 0)
service_start(cfgfile, v);
else fatal_exit("unknown option: %s", wopt);
exit(0);
}

View file

@ -49,8 +49,10 @@
/**
* Handle commandline service for windows.
* @param str: option
* @param wopt: windows option string (install, remove, service).
* @param cfgfile: configfile to open (default or passed with -c).
* @param v: amount of commandline verbosity added with -v.
*/
void wsvc_command_option(const char* str);
void wsvc_command_option(const char* wopt, const char* cfgfile, int v);
#endif /* WINRC_WIN_SVC_H */