/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2011 Index Data
* See the file LICENSE for details.
*/
+/**
+ * \file sc.c
+ * \brief Windows Service Control
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#ifdef WIN32
#include <windows.h>
char *display_name;
int (*sc_main)(yaz_sc_t s, int argc, char **argv);
void (*sc_stop)(yaz_sc_t s);
+ int argc;
+ char **argv;
#ifdef WIN32
SERVICE_STATUS_HANDLE gSvcStatusHandle;
SERVICE_STATUS gSvcStatus;
yaz_sc_t yaz_sc_create(const char *service_name, const char *display_name)
{
- yaz_sc_t s = xmalloc(sizeof(*s));
+ yaz_sc_t s = (yaz_sc_t) xmalloc(sizeof(*s));
s->service_name = service_name ? xstrdup(service_name) : 0;
s->display_name = display_name ? xstrdup(display_name) : 0;
break;
}
}
- *argc_p -= skip_opt;
+ *argc_p = *argc_p - skip_opt;
for (; i < *argc_p; i++)
(*argv_p)[i] = (*argv_p)[i + skip_opt];
+ /* now look for the service arguments */
/* we must have a YAZ log file to work with */
+ skip_opt = 0;
for (i = 1; i < *argc_p; i++)
{
const char *opt = (*argv_p)[i];
}
if (s->run_flag)
{ /* remove -l logfile for a running service */
+ *argc_p = *argc_p - skip_opt;
for (; i < *argc_p; i++)
(*argv_p)[i] = (*argv_p)[i + skip_opt];
+
}
}
sc_ReportSvcStatus(s, SERVICE_START_PENDING, NO_ERROR, 3000);
- ret_code = s->sc_main(s, argc, argv);
+ ret_code = s->sc_main(s, s->argc, s->argv);
sc_ReportSvcStatus(s, SERVICE_STOPPED,
ret_code ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR, ret_code);
for (i = 1; i < argc; i++)
{
wrbuf_puts(w, " ");
+ if (strchr(argv[i], ' '))
+ wrbuf_puts(w, "\"");
wrbuf_puts(w, argv[i]);
+ if (strchr(argv[i], ' '))
+ wrbuf_puts(w, "\"");
}
wrbuf_puts(w, " -run \"");
wrbuf_puts(w, cwdstr);
dt[1].lpServiceName = 0;
dt[1].lpServiceProc = 0;
+ s->argc = argc;
+ s->argv = argv;
if (!StartServiceCtrlDispatcher(dt))
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "Service %s could not be controlled",
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab