- Timestamp:
- Dec 21, 2010, 6:09:09 PM (14 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2
- Property svn:mergeinfo changed
/code/branches/network3 (added) merged: 7333,7336-7337,7344 /code/branches/network4 (added) merged: 7497,7718,7753-7755 /code/branches/network5 (added) merged: 7757-7759,7772-7778,7780-7781
- Property svn:mergeinfo changed
-
code/branches/presentation2/src/libraries/util/SignalHandler.cc
r7457 r7788 51 51 #include <X11/Xutil.h> 52 52 #include <X11/keysym.h> 53 #include <sys/prctl.h> 53 54 54 55 namespace orxonox … … 137 138 COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl; 138 139 139 int sigPipe[2]; 140 if ( pipe(sigPipe) == -1 ) 141 { 142 perror("pipe failed!\n"); 143 exit(EXIT_FAILURE); 144 } 145 146 int sigPid = fork(); 147 148 if ( sigPid == -1 ) 149 { 150 perror("fork failed!\n"); 151 exit(EXIT_FAILURE); 152 } 153 154 // gdb will be attached to this process 155 if ( sigPid == 0 ) 156 { 157 getInstance().dontCatch(); 158 // wait for message from parent when it has attached gdb 159 int someData; 160 161 read( sigPipe[0], &someData, sizeof(someData) ); 162 163 if ( someData != 0x12345678 ) 164 { 165 COUT(0) << "something went wrong :(" << std::endl; 166 } 167 168 return; 169 } 170 140 141 // First start GDB which will be attached to this process later on 142 171 143 int gdbIn[2]; 172 144 int gdbOut[2]; 173 145 int gdbErr[2]; 174 146 175 147 if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 ) 176 148 { 177 149 perror("pipe failed!\n"); 178 kill( sigPid, SIGTERM );179 waitpid( sigPid, NULL, 0 );180 150 exit(EXIT_FAILURE); 181 151 } 182 152 183 153 int gdbPid = fork(); 184 154 // this process will run gdb 185 155 186 156 if ( gdbPid == -1 ) 187 157 { 188 158 perror("fork failed\n"); 189 kill( sigPid, SIGTERM );190 waitpid( sigPid, NULL, 0 );191 159 exit(EXIT_FAILURE); 192 160 } 193 161 194 162 if ( gdbPid == 0 ) 195 163 { 196 164 // start gdb 197 165 198 166 close(gdbIn[1]); 199 167 close(gdbOut[0]); 200 168 close(gdbErr[0]); 201 169 202 170 dup2( gdbIn[0], STDIN_FILENO ); 203 171 dup2( gdbOut[1], STDOUT_FILENO ); 204 172 dup2( gdbErr[1], STDERR_FILENO ); 205 173 206 174 execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL)); 175 } 176 177 178 // Now start a fork of this process on which GDB will be attached on 179 180 int sigPipe[2]; 181 if ( pipe(sigPipe) == -1 ) 182 { 183 perror("pipe failed!\n"); 184 kill( gdbPid, SIGTERM ); 185 waitpid( gdbPid, NULL, 0 ); 186 exit(EXIT_FAILURE); 187 } 188 189 int sigPid = fork(); 190 191 if ( sigPid == -1 ) 192 { 193 perror("fork failed!\n"); 194 kill( gdbPid, SIGTERM ); 195 waitpid( gdbPid, NULL, 0 ); 196 exit(EXIT_FAILURE); 197 } 198 199 // gdb will be attached to this process 200 if ( sigPid == 0 ) 201 { 202 getInstance().dontCatch(); 203 204 // make sure gdb is allowed to attach to our PID even if there are some system restrictions 205 #ifdef PR_SET_PTRACER 206 if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 ) 207 COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl; 208 #endif 209 210 // wait for message from parent when it has attached gdb 211 int someData; 212 213 if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) ) 214 COUT(0) << "something went wrong :(" << std::endl; 215 216 if ( someData != 0x12345678 ) 217 { 218 COUT(0) << "something went wrong :(" << std::endl; 219 } 220 221 return; 207 222 } 208 223
Note: See TracChangeset
for help on using the changeset viewer.