TecsServer no longer restarted by SICS

This commit is contained in:
cvs
2000-06-07 06:37:13 +00:00
parent b7c9700c51
commit f979f410a4
9 changed files with 69 additions and 68 deletions

View File

@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
@@ -8,6 +9,11 @@
#include "coc_client.h"
#include "str_util.h"
/* --- non ANSI signal --- */
#ifndef SIGPIPE
#define SIGPIPE 13
#endif
/*-------------------------------------------------------------------------*/
int CocConnect(CocConn *conn) {
@@ -29,11 +35,14 @@ int CocConnect(CocConn *conn) {
int CocOpen(CocConn *conn)
{
int i, try, tmo;
int i, try, tmo, iret=-1;
ERR_I(i=CocConnect(conn));
if (i==0) return(0);
if (conn->startcmd[0]=='\0') ERR_MSG("TECS is down, can not restart from here");
if (conn->startcmd[0]=='\0') {
CocDelay(500);
ErrTxt("connect",1); return(-2);
}
printf("Starting TecsServer ...\n\n%s\n", conn->startcmd);
ERR_I(system(conn->startcmd));
@@ -50,7 +59,7 @@ int CocOpen(CocConn *conn)
}
}
ERR_MSG("can not start TECS, too many retries");
OnError: return(-1);
OnError: return(iret);
}
/*-------------------------------------------------------------------------*/
@@ -104,15 +113,23 @@ int CocCheck(CocConn *conn) {
/*-------------------------------------------------------------------------*/
int CocTryCmd(CocConn *conn)
{ if (conn->fd<0) {
ERR_I(CocOpen(conn));
int CocTryCmd(CocConn *conn) {
int iret=-1;
signal(SIGPIPE, SIG_IGN);
if (conn->fd<0) {
ERR_I(iret=CocOpen(conn));
iret=-1;
ERR_I(CocSendMagic(conn, conn->magic));
}
ERR_SI(send(conn->fd, conn->cmdbuf->buf, conn->cmdbuf->wrpos, 0));
ERR_I(CocRecv(conn->fd, conn->resbuf));
signal(SIGPIPE, SIG_DFL);
return(0);
OnError: return(-1);
OnError:
signal(SIGPIPE, SIG_DFL);
if (ErrCode==ECONNRESET || ErrCode==EPIPE) return(-2);
return(iret);
}
/*-------------------------------------------------------------------------*/
@@ -133,8 +150,9 @@ int CocCmdWithRetry(CocConn *conn) {
if (iret>=0) break;
close(conn->fd);
conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
ErrShow("try again, error was");
if (iret==-1) goto OnError; /* severe error */
ErrShort(ErrMessage);
ErrShort("try to reconnect");
}
ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); return(-2); }