From: Adam Dickmeiss Date: Tue, 22 Apr 2008 10:21:11 +0000 (+0200) Subject: Incorporate Windos services (sc). X-Git-Tag: PAZPAR2.1.0.8~6 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5fdac8e7a282d625568f5768bd3ae9367dd4acaf;p=pazpar2-moved-to-github.git Incorporate Windos services (sc). --- diff --git a/configure.ac b/configure.ac index 0bb54cd..3f13a47 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ AC_PROG_RANLIB AC_LANG(C) -YAZ_INIT([static threads],[3.0.25]) +YAZ_INIT([static threads],[3.0.29]) if test -z "$YAZLIB"; then AC_MSG_ERROR([YAZ development libraries missing]) fi diff --git a/src/eventl.c b/src/eventl.c index 518b69e..3b689cd 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -110,7 +110,10 @@ int event_loop(IOCHAN *iochans) if (errno == EINTR) continue; else - abort(); + { + yaz_log(YLOG_ERRNO|YLOG_WARN, "select"); + return 0; + } } for (p = *iochans; p; p = p->next) { diff --git a/src/http.c b/src/http.c index c68318a..642465f 100644 --- a/src/http.c +++ b/src/http.c @@ -701,10 +701,10 @@ struct http_header * http_header_append(struct http_channel *ch, static int is_inprogress(void) { #ifdef WIN32 - if (WSAGetLastError() != WSAEWOULDBLOCK) + if (WSAGetLastError() == WSAEWOULDBLOCK) return 1; #else - if (errno != EINPROGRESS) + if (errno == EINPROGRESS) return 1; #endif return 0; @@ -1121,8 +1121,10 @@ static void http_accept(IOCHAN i, int event) pazpar2_add_channel(c); } +static int listener_socket = 0; + /* Create a http-channel listener, syntax [host:]port */ -void http_init(const char *addr) +int http_init(const char *addr) { IOCHAN c; int l; @@ -1147,7 +1149,7 @@ void http_init(const char *addr) hostname[len] = '\0'; if (!(he = gethostbyname(hostname))){ yaz_log(YLOG_FATAL, "Unable to resolve '%s'", hostname); - exit(1); + return 1; } memcpy(&myaddr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); @@ -1162,27 +1164,43 @@ void http_init(const char *addr) myaddr.sin_port = htons(port); if (!(p = getprotobyname("tcp"))) { - abort(); + return 1; } if ((l = socket(PF_INET, SOCK_STREAM, p->p_proto)) < 0) yaz_log(YLOG_FATAL|YLOG_ERRNO, "socket"); if (setsockopt(l, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof(one)) < 0) - abort(); + return 1; if (bind(l, (struct sockaddr *) &myaddr, sizeof myaddr) < 0) { yaz_log(YLOG_FATAL|YLOG_ERRNO, "bind"); - exit(1); + return 1; } if (listen(l, SOMAXCONN) < 0) { yaz_log(YLOG_FATAL|YLOG_ERRNO, "listen"); - exit(1); + return 1; } + listener_socket = l; + c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT); pazpar2_add_channel(c); + return 0; +} + +void http_close_server(void) +{ + /* break the event_loop (select) by closing down the HTTP listener sock */ + if (listener_socket) + { +#ifdef WIN32 + closesocket(listener_socket); +#else + close(listener_socket); +#endif + } } void http_set_proxyaddr(char *host, char *base_url) diff --git a/src/http.h b/src/http.h index a2ec757..d221c43 100644 --- a/src/http.h +++ b/src/http.h @@ -100,7 +100,8 @@ struct http_response }; void http_set_proxyaddr(char *url, char *baseurl); -void http_init(const char *addr); +int http_init(const char *addr); +void http_close_server(void); void http_addheader(struct http_response *r, const char *name, const char *value); struct http_header * http_header_append(struct http_channel *ch, diff --git a/src/http_command.c b/src/http_command.c index bb69bee..7eab95f 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -238,7 +238,7 @@ static int process_settings(struct session *se, struct http_request *rq, static void cmd_exit(struct http_channel *c) { yaz_log(YLOG_WARN, "exit"); - exit(0); + http_close_server(); } static void cmd_init(struct http_channel *c) diff --git a/src/logic.c b/src/logic.c index 3d4de11..afc84a9 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1016,7 +1016,7 @@ void statistics(struct session *se, struct statistics *stat) stat->num_clients = count; } -void start_http_listener(void) +int start_http_listener(void) { char hp[128] = ""; struct conf_server *ser = global_parameters.server; @@ -1033,7 +1033,7 @@ void start_http_listener(void) sprintf(hp + strlen(hp), "%d", ser->port); } } - http_init(hp); + return http_init(hp); } void start_proxy(void) diff --git a/src/pazpar2.c b/src/pazpar2.c index 7eecacb..371d6f5 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "database.h" #include "settings.h" #include +#include void child_handler(void *data) { @@ -81,7 +82,7 @@ static int tcpip_init (void) #endif -int main(int argc, char **argv) +static int sc_main(yaz_sc_t s, int argc, char **argv) { int daemon = 0; int ret; @@ -169,7 +170,12 @@ int main(int argc, char **argv) } global_parameters.server = config->servers; - start_http_listener(); + ret = start_http_listener(); + if (ret) + return ret; /* error starting http listener */ + + yaz_sc_running(s); + yaz_daemon("pazpar2", (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) + (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE, @@ -179,6 +185,22 @@ int main(int argc, char **argv) } +static void sc_stop(yaz_sc_t s) +{ + +} + +int main(int argc, char **argv) +{ + int ret; + yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar Metasearcher"); + + ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop); + + yaz_sc_destroy(&s); + exit(ret); +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/pazpar2.h b/src/pazpar2.h index 1ce73ca..72310aa 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -182,7 +182,7 @@ int session_active_clients(struct session *s); void session_apply_setting(struct session *se, char *dbname, char *setting, char *value); const char *session_setting_oneval(struct session_database *db, int offset); -void start_http_listener(void); +int start_http_listener(void); void start_proxy(void); void pazpar2_add_channel(IOCHAN c);