/[svn]/qsampler/trunk/src/main.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2064 by capela, Wed Jan 6 09:52:32 2010 UTC revision 2065 by capela, Sat Mar 13 12:44:15 2010 UTC
# Line 235  private: Line 235  private:
235    
236    
237  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
238    // stacktrace - Signal crash handler.
239    //
240    
241    #ifdef CONFIG_STACKTRACE
242    #if defined(__GNUC__) && defined(Q_OS_LINUX)
243    
244    #include <stdio.h>
245    #include <errno.h>
246    #include <signal.h>
247    #include <sys/wait.h>
248    
249    void stacktrace ( int signo )
250    {
251            pid_t pid;
252            int rc;
253            int status = 0;
254            char cmd[80];
255    
256            // Reinstall default handler; prevent race conditions...
257            signal(signo, SIG_DFL);
258    
259            static const char *shell  = "/bin/sh";
260            static const char *format = "gdb -q --batch --pid=%d --eval-command=bt";
261    
262            snprintf(cmd, sizeof(cmd), format, (int) getpid());
263    
264            pid = fork();
265    
266            // Fork failure!
267            if (pid < 0)
268                    return;
269    
270            // Fork child...
271            if (pid == 0) {
272                    execl(shell, shell, "-c", cmd, NULL);
273                    _exit(1);
274                    return;
275            }
276    
277            // Parent here: wait for child to terminate...
278            do { rc = waitpid(pid, &status, 0); }
279            while ((rc < 0) && (errno == EINTR));
280    
281            // Dispatch any logging, if any...
282            QApplication::processEvents(QEventLoop::AllEvents, 3000);
283    
284            // Make sure everyone terminates...
285            kill(pid, SIGTERM);
286            _exit(1);
287    }
288    
289    #endif
290    #endif
291    
292    
293    //-------------------------------------------------------------------------
294  // main - The main program trunk.  // main - The main program trunk.
295  //  //
296    
297  int main ( int argc, char **argv )  int main ( int argc, char **argv )
298  {  {
299          Q_INIT_RESOURCE(qsampler);          Q_INIT_RESOURCE(qsampler);
300    #ifdef CONFIG_STACKTRACE
301    #if defined(__GNUC__) && defined(Q_OS_LINUX)
302            signal(SIGILL,  stacktrace);
303            signal(SIGFPE,  stacktrace);
304            signal(SIGSEGV, stacktrace);
305            signal(SIGABRT, stacktrace);
306            signal(SIGBUS,  stacktrace);
307    #endif
308    #endif
309          qsamplerApplication app(argc, argv);          qsamplerApplication app(argc, argv);
310    
311          #if defined(__APPLE__)  //  Toshi Nagata 20080105          #if defined(__APPLE__)  //  Toshi Nagata 20080105

Legend:
Removed from v.2064  
changed lines
  Added in v.2065

  ViewVC Help
Powered by ViewVC