35 #include <sys/types.h> 59 #define BES_SERVER_ROOT "BES_SERVER_ROOT" 60 #define BES_SERVER "/beslistener" 61 #define BES_SERVER_PID "/bes.pid" 67 bool load_names(
const string &install_dir,
const string &pid_dir ) ;
78 main(
int argc,
char *argv[])
82 uid_t curr_euid = geteuid() ;
85 cerr <<
"FAILED: Must be root to run BES" << endl ;
89 cerr <<
"Developer Mode: not testing if BES is run by root" << endl ;
110 unsigned short num_args = 1 ;
111 while( ( c = getopt( argc, argv,
"hvsd:c:p:u:i:r:" ) ) != EOF )
123 install_dir = optarg ;
126 cout <<
"The specified install directory (-i option) " 127 <<
"is incorrectly formatted. Must be less than " 128 <<
"255 characters and include the characters " 129 <<
"[0-9A-z_./-]" << endl ;
142 cout <<
"The specified state directory (-r option) " 143 <<
"is incorrectly formatted. Must be less than " 144 <<
"255 characters and include the characters " 145 <<
"[0-9A-z_./-]" << endl ;
154 string check_path = optarg ;
157 cout <<
"The specified install directory (-i option) " 158 <<
"is incorrectly formatted. Must be less than " 159 <<
"255 characters and include the characters " 160 <<
"[0-9A-z_./-]" << endl ;
168 string port_num = optarg ;
169 for(
unsigned int i = 0; i < port_num.length(); i++ )
171 if( !isdigit( port_num[i] ) )
173 cout <<
"The specified port contains non-digit " 174 <<
"characters: " << port_num << endl ;
183 string check_arg = optarg ;
186 cout <<
"The specified debug options \"" << check_arg
187 <<
"\" contains invalid characters" << endl ;
201 if( argc > num_args )
204 <<
": too many arguments passed to the BES" ;
208 if( pid_dir.empty() )
210 pid_dir = install_dir ;
221 <<
": too many arguments passed to the BES" ;
228 char temp_name[len + 1] ;
230 temp_name[len] =
'\0' ;
235 for(
int i = 1; i < num_args; i++ )
245 <<
": there seems to be a BES daemon already running at " ;
247 temp.getline( buf, 500 ) ;
248 cout << buf << endl ;
259 <<
": server cannot mount at first try (core dump). " 260 <<
"Please correct problems on the process manager " 283 if( ( pid = fork() ) < 0 )
294 const char *perror_string = 0 ;
297 if( ( pid = fork() ) < 0 )
300 perror_string = strerror( errno ) ;
302 cerr << perror_string ;
308 execvp( arguments[0], arguments ) ;
310 <<
": mounting listener, subprocess failed: " ;
311 perror_string = strerror( errno ) ;
313 cerr << perror_string ;
318 if( ( pid = waitpid( pid, &status, 0 ) ) < 0 )
321 perror_string = strerror( errno ) ;
323 cerr << perror_string ;
327 int child_status =
pr_exit( status ) ;
328 return child_status ;
334 if( WIFEXITED( status ) )
337 switch( WEXITSTATUS( status ) )
340 status_to_be_returned = 0 ;
345 <<
": server cannot start, exited with status " 346 << WEXITSTATUS( status ) << endl ;
347 cerr <<
"Please check all error messages " 348 <<
"and adjust server installation" << endl ;
349 status_to_be_returned = 0 ;
355 <<
": abnormal server termination, exited with status " 356 << WEXITSTATUS( status ) << endl ;
357 status_to_be_returned = 1 ;
363 <<
": server has been requested to re-start." << endl ;
364 status_to_be_returned = 1 ;
368 status_to_be_returned = 1 ;
372 return status_to_be_returned;
374 else if( WIFSIGNALED( status ) )
377 <<
": abnormal server termination, signaled with signal number " 378 << WTERMSIG( status ) << endl ;
380 if( WCOREDUMP( status ) )
382 cerr <<
NameProgram <<
": server dumped core." << endl ;
388 else if( WIFSTOPPED( status ) )
391 <<
": abnormal server termination, stopped with signal number " 392 << WSTOPSIG( status ) << endl ;
401 const char *perror_string = 0 ;
405 cerr <<
NameProgram <<
": unable to create pid file " 407 perror_string = strerror( errno ) ;
409 cerr << perror_string ;
410 cerr <<
" ... Continuing" << endl ;
415 f <<
"PID: " << pid <<
" UID: " << getuid() << endl ;
417 mode_t new_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
423 load_names(
const string &install_dir,
const string &pid_dir )
425 char *xdap_root = 0 ;
426 string bindir =
"/bin";
427 if( !pid_dir.empty() )
432 if( !install_dir.empty() )
444 string::size_type slash = prog.find_last_of(
'/' ) ;
445 if( slash != string::npos )
448 slash = prog.find_last_of(
'/' ) ;
449 if( slash != string::npos )
451 string root = prog.substr( 0, slash ) ;
483 <<
"Please either pass -i <install_dir> on the command line or " 485 <<
"to the installation directory where the BES listener is." static bool pathname_ok(const string &path, bool strict)
Does the string name a potentailly valid pathname? Test the given pathname to verfiy that it is a val...
#define SERVER_EXIT_NORMAL_SHUTDOWN
int main(int argc, char *argv[])
static bool command_line_arg_ok(const string &arg)
sanitize command line arguments
static void show_usage(const string &app_name)
void store_listener_id(int pid)
#define SERVER_EXIT_ABNORMAL_TERMINATION
int mount_server(char **)
#define SERVER_EXIT_FATAL_CAN_NOT_START
static void show_version(const string &app_name)
bool load_names(const string &install_dir, const string &pid_dir)
static bool size_ok(unsigned int sz, unsigned int nelem)
sanitize the size of an array.
#define SERVER_EXIT_RESTART
#define SERVER_EXIT_UNDEFINED_STATE