Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/SignalHandler.cc

    r7457 r7801  
    5151#include <X11/Xutil.h>
    5252#include <X11/keysym.h>
     53#include <sys/prctl.h>
    5354
    5455namespace orxonox
     
    137138      COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
    138139
    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     
    171143      int gdbIn[2];
    172144      int gdbOut[2];
    173145      int gdbErr[2];
    174 
     146     
    175147      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
    176148      {
    177149        perror("pipe failed!\n");
    178         kill( sigPid, SIGTERM );
    179         waitpid( sigPid, NULL, 0 );
    180150        exit(EXIT_FAILURE);
    181151      }
    182 
     152     
    183153      int gdbPid = fork();
    184154      // this process will run gdb
    185 
     155     
    186156      if ( gdbPid == -1 )
    187157      {
    188158        perror("fork failed\n");
    189         kill( sigPid, SIGTERM );
    190         waitpid( sigPid, NULL, 0 );
    191159        exit(EXIT_FAILURE);
    192160      }
    193 
     161     
    194162      if ( gdbPid == 0 )
    195163      {
    196164        // start gdb
    197 
     165       
    198166        close(gdbIn[1]);
    199167        close(gdbOut[0]);
    200168        close(gdbErr[0]);
    201 
     169       
    202170        dup2( gdbIn[0], STDIN_FILENO );
    203171        dup2( gdbOut[1], STDOUT_FILENO );
    204172        dup2( gdbErr[1], STDERR_FILENO );
    205 
     173       
    206174        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;
    207222      }
    208223
Note: See TracChangeset for help on using the changeset viewer.