From 50db7bd888de53a53335f62812245c2803bcc96e Mon Sep 17 00:00:00 2001 From: Peter Baumann Date: Sun, 26 Jul 2009 12:28:13 +0200 Subject: PB: introduced some symbolic constants (start for cleanup); VLOG -> TALK; sprintf: %d -> %ld --- rasmgr/rasmgr_host.cc | 2 +- rasmgr/rasmgr_srv.cc | 76 ++++++++++++++++++++++++++++++--------------------- rasmgr/rasmgr_srv.hh | 19 +++++++++++-- 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/rasmgr/rasmgr_host.cc b/rasmgr/rasmgr_host.cc index 0da6a43..ece6fa4 100644 --- a/rasmgr/rasmgr_host.cc +++ b/rasmgr/rasmgr_host.cc @@ -136,7 +136,7 @@ char* ServerHost::getDescription(char *destBuffer) lPort = config.getListenPort(); } - sprintf(destBuffer,"%-10s %-32s %4d %-4s %2d %s",hostName,netwName,lPort,sUp,startedServers,uLh); + sprintf(destBuffer,"%-10s %-32s %4ld %-4s %2d %s",hostName,netwName,lPort,sUp,startedServers,uLh); return destBuffer; } diff --git a/rasmgr/rasmgr_srv.cc b/rasmgr/rasmgr_srv.cc index 542f6dc..91c593c 100644 --- a/rasmgr/rasmgr_srv.cc +++ b/rasmgr/rasmgr_srv.cc @@ -244,6 +244,7 @@ char* RasServer::getDescription(char *destBuffer) const char* host= ptrServerHost->getName();//"(internal)"; const char* dbHost = getDBHostName(); + //if(isinternal==false) // { host=ptrServerHost->getName(); // } @@ -275,9 +276,9 @@ char* RasServer::getDescriptionPort(char *destBuffer) const char *ars = autorestart ? "on":"off"; if(serverType==SERVERTYPE_FLAG_RPC) - sprintf(destBuffer,"%-20s %s %-20s %#10x %-3s %3d/%-3d",serverName,sType,host,listenPort,ars,currentCountDown,initialCountDown); + sprintf(destBuffer,"%-20s %s %-20s %#10lx %-3s %3d/%-3d",serverName,sType,host,listenPort,ars,currentCountDown,initialCountDown); else - sprintf(destBuffer,"%-20s %s %-20s %10d %-3s %3d/%-3d",serverName,sType,host,listenPort,ars,currentCountDown,initialCountDown); + sprintf(destBuffer,"%-20s %s %-20s %10ld %-3s %3d/%-3d",serverName,sType,host,listenPort,ars,currentCountDown,initialCountDown); //countdown=%d InitialCountDown, return destBuffer; } @@ -371,19 +372,18 @@ const char* RasServer::getExecutableName() int RasServer::startServerInDebugger(char *command) { - // sorry for literals, I will change this soon if(ptrDatabaseHost==NULL) - return -1; + return RASSERVER_NODATABASEHOST; if(ptrServerHost->isUp()==false) - return -5; + return RASSERVER_SRVNOTUP; downReq=false; const char *sTypeString= serverType==SERVERTYPE_FLAG_HTTP ? "--http":""; const char *rasmgrHost = ptrServerHost->useLocalHost() ? "localhost" : config.getHostName(); sprintf(command, "%s --rsn %s %s --lport %ld ",executableName,serverName,sTypeString,listenPort); - sprintf(command+strlen(command),"--mgr %s --mgrport %ld --connect %s ",rasmgrHost,config.getListenPort(),ptrDatabaseHost->getConnectionString()); + sprintf(command+strlen(command),"--mgr %s --mgrport %d --connect %s ",rasmgrHost,config.getListenPort(),ptrDatabaseHost->getConnectionString()); sprintf(command+strlen(command),"--sync %s %s",authorization.getSyncroString(),extraParam); currentCountDown=initialCountDown; @@ -391,26 +391,40 @@ int RasServer::startServerInDebugger(char *command) activityCounter = 0; TALK( "RasServer::startServerInDebugger() -> " << command ); - return 0; + return RASSERVER_OK; } int RasServer::startServer() -{ // sorry for literals, I will change this soon +{ if(ptrDatabaseHost==NULL) - return -1; + return RASSERVER_NODATABASEHOST; if(ptrServerHost->isUp()==false) - return -5; + return RASSERVER_SRVNOTUP; downReq=false; const char *sTypeString= serverType==SERVERTYPE_FLAG_HTTP ? "--http" : ""; sTypeString= serverType==SERVERTYPE_FLAG_RNP ? "--rnp" : sTypeString; const char *rasmgrHost = ptrServerHost->useLocalHost() ? "localhost" : config.getHostName(); - char command[400]; - sprintf(command, "%s %s %s --rsn %s %s --lport %ld ",serverName,executableName,executableName,serverName,sTypeString,listenPort); - sprintf(command+strlen(command),"--mgr %s --mgrport %ld --connect %s ",rasmgrHost,config.getListenPort(),ptrDatabaseHost->getConnectionString()); - sprintf(command+strlen(command)," %s",extraParam); + char command[MAX_CMD_LEN+1]; + const char *SPRINTF_FORMAT = "%s %s %s --rsn %s %s --lport %ld --mgr %s --mgrport %ld --connect %s %s"; + // check for buffer oflo + unsigned int commandLen = + strlen(SPRINTF_FORMAT) + + strlen(serverName) + strlen(executableName) + strlen(executableName) + strlen(serverName) + strlen(sTypeString) + + 4 // aka strlen(listenPort) + + strlen(rasmgrHost) + + 4 // aka strlen(config.getListenPort()) + + strlen(ptrDatabaseHost->getConnectionString()) + + strlen(extraParam); + if (commandLen > MAX_CMD_LEN) + { + TALK( "RasServer::startServer(): fatal error: command line can host " << MAX_CMD_LEN << " bytes, but needs " << commandLen << "." ); + std::cout<<"Error: rasserver command line too long, cannot launch. Disappointedly aborting server start." <getConnectionString(), extraParam); if(isinternal) { @@ -422,7 +436,7 @@ int RasServer::startServer() TALK( "connecting to remote rasmgr" ); int socket=ptrServerHost->getConnectionSocket(); if(socket<0) - return -3; + return RASSERVER_NOREMOTERASMGR; char message[MAXMSG]="POST exec HTTP/1.1\r\nAccept: text/plain\r\nUserAgent: RasMGR/1.0\r\nContent-length: "; @@ -432,14 +446,14 @@ int RasServer::startServer() close(socket); if(nbytes<0) - return -4; + return RASSERVER_INCOMPLETESEND; } currentCountDown=initialCountDown; activityExpected=true; isstarting=true; activityCounter = 0; - return 0; + return RASSERVER_OK; } int RasServer::downServer(bool forced) { @@ -447,7 +461,7 @@ int RasServer::downServer(bool forced) { downReq=true; //std::cout<<"Down request, but working"<getConnectionSocket(); if(socket<0) - return -2; + return RASSERVER_CANNOTSTARTSRV; char message[MAXMSG]="POST downserver HTTP/1.1\r\nAccept: text/plain\r\nUserAgent: RasMGR/1.0\r\nContent-length: "; @@ -472,12 +486,12 @@ int RasServer::downNow() close(socket); if(nbytes<0) - return -3; + return RASSERVER_NOREMOTERASMGR; // FIXME: should be RASSERVER_INCOMPLETESEND? } //ptrServerHost->regDownServer(); - return 0; + return RASSERVER_OK; } int RasServer::killServer() { @@ -497,7 +511,7 @@ int RasServer::killServer() { int socket=ptrServerHost->getConnectionSocket(); if(socket<0) - return -2; + return RASSERVER_CANNOTSTARTSRV; char message[MAXMSG]="POST killserver HTTP/1.1\r\nAccept: text/plain\r\nUserAgent: RasMGR/1.0\r\nContent-length: "; @@ -507,10 +521,10 @@ int RasServer::killServer() close(socket); if(nbytes<0) - return -3; + return RASSERVER_NOREMOTERASMGR; // FIXME: should be RASSERVER_INCOMPLETESEND? } - return 0; + return RASSERVER_OK; } void RasServer::changeStatus(int newStatus,long infCount) @@ -537,7 +551,7 @@ void RasServer::changeStatus(int newStatus,long infCount) return; } newStatus = SERVER_AVAILABLE; - VLOG <<"rasmgr: Dead client detected, server "<1 && autorestart) - { // a crashed server doesn't autorestart if he crashes before starting work. + { // a crashed server doesn't autorestart if it crashes before starting work. TALK( "auto restart activated, restarting." ); startServer(); } @@ -601,22 +615,22 @@ void RasServer::changeStatus(int newStatus,long infCount) // commented out due to some error if(initialCountDown) { - VLOG <<"rasmgr: initialCountDown==" << initialCountDown << std::endl; + TALK( "rasmgr: initialCountDown is " << initialCountDown ); if(available) { - VLOG <<"rasmgr: available" << std::endl; + TALK( "rasmgr: " << serverName << " is available." ); currentCountDown--; if(currentCountDown==0) { available=false; - VLOG <<"rasmgr: Countdown reached for "<rpc prognum; 'h' ->TCP/IP port - char extraParam[100]; + char extraParam[MAX_CMD_LEN]; - char executableName[100]; + char executableName[MAX_CMD_LEN]; DatabaseHost *ptrDatabaseHost; //char connStr[100]; -- cgit