mirror of
https://github.com/gigablast/open-source-search-engine.git
synced 2024-10-04 04:07:13 +03:00
prevent double ./gb start calls from messing
things up.
This commit is contained in:
parent
994bdbdd54
commit
efa93aad18
8
Mem.cpp
8
Mem.cpp
@ -644,7 +644,8 @@ void Mem::addMem ( void *mem , int32_t size , const char *note , char isnew ) {
|
||||
}
|
||||
// hey!
|
||||
if ( s_pid == -1 && m_numTotalAllocated >1000 ) {
|
||||
log(LOG_WARN, "pid is %i and numAllocs is %i", s_pid, m_numTotalAllocated);
|
||||
log(LOG_WARN, "pid is %i and numAllocs is %i", (int)s_pid,
|
||||
(int)m_numTotalAllocated);
|
||||
//char *xx=NULL;*xx=0;}
|
||||
// if ( s_pid == -1 && m_numTotalAllocated >1000 ) { char *xx=NULL;*xx=0;}
|
||||
}
|
||||
@ -997,9 +998,10 @@ bool Mem::rmMem ( void *mem , int32_t size , const char *note ) {
|
||||
if ( size == 0 ) return true;
|
||||
// hey!
|
||||
if ( s_pid == -1 && m_numTotalAllocated >1000 ) {
|
||||
log(LOG_WARN, "pid is %i and numAllocs is %i", s_pid, m_numTotalAllocated);
|
||||
log(LOG_WARN, "pid is %i and numAllocs is %i",
|
||||
(int)s_pid, (int)m_numTotalAllocated);
|
||||
//char *xx=NULL;*xx=0;}
|
||||
}
|
||||
}
|
||||
// threads can't be here!
|
||||
if ( s_pid != -1 && getpid() != s_pid ) {
|
||||
log("mem: rmMem: Called from thread.");
|
||||
|
@ -268,7 +268,7 @@ void timePollWrapper ( int fd , void *state ) {
|
||||
THIS->closeLeastUsed( 60 );
|
||||
}
|
||||
|
||||
bool TcpServer::testBind ( uint16_t port ) {
|
||||
bool TcpServer::testBind ( uint16_t port , bool printMsg ) {
|
||||
// assign port for the test
|
||||
m_port = port;
|
||||
// sockaddr_in provides interface to sockaddr
|
||||
@ -321,6 +321,8 @@ retry19:
|
||||
g_errno = errno;
|
||||
//if ( g_errno == EINVAL ) { port++; goto again; }
|
||||
close ( m_sock );
|
||||
if ( ! printMsg )
|
||||
return false;
|
||||
fprintf(stderr,"Failed to bind socket on port %"INT32": %s."
|
||||
"\n"
|
||||
"Are you already running gb?\n"
|
||||
|
@ -65,7 +65,7 @@ class TcpServer {
|
||||
//int32_t maxReadBufSize = 128*1024 ,
|
||||
//int32_t maxSendBufSize = 128*1024 );
|
||||
|
||||
bool testBind ( uint16_t port ) ;
|
||||
bool testBind ( uint16_t port , bool printMsg ) ;
|
||||
|
||||
// . returns false if blocked, true otherwise
|
||||
// . sets errno on error
|
||||
|
39
main.cpp
39
main.cpp
@ -1358,6 +1358,18 @@ int main2 ( int argc , char *argv[] ) {
|
||||
}
|
||||
*/
|
||||
|
||||
if ( strcmp ( cmd ,"isportinuse") == 0 ) {
|
||||
if ( cmdarg+1 >= argc ) goto printHelp;
|
||||
int port = atol ( argv[cmdarg+1] );
|
||||
// make sure port is available. returns false if in use.
|
||||
if ( ! g_httpServer.m_tcp.testBind(port,false) )
|
||||
// and we should return with 1 so the keep alive
|
||||
// script will exit
|
||||
exit (1);
|
||||
// port is not in use, return 0
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// need threads here for tests?
|
||||
|
||||
// gb thrutest <testDir> <fileSize>
|
||||
@ -3048,7 +3060,8 @@ int main2 ( int argc , char *argv[] ) {
|
||||
// make sure port is available, no use loading everything up then
|
||||
// failing because another process is already running using this port
|
||||
//if ( ! g_udpServer.testBind ( g_hostdb.getMyPort() ) )
|
||||
if ( ! g_httpServer.m_tcp.testBind(g_hostdb.getMyHost()->m_httpPort))
|
||||
if ( ! g_httpServer.m_tcp.testBind(g_hostdb.getMyHost()->m_httpPort,
|
||||
true)) // printmsg?
|
||||
return 1;
|
||||
|
||||
int32_t *ips;
|
||||
@ -5202,6 +5215,23 @@ int install ( install_flag_konst_t installFlag , int32_t hostId , char *dir ,
|
||||
"while [ \\$EXITSTATUS != 0 ]; do "
|
||||
"{ "
|
||||
|
||||
// if gb still running, then do not try to
|
||||
// run it again. we
|
||||
// probably double-called './gb start'.
|
||||
// so see if the port is bound to.
|
||||
"./gb isportinuse %i ; "
|
||||
"if [ \\$? -eq 1 ] ; then "
|
||||
"echo \"gb or something else "
|
||||
"is already running on "
|
||||
"port %i. Not starting.\" ; "
|
||||
"exit 0; "
|
||||
"fi ; "
|
||||
|
||||
// ok, the port is available
|
||||
//"echo \"Starting gb\"; "
|
||||
|
||||
//"exit 0; "
|
||||
|
||||
// in case gb was updated...
|
||||
"mv -f gb.installed gb ; "
|
||||
|
||||
@ -5222,11 +5252,16 @@ int install ( install_flag_konst_t installFlag , int32_t hostId , char *dir ,
|
||||
"ADDARGS='-r'\\$INC ; "
|
||||
"INC=\\$((INC+1));"
|
||||
"} "
|
||||
"done >& /dev/null & \" %s",
|
||||
//"done >& /dev/null & \" %s",
|
||||
"done & \" %s",
|
||||
//"\" %s",
|
||||
iptoa(h2->m_ip),
|
||||
h2->m_dir ,
|
||||
|
||||
// for ./gb isportinuse %i
|
||||
h2->m_httpPort ,
|
||||
h2->m_httpPort ,
|
||||
|
||||
// for moving log file
|
||||
h2->m_hostId ,
|
||||
h2->m_hostId ,
|
||||
|
Loading…
Reference in New Issue
Block a user