00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <iostream>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <stdio.h>
00029 #include <time.h>
00030 #include <signal.h>
00031 #include <execinfo.h>
00032
00033 #include <sys/stat.h>
00034 #include <sys/types.h>
00035 #include <fcntl.h>
00036 #include <unistd.h>
00037 #include <getopt.h>
00038
00039
00040 #include <sys/syscall.h>
00041
00042 #include "token.h"
00043 #include "SystemManager.h"
00044 #include "Event.h"
00045 #include "../interface/RioError.h"
00046
00047 #define VG_N_THREADS 500
00048
00049 CSystemManager * manager_ptr;
00050
00051
00052 static char Usage[] =
00053 " [-d debug] [-f] [-h] [-p prefix directory] [-v]\n\n"
00054 " -d|--debuglevel <debug_level>\n"
00055 " Set debug level to debug_level\n"
00056 " -f|--format\n"
00057 " Format disks and destroy all information\n"
00058 " -h|--help\n"
00059 " Show this message and exit\n"
00060 " -p|--prefixdirectory <prefix directory>\n"
00061 " Set the prefix directory of config files and logs.\n"
00062 " -v|--version\n"
00063 " Show version number and exit\n";
00064
00065
00066 void usage( char *progname )
00067 {
00068 RioErr << "Usage:" << endl;
00069 RioErr << " " << progname << Usage << endl;
00070 exit( 1 );
00071 }
00072
00073
00074
00075
00076 void show_stackframe()
00077 {
00078 void *trace[16];
00079 char **messages = (char **)NULL;
00080 int i, trace_size = 0;
00081
00082 trace_size = backtrace( trace, 16 );
00083 messages = backtrace_symbols( trace, trace_size );
00084 RioErr << "[bt] Execution path:" << endl;
00085 for( i = 0; i < trace_size; ++i )
00086 RioErr << "[bt(" << i << "/" << trace_size << ")] " << messages[i]
00087 << endl;
00088 }
00089
00090
00091
00092
00093 void sigPipeHandler( int signum )
00094 {
00095 RioErr << "WARNING: Broken Pipe" << endl;
00096 }
00097
00098 void segfaultHandler( int sig )
00099 {
00100 RioErr << "[Server] SEGMENTATION FAULT!" << endl;
00101 show_stackframe();
00102
00103 _exit( 1 );
00104 }
00105
00106
00107 void signalHandler( int sig )
00108 {
00109
00110
00111
00112
00113
00114
00115 RioErr << "[Server] CAUGHT SIGTERM SIGNAL!" << endl;
00116 manager_ptr->Stop();
00117 }
00118
00119
00120
00121 int main( int argc, char *argv[] )
00122 {
00123 int flag_debug = 0;
00124 int flag_format = 0;
00125 CSystemManager manager;
00126 char optch;
00127 int ind = -1;
00128
00129
00130
00131 char *prefix_directory = NULL;
00132 static char opts_short[] ="d:fhp:v";
00133 static struct option opts_int[] =
00134 {
00135 {"debuglevel" , 1, 0, 'd'},
00136 {"format" , 0, 0, 'f'},
00137 {"help" , 0, 0, 'h'},
00138
00139
00140
00141
00142 {"prefixdirectory" , 1, 0, 'p'},
00143 {"version" , 0, 0, 'v'},
00144 {0, 0, 0, 0}
00145 };
00146
00147 RioErr << "MAINTHREADID " << syscall( SYS_gettid ) << endl;
00148
00149
00150 while( (optch = getopt_long(argc, argv, opts_short, opts_int, &ind)) != -1)
00151 {
00152 switch( optch )
00153 {
00154 case 'd':
00155 flag_debug = atoi( optarg );
00156 break;
00157 case 'f':
00158 flag_format = 1;
00159 break;
00160 case 'h':
00161 usage( argv[ 0 ] );
00162
00163
00164 case 'p':
00165 prefix_directory = optarg;
00166 break;
00167 case 'v':
00168 cout << " RIOServer version: " << VERSION << endl;
00169 exit( 0 );
00170 default:
00171 usage( argv[ 0 ] );
00172 }
00173 }
00174
00175 signal( SIGPIPE, sigPipeHandler );
00176 signal( SIGSEGV, segfaultHandler );
00177 signal( SIGTERM, signalHandler );
00178
00179 manager_ptr = &manager;
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 if( manager.Run( flag_debug, flag_format, prefix_directory) )
00190 {
00191 exit( 0 );
00192 }
00193 }