/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/linuxsampler.cpp

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

revision 214 by schoenebeck, Sat Aug 14 23:00:44 2004 UTC revision 271 by schoenebeck, Fri Oct 8 20:51:39 2004 UTC
# Line 27  Line 27 
27  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
28  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
29  #include "network/lscpserver.h"  #include "network/lscpserver.h"
30    #include "common/stacktrace.h"
31    
32  using namespace LinuxSampler;  using namespace LinuxSampler;
33    
34  Sampler*    pSampler    = NULL;  Sampler*    pSampler    = NULL;
35  LSCPServer* pLSCPServer = NULL;  LSCPServer* pLSCPServer = NULL;
36  pthread_t   signalhandlerthread;  pthread_t   main_thread;
37    
38  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
39  void signal_handler(int signal);  void signal_handler(int signal);
40    void kill_app();
41    
42  int main(int argc, char **argv) {  int main(int argc, char **argv) {
43    
44        // initialize the stack trace mechanism with our binary file
45        StackTraceInit(argv[0], -1);
46    
47        main_thread = pthread_self();
48    
49      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
     signalhandlerthread = pthread_self();  
50      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
51    
52        // register signal handler for all unusual signals
53        // (we will print the stack trace and exit)
54        struct sigaction sact;
55        sigemptyset(&sact.sa_mask);
56        sact.sa_flags   = 0;
57        sact.sa_handler = signal_handler;
58        sigaction(SIGSEGV, &sact, NULL);
59        sigaction(SIGBUS,  &sact, NULL);
60        sigaction(SIGILL,  &sact, NULL);
61        sigaction(SIGFPE,  &sact, NULL);
62        sigaction(SIGUSR1, &sact, NULL);
63        sigaction(SIGUSR2, &sact, NULL);
64    
65      // parse and assign command line options      // parse and assign command line options
66      //parse_options(argc, argv);      //parse_options(argc, argv);
67    
# Line 77  int main(int argc, char **argv) { Line 96  int main(int argc, char **argv) {
96      return EXIT_SUCCESS;      return EXIT_SUCCESS;
97  }  }
98    
99  void signal_handler(int signal) {  void signal_handler(int iSignal) {
100      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      switch (iSignal) {
101          if (pLSCPServer) {          case SIGINT: {
102              pLSCPServer->StopThread();              if (pthread_equal(pthread_self(), main_thread)) {
103              delete pLSCPServer;                  if (pLSCPServer) {
104                        pLSCPServer->StopThread();
105                        delete pLSCPServer;
106                    }
107                    if (pSampler) delete pSampler;
108                    printf("LinuxSampler stopped due to SIGINT.\n");
109                    exit(EXIT_SUCCESS);
110                }
111                return;
112            }
113            case SIGSEGV:
114                std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush;
115                break;
116            case SIGBUS:
117                std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush;
118                break;
119            case SIGILL:
120                std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush;
121                break;
122            case SIGFPE:
123                std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush;
124                break;
125            case SIGUSR1:
126                std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush;
127                break;
128            case SIGUSR2:
129                std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush;
130                break;
131            default: { // this should never happen, as we register for the signals we want
132                std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush;
133                break;
134          }          }
         if (pSampler) delete pSampler;  
         printf("LinuxSampler stopped due to SIGINT\n");  
         exit(EXIT_SUCCESS);  
135      }      }
136        signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
137        std::cerr << "Showing stack trace...\n" << std::flush;
138        StackTrace();
139        sleep(2);
140        std::cerr << "Killing LinuxSampler...\n" << std::flush;
141        kill_app(); // Use abort() if we want to generate a core dump.
142    }
143    
144    void kill_app() {
145        kill(main_thread, SIGKILL);
146  }  }
147    
148  /*void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {

Legend:
Removed from v.214  
changed lines
  Added in v.271

  ViewVC Help
Powered by ViewVC