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
00026
00027 #include <unistd.h>
00028 #include <execinfo.h>
00029 #include <getopt.h>
00030
00031 #include "PLSessionManager.h"
00032
00033 static char Usage[] =
00034 "[-h] [-p directory] [-v]\n";
00035
00036 static char Usage2[] =
00037 "\t-h|--help\n Show this message and exit\n"
00038 "\t-p|--prefixdirectory<directory>\t prefix directory\n"
00039 "\t-v|--version\tShow version number and exit\n";
00040
00041 void usage(char* progname)
00042 {
00043 cout << "Usage: " << progname << " " << Usage;
00044 cout << Usage2;
00045 }
00046
00047
00048
00049
00050 void show_stackframe()
00051 {
00052 void *trace[16];
00053 char **messages = (char **)NULL;
00054 int i = 0;
00055 int trace_size = 0;
00056
00057 trace_size = backtrace( trace, 16 );
00058 messages = backtrace_symbols( trace, trace_size );
00059 RioErr << "[bt] Execution path:" << endl;
00060 for( i = 0; i < trace_size; ++i )
00061 RioErr << "[bt(" << i << "/" << trace_size << ")] " << messages[i]
00062 << endl;
00063 }
00064
00065 void segfaultHandler( int sig )
00066 {
00067 RioErr << "[PL] SEGMENTATION FAULT(" << sig << ")!" << endl;
00068 show_stackframe();
00069
00070 _exit( 1 );
00071 }
00072
00073
00074
00075 int main( int argc, char *argv[] )
00076 {
00077 #ifdef RIO_DEBUG1
00078 RioErr << "### [PLInit - main] Start" << endl;
00079 #endif
00080
00081 int hResult;
00082 PLSessionManager *m_PLSessionManager;
00083
00084 char optch;
00085 int ind = -1;
00086
00087
00088
00089 char *prefix_directory = NULL;
00090 static char opts_short[] ="hp:v";
00091 static struct option opts_int[] =
00092 {
00093 {"help" , 0, 0, 'h'},
00094
00095
00096
00097
00098 {"prefixdirectory" , 1, 0, 'p'},
00099 {"version" , 0, 0, 'v'},
00100 {0, 0, 0, 0}
00101 };
00102
00103
00104 while( (optch = getopt_long(argc, argv, opts_short, opts_int, &ind)) != -1)
00105 {
00106 switch( optch )
00107 {
00108 case 'h':
00109 usage( argv[ 0 ] );
00110
00111
00112 case 'p':
00113 prefix_directory = optarg;
00114 break;
00115 case 'v':
00116 cout << " RIOPL version: " << VERSION << endl;
00117 exit( 0 );
00118 default:
00119 usage( argv[ 0 ] );
00120 }
00121 }
00122
00123 RioErr << "Criando a classe PLSessionManager na PLInit." << endl;
00124
00125 m_PLSessionManager = new PLSessionManager();
00126
00127 hResult = m_PLSessionManager->Initialize( prefix_directory );
00128
00129 if( FAILED( hResult ) )
00130 {
00131 RioErr << "Start(): Failed to initialize Session Manager"
00132 << ". hresult=" << (int *)hResult << endl;
00133
00134 delete m_PLSessionManager;
00135 m_PLSessionManager = 0;
00136
00137 #ifdef RIO_DEBUG1
00138 RioErr << "### [PLInit - main] Finish" << endl;
00139 #endif
00140
00141 return hResult;
00142 }
00143
00144 signal( SIGSEGV, segfaultHandler );
00145 signal( SIGABRT, segfaultHandler );
00146
00147 while( true )
00148 {
00149 sleep( 10 );
00150 RioErr << "Dormindo 10 segundos na PLInit." << endl;
00151 }
00152 }