/*
- * Copyright (c) 1998-2000, Index Data.
+ * Copyright (c) 1998-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: socket-manager.h,v 1.2 2002-10-23 21:23:01 adam Exp $
+ * $Id: socket-manager.h,v 1.3 2004-01-05 11:31:04 adam Exp $
*/
#ifndef YAZ_SOCKET_MANAGER_INCLUDED
IYazSocketObserver *observer;
int fd;
unsigned mask;
- unsigned timeout;
- unsigned timeout_this;
+ int timeout;
+ int timeout_this;
time_t last_activity;
YazSocketEntry *next;
};
virtual void maskObserver(IYazSocketObserver *observer, int mask);
/// Set timeout
virtual void timeoutObserver(IYazSocketObserver *observer,
- unsigned timeout);
+ int timeout);
/// Process one event. return > 0 if event could be processed;
int processEvent();
Yaz_SocketManager();
/*
- * Copyright (c) 1998-2003, Index Data.
+ * Copyright (c) 1998-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-proxy-main.cpp,v 1.26 2003-10-24 12:19:23 adam Exp $
+ * $Id: yaz-proxy-main.cpp,v 1.27 2004-01-05 11:31:04 adam Exp $
*/
#include <signal.h>
static char *pid_fname = 0;
static char *uid = 0;
static char *log_file = 0;
+static int debug = 0;
int args(Yaz_Proxy *proxy, int argc, char **argv)
{
char *prog = argv[0];
int ret;
- while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:U:", argv, argc, &arg)) != -2)
+ while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:U:X",
+ argv, argc, &arg)) != -2)
{
int err;
switch (ret)
case 'T':
proxy->set_target_idletime(atoi(arg));
break;
+ case 'X':
+ debug = 1;
+ break;
case 'p':
if (!pid_fname)
pid_fname = xstrdup(arg);
}
if (addr)
{
- yaz_log(LOG_LOG, "Starting proxy pid=%ld", (long) getpid());
+ yaz_log(LOG_LOG, "0 Starting proxy " VERSION );
if (proxy->server(addr))
{
yaz_log(LOG_FATAL|LOG_ERRNO, "listen %s", addr);
static_yaz_proxy->reconfig();
}
-int main(int argc, char **argv)
-{
- static int mk_pid = 0;
- Yaz_SocketManager mySocketManager;
- Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
-
- static_yaz_proxy = &proxy;
-
- signal(SIGHUP, sighup_handler);
-
- args(&proxy, argc, argv);
+static void child_run(Yaz_SocketManager *m)
+{
+ yaz_log(LOG_LOG, "0 proxy pid=%ld", (long) getpid());
if (pid_fname)
{
FILE *f = fopen(pid_fname, "w");
xfree(uid);
}
- while (mySocketManager.processEvent() > 0)
+ while (m->processEvent() > 0)
;
exit (0);
+}
+
+int main(int argc, char **argv)
+{
+ int cont = 1;
+ static int mk_pid = 0;
+ Yaz_SocketManager mySocketManager;
+ Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
+
+ static_yaz_proxy = &proxy;
+
+ signal(SIGHUP, sighup_handler);
+
+ args(&proxy, argc, argv);
+
+ if (debug)
+ {
+ child_run(&mySocketManager);
+ exit(0);
+ }
+ while (cont)
+ {
+ pid_t p = fork();
+ if (p == (pid_t) -1)
+ {
+ yaz_log(LOG_FATAL|LOG_ERRNO, "fork");
+ exit(1);
+ }
+ else if (p == 0)
+ {
+ child_run(&mySocketManager);
+ }
+ pid_t p1;
+ int status;
+ p1 = wait(&status);
+ if (p1 != p)
+ {
+ yaz_log(LOG_FATAL, "p1=%d != p=%d", p1, p);
+ exit(1);
+ }
+ if (WIFSIGNALED(status))
+ {
+ switch(WTERMSIG(status)) {
+ case SIGILL:
+ yaz_log(LOG_WARN, "Received SIGILL from child %ld", (long) p);
+ cont = 1;
+ break;
+ case SIGABRT:
+ yaz_log(LOG_WARN, "Received SIGABRT from child %ld", (long) p);
+ cont = 1;
+ break ;
+ case SIGSEGV:
+ yaz_log(LOG_WARN, "Received SIGSEGV from child %ld", (long) p);
+ cont = 1;
+ break;
+ case SIGTERM:
+ yaz_log(LOG_LOG, "Received SIGTERM from child %ld",
+ WTERMSIG(status), (long) p);
+ cont = 0;
+ break;
+ default:
+ yaz_log(LOG_WARN, "Received SIG %d from child %ld",
+ WTERMSIG(status), (long) p);
+ cont = 0;
+ }
+ }
+ else if (status == 0)
+ cont = 0;
+ else
+ {
+ yaz_log(LOG_LOG, "Exit %d from child %ld", status, (long) p);
+ cont = 1;
+ }
+ if (cont)
+ sleep(1);
+ }
+ exit (0);
return 0;
}
/*
- * Copyright (c) 1998-2003, Index Data.
+ * Copyright (c) 1998-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-socket-manager.cpp,v 1.22 2003-12-16 11:26:42 adam Exp $
+ * $Id: yaz-socket-manager.cpp,v 1.23 2004-01-05 11:31:04 adam Exp $
*/
#include <assert.h>
#ifdef WIN32
se->fd = fd;
se->mask = 0;
se->last_activity = 0;
- se->timeout = 0;
+ se->timeout = -1;
}
void Yaz_SocketManager::deleteObserver(IYazSocketObserver *observer)
}
void Yaz_SocketManager::timeoutObserver(IYazSocketObserver *observer,
- unsigned timeout)
+ int timeout)
{
YazSocketEntry *se;
{
YazSocketEntry *p;
YazSocketEvent *event = getEvent();
- unsigned timeout = 0;
+ int timeout = -1;
yaz_log (m_log, "Yaz_SocketManager::processEvent manager=%p", this);
if (event)
{
}
if (fd > max)
max = fd;
- if (p->timeout)
+ if (p->timeout >= 0)
{
unsigned timeout_this;
timeout_this = p->timeout;
timeout_this -= now - p->last_activity;
else
p->last_activity = now;
- if (timeout_this < 1 || timeout_this > 2147483646)
- timeout_this = 1;
- if (!timeout || timeout_this < timeout)
+ if (timeout_this < 0 || timeout_this > 2147483646)
+ timeout_this = 0;
+ if (timeout == -1 || timeout_this < timeout)
timeout = timeout_this;
p->timeout_this = timeout_this;
yaz_log (m_log, "Yaz_SocketManager::select timeout_this=%d",
yaz_log (m_log, "Yaz_SocketManager::select begin no=%d timeout=%d",
no, timeout);
- while ((res = select(max + 1, &in, &out, &except, timeout ? &to : 0)) < 0)
+ while ((res = select(max + 1, &in, &out, &except,
+ timeout== -1 ? 0 : &to)) < 0)
if (errno != EINTR)
{
yaz_log (LOG_LOG|LOG_WARN, "select");