#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <execinfo.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/syscall.h>
#include "token.h"
#include "SystemManager.h"
#include "Event.h"
#include "../interface/RioError.h"
Go to the source code of this file.
Defines | |
#define | VG_N_THREADS 500 |
Functions | |
void | usage (char *progname) |
void | show_stackframe () |
Handles the SEGFAULT. | |
void | sigPipeHandler (int signum) |
Handles the SIGPIPE(-13). | |
void | segfaultHandler (int sig) |
void | signalHandler (int sig) |
int | main (int argc, char *argv[]) |
Variables | |
CSystemManager * | manager_ptr |
static char | Usage [] |
#define VG_N_THREADS 500 |
Definition at line 47 of file Server.cpp.
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 121 of file Server.cpp.
00122 { 00123 int flag_debug = 0; 00124 int flag_format = 0; 00125 CSystemManager manager; 00126 char optch; 00127 int ind = -1; 00128 // Variavel usada pela nova opcao para permitir arquivos de configuracao 00129 // em um diretorio diferente do que esta o servidor, e salvar os logs em 00130 // um diretorio diferente de onde esta o servidor. 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 // Nova opcao para permitir arquivos de configuracao e os logd em um 00139 // diretorio diferente do que esta o servidor. Os arquivos de 00140 // configuracao estarao em no subdiretorio etc e os arquivos de log 00141 // no subdiretorio var 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 // parse main options 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 // Nova opcao para permitir arquivos de configuracao em um 00163 // diretorio diferente do que esta o servidor 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 // start up SystemManager 00181 // Agora o metodo Run da classe SystemManager possuira um novo parametro, 00182 // do tipo (char *), que contera o prefixo do diretorio em que as 00183 // configuracoes serao lidas e os logs serao salvos. As configuracoes 00184 // (RIOsystem.cfg, RIOdisk.cfg e RIOpasswd) serao lidas do subdiretorio 00185 // etc e os logs serao salvos no subdiretorio var. Por default, esta 00186 // variavel sera NULL e, neste caso, as configuracoes serao lidas do 00187 // do diretorio em que o codigo do servidor esta, e os logs serao salvos 00188 // neste diretorio. 00189 if( manager.Run( flag_debug, flag_format, prefix_directory) ) 00190 { 00191 exit( 0 ); 00192 } 00193 }/* end of main */
void segfaultHandler | ( | int | sig | ) |
Definition at line 98 of file Server.cpp.
00099 { 00100 RioErr << "[Server] SEGMENTATION FAULT!" << endl; 00101 show_stackframe(); 00102 00103 _exit( 1 ); 00104 }
void show_stackframe | ( | ) |
Handles the SEGFAULT.
Definition at line 76 of file Server.cpp.
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 }
void signalHandler | ( | int | sig | ) |
Definition at line 107 of file Server.cpp.
00108 { 00109 // Nova funcao para tratar o sigterm (futuramente podemos finalizar as 00110 // estruturas aqui nesta funcao. 00111 // 00112 // Obs: Nao e necessario dar o exit( 2 ) que existia antes, porque a 00113 // finalizacao do objeto SystemManager faz com que a thread principal 00114 // termine a sua execucao. 00115 RioErr << "[Server] CAUGHT SIGTERM SIGNAL!" << endl; 00116 manager_ptr->Stop(); 00117 }
void sigPipeHandler | ( | int | signum | ) |
Handles the SIGPIPE(-13).
Definition at line 93 of file Server.cpp.
00094 { 00095 RioErr << "WARNING: Broken Pipe" << endl; 00096 }
void usage | ( | char * | progname | ) |
Definition at line 66 of file Server.cpp.
Definition at line 49 of file Server.cpp.
char Usage[] [static] |
" [-d debug] [-f] [-h] [-p prefix directory] [-v]\n\n" " -d|--debuglevel <debug_level>\n" " Set debug level to debug_level\n" " -f|--format\n" " Format disks and destroy all information\n" " -h|--help\n" " Show this message and exit\n" " -p|--prefixdirectory <prefix directory>\n" " Set the prefix directory of config files and logs.\n" " -v|--version\n" " Show version number and exit\n"
Definition at line 52 of file Server.cpp.