Browse code

b/f: core: init monitoring interface used by core after loading modules

Stefan Sayer authored on 21/12/2013 15:15:10
Showing 1 changed files
... ...
@@ -594,6 +594,8 @@ int main(int argc, char* argv[])
594 594
 
595 595
   AmPlugIn::instance()->registerLoggingPlugins();
596 596
 
597
+  AmSessionContainer::instance()->initMonitoring();
598
+
597 599
   #ifndef DISABLE_DAEMON_MODE
598 600
   if(fd[1]) {
599 601
     DBG("hi world! I'm main child [%d]\n", main_pid);
Browse code

core: draft support for TCP transport (WIP)

Raphael Coeffic authored on 22/08/2013 07:16:33
Showing 1 changed files
... ...
@@ -583,7 +583,9 @@ int main(int argc, char* argv[])
583 583
   AmRtpReceiver::instance()->start();
584 584
 
585 585
   INFO("Starting SIP stack (control interface)\n");
586
-  sip_ctrl.load();
586
+  if(sip_ctrl.load()) {
587
+    goto error;
588
+  }
587 589
   
588 590
   INFO("Loading plug-ins\n");
589 591
   AmPlugIn::instance()->init();
Browse code

core: use libevent2 in RTP-receiver instead of poll()

Raphael Coeffic authored on 06/11/2013 15:44:29
Showing 1 changed files
... ...
@@ -53,12 +53,12 @@
53 53
 #include <grp.h>
54 54
 #include <pwd.h>
55 55
 
56
-//#include <sys/wait.h>
57
-//#include <sys/socket.h>
58 56
 #include <sys/types.h>
59 57
 #include <sys/stat.h>
60 58
 #include <fcntl.h>
61 59
 
60
+#include <event2/thread.h>
61
+
62 62
 #ifdef PROPAGATE_COREDUMP_SETTINGS
63 63
 #include <sys/resource.h>
64 64
 #include <sys/prctl.h>
... ...
@@ -572,6 +572,13 @@ int main(int argc, char* argv[])
572 572
   INFO("Starting media processor\n");
573 573
   AmMediaProcessor::instance()->init();
574 574
 
575
+  // init thread usage with libevent
576
+  // before it's too late
577
+  if(evthread_use_pthreads() != 0) {
578
+    ERROR("cannot init thread usage with libevent");
579
+    goto error;
580
+  }
581
+
575 582
   INFO("Starting RTP receiver\n");
576 583
   AmRtpReceiver::instance()->start();
577 584
 
Browse code

core: avoid compiler warnings with void cast on unused function results

Juha Heinanen authored on 11/06/2013 15:01:24
Showing 1 changed files
... ...
@@ -478,7 +478,7 @@ int main(int argc, char* argv[])
478 478
       /* parent process => wait for result from child*/
479 479
       for(int i=0;i<2;i++){
480 480
         DBG("waiting for child[%d] response\n", i);
481
-        read(fd[0], &pid, sizeof(int));
481
+        (void)read(fd[0], &pid, sizeof(int));
482 482
         if(pid<0){
483 483
           ERROR("Child [%d] return an error: %d\n", i, pid);
484 484
           close(fd[0]);
... ...
@@ -494,7 +494,7 @@ int main(int argc, char* argv[])
494 494
       close(fd[0]);
495 495
       main_pid = getpid();
496 496
       DBG("hi world! I'm child [%d]\n", main_pid);
497
-      write(fd[1], &main_pid, sizeof(int));
497
+      (void)write(fd[1], &main_pid, sizeof(int));
498 498
     }
499 499
     /* become session leader to drop the ctrl. terminal */
500 500
     if (setsid()<0){
... ...
@@ -588,7 +588,7 @@ int main(int argc, char* argv[])
588 588
   #ifndef DISABLE_DAEMON_MODE
589 589
   if(fd[1]) {
590 590
     DBG("hi world! I'm main child [%d]\n", main_pid);
591
-    write(fd[1], &main_pid, sizeof(int));
591
+    (void)write(fd[1], &main_pid, sizeof(int));
592 592
     close(fd[1]); fd[1] = 0;
593 593
   }
594 594
   #endif
... ...
@@ -625,7 +625,7 @@ int main(int argc, char* argv[])
625 625
   if(fd[1]){
626 626
      main_pid = -1;
627 627
      DBG("send -1 to parent\n");
628
-     write(fd[1], &main_pid, sizeof(int));
628
+     (void)write(fd[1], &main_pid, sizeof(int));
629 629
      close(fd[1]);
630 630
   }
631 631
 #endif
Browse code

apps, core: fixed spelling errors found by lintian

Juha Heinanen authored on 10/06/2013 11:48:22
Showing 1 changed files
... ...
@@ -486,7 +486,7 @@ int main(int argc, char* argv[])
486 486
         }
487 487
         DBG("child [%d] pid:%d\n", i, pid);
488 488
       }
489
-      DBG("all childs return OK. bye world!\n");
489
+      DBG("all children return OK. bye world!\n");
490 490
       close(fd[0]);
491 491
       return 0;
492 492
     }else {
Browse code

load the sip stack before plug-ins

Raphael Coeffic authored on 28/04/2013 12:24:19
Showing 1 changed files
... ...
@@ -575,6 +575,9 @@ int main(int argc, char* argv[])
575 575
   INFO("Starting RTP receiver\n");
576 576
   AmRtpReceiver::instance()->start();
577 577
 
578
+  INFO("Starting SIP stack (control interface)\n");
579
+  sip_ctrl.load();
580
+  
578 581
   INFO("Loading plug-ins\n");
579 582
   AmPlugIn::instance()->init();
580 583
   if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins))
... ...
@@ -582,9 +585,6 @@ int main(int argc, char* argv[])
582 585
 
583 586
   AmPlugIn::instance()->registerLoggingPlugins();
584 587
 
585
-  INFO("Starting SIP stack (control interface)\n");
586
-  sip_ctrl.load();
587
-
588 588
   #ifndef DISABLE_DAEMON_MODE
589 589
   if(fd[1]) {
590 590
     DBG("hi world! I'm main child [%d]\n", main_pid);
... ...
@@ -593,6 +593,7 @@ int main(int argc, char* argv[])
593 593
   }
594 594
   #endif
595 595
 
596
+  // running the server
596 597
   if(sip_ctrl.run() != -1)
597 598
     success = true;
598 599
 
Browse code

make SipCtrlInterface a singleton.

Raphael Coeffic authored on 28/04/2013 12:23:46
Showing 1 changed files
... ...
@@ -75,7 +75,7 @@ const char* progname = NULL;    /**< Program name (actually argv[0])*/
75 75
 int main_pid = 0;               /**< Main process PID */
76 76
 
77 77
 /** SIP stack (controller interface) */
78
-static SipCtrlInterface sip_ctrl;
78
+#define sip_ctrl (*SipCtrlInterface::instance())
79 79
 
80 80
 
81 81
 static void print_usage(bool short_=false)
Browse code

core: fix return status pipe machinery in non-daemon mode

Raphael Coeffic authored on 24/05/2013 10:35:16
Showing 1 changed files
... ...
@@ -477,23 +477,23 @@ int main(int argc, char* argv[])
477 477
       close(fd[1]);
478 478
       /* parent process => wait for result from child*/
479 479
       for(int i=0;i<2;i++){
480
-        INFO("waiting for child[%d] response\n", i);
480
+        DBG("waiting for child[%d] response\n", i);
481 481
         read(fd[0], &pid, sizeof(int));
482 482
         if(pid<0){
483 483
           ERROR("Child [%d] return an error: %d\n", i, pid);
484 484
           close(fd[0]);
485 485
           goto error;
486 486
         }
487
-        INFO("child [%d] pid:%d\n", i, pid);
487
+        DBG("child [%d] pid:%d\n", i, pid);
488 488
       }
489
-      INFO("all childs return OK. bye world!\n");
489
+      DBG("all childs return OK. bye world!\n");
490 490
       close(fd[0]);
491 491
       return 0;
492 492
     }else {
493 493
       /* child */
494 494
       close(fd[0]);
495 495
       main_pid = getpid();
496
-      INFO("hi world! I'm child [%d]\n", main_pid);
496
+      DBG("hi world! I'm child [%d]\n", main_pid);
497 497
       write(fd[1], &main_pid, sizeof(int));
498 498
     }
499 499
     /* become session leader to drop the ctrl. terminal */
... ...
@@ -508,7 +508,7 @@ int main(int argc, char* argv[])
508 508
       /*parent process => exit */
509 509
       close(fd[1]);
510 510
       main_pid = getpid();
511
-      INFO("I'm out. pid: %d", main_pid);
511
+      DBG("I'm out. pid: %d", main_pid);
512 512
       return 0;
513 513
     }
514 514
 	
... ...
@@ -586,9 +586,11 @@ int main(int argc, char* argv[])
586 586
   sip_ctrl.load();
587 587
 
588 588
   #ifndef DISABLE_DAEMON_MODE
589
-  INFO("hi world! I'm main child [%d]\n", main_pid);
590
-  write(fd[1], &main_pid, sizeof(int));
591
-  close(fd[1]);
589
+  if(fd[1]) {
590
+    DBG("hi world! I'm main child [%d]\n", main_pid);
591
+    write(fd[1], &main_pid, sizeof(int));
592
+    close(fd[1]); fd[1] = 0;
593
+  }
592 594
   #endif
593 595
 
594 596
   if(sip_ctrl.run() != -1)
... ...
@@ -619,11 +621,11 @@ int main(int argc, char* argv[])
619 621
   if (AmConfig::DaemonMode) {
620 622
     unlink(AmConfig::DaemonPidFile.c_str());
621 623
   }
622
-  if (!(fcntl(fd[1], F_GETFL) == -1 && errno == EBADF)){
623
-    main_pid = -1;
624
-    ERROR("send -1 to parent\n");
625
-    write(fd[1], &main_pid, sizeof(int));
626
-    close(fd[1]);
624
+  if(fd[1]){
625
+     main_pid = -1;
626
+     DBG("send -1 to parent\n");
627
+     write(fd[1], &main_pid, sizeof(int));
628
+     close(fd[1]);
627 629
   }
628 630
 #endif
629 631
 
Browse code

pass return code from main() correctly in daemon mode

Raphael Coeffic authored on 23/05/2013 13:46:23
Showing 1 changed files
... ...
@@ -325,6 +325,9 @@ int main(int argc, char* argv[])
325 325
 {
326 326
   int success = false;
327 327
   std::map<char,string> args;
328
+  #ifndef DISABLE_DAEMON_MODE
329
+  int fd[2] = {0,0};
330
+  #endif
328 331
 
329 332
   progname = strrchr(argv[0], '/');
330 333
   progname = (progname == NULL ? argv[0] : progname + 1);
... ...
@@ -462,13 +465,36 @@ int main(int argc, char* argv[])
462 465
 #endif
463 466
 
464 467
     /* fork to become!= group leader*/
468
+    if (pipe(fd) == -1) { /* Create a pipe */
469
+        ERROR("Cannot create pipe.\n");
470
+        goto error;
471
+    }
465 472
     int pid;
466 473
     if ((pid=fork())<0){
467 474
       ERROR("Cannot fork: %s.\n", strerror(errno));
468 475
       goto error;
469 476
     }else if (pid!=0){
470
-      /* parent process => exit*/
477
+      close(fd[1]);
478
+      /* parent process => wait for result from child*/
479
+      for(int i=0;i<2;i++){
480
+        INFO("waiting for child[%d] response\n", i);
481
+        read(fd[0], &pid, sizeof(int));
482
+        if(pid<0){
483
+          ERROR("Child [%d] return an error: %d\n", i, pid);
484
+          close(fd[0]);
485
+          goto error;
486
+        }
487
+        INFO("child [%d] pid:%d\n", i, pid);
488
+      }
489
+      INFO("all childs return OK. bye world!\n");
490
+      close(fd[0]);
471 491
       return 0;
492
+    }else {
493
+      /* child */
494
+      close(fd[0]);
495
+      main_pid = getpid();
496
+      INFO("hi world! I'm child [%d]\n", main_pid);
497
+      write(fd[1], &main_pid, sizeof(int));
472 498
     }
473 499
     /* become session leader to drop the ctrl. terminal */
474 500
     if (setsid()<0){
... ...
@@ -480,6 +506,9 @@ int main(int argc, char* argv[])
480 506
       goto error;
481 507
     }else if (pid!=0){
482 508
       /*parent process => exit */
509
+      close(fd[1]);
510
+      main_pid = getpid();
511
+      INFO("I'm out. pid: %d", main_pid);
483 512
       return 0;
484 513
     }
485 514
 	
... ...
@@ -555,7 +584,13 @@ int main(int argc, char* argv[])
555 584
 
556 585
   INFO("Starting SIP stack (control interface)\n");
557 586
   sip_ctrl.load();
558
-  
587
+
588
+  #ifndef DISABLE_DAEMON_MODE
589
+  INFO("hi world! I'm main child [%d]\n", main_pid);
590
+  write(fd[1], &main_pid, sizeof(int));
591
+  close(fd[1]);
592
+  #endif
593
+
559 594
   if(sip_ctrl.run() != -1)
560 595
     success = true;
561 596
 
... ...
@@ -584,6 +619,12 @@ int main(int argc, char* argv[])
584 619
   if (AmConfig::DaemonMode) {
585 620
     unlink(AmConfig::DaemonPidFile.c_str());
586 621
   }
622
+  if (!(fcntl(fd[1], F_GETFL) == -1 && errno == EBADF)){
623
+    main_pid = -1;
624
+    ERROR("send -1 to parent\n");
625
+    write(fd[1], &main_pid, sizeof(int));
626
+    close(fd[1]);
627
+  }
587 628
 #endif
588 629
 
589 630
   sip_ctrl.cleanup();
Browse code

init the plug-ins after most of the initialization has been done.

Raphael Coeffic authored on 12/04/2013 12:46:18
Showing 1 changed files
... ...
@@ -522,13 +522,6 @@ int main(int argc, char* argv[])
522 522
   if(set_sighandler(signal_handler))
523 523
     goto error;
524 524
     
525
-  INFO("Loading plug-ins\n");
526
-  AmPlugIn::instance()->init();
527
-  if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins))
528
-    goto error;
529
-
530
-  AmPlugIn::instance()->registerLoggingPlugins();
531
-
532 525
 #ifdef WITH_ZRTP
533 526
   if (AmZRTP::init()) {
534 527
     ERROR("Cannot initialize ZRTP\n");
... ...
@@ -553,6 +546,13 @@ int main(int argc, char* argv[])
553 546
   INFO("Starting RTP receiver\n");
554 547
   AmRtpReceiver::instance()->start();
555 548
 
549
+  INFO("Loading plug-ins\n");
550
+  AmPlugIn::instance()->init();
551
+  if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins))
552
+    goto error;
553
+
554
+  AmPlugIn::instance()->registerLoggingPlugins();
555
+
556 556
   INFO("Starting SIP stack (control interface)\n");
557 557
   sip_ctrl.load();
558 558
   
Browse code

core: propagate coredump settings in daemon mode

it seems that coredump settings needs to be propagated explicitly in daemon mode (see man prctl, linux only)

Václav Kubart authored on 23/01/2013 14:19:24 • Raphael Coeffic committed on 30/01/2013 13:58:18
Showing 1 changed files
... ...
@@ -59,6 +59,11 @@
59 59
 #include <sys/stat.h>
60 60
 #include <fcntl.h>
61 61
 
62
+#ifdef PROPAGATE_COREDUMP_SETTINGS
63
+#include <sys/resource.h>
64
+#include <sys/prctl.h>
65
+#endif
66
+
62 67
 #include <string>
63 68
 using std::string;
64 69
 
... ...
@@ -399,6 +404,13 @@ int main(int argc, char* argv[])
399 404
 #ifndef DISABLE_DAEMON_MODE
400 405
 
401 406
   if(AmConfig::DaemonMode){
407
+#ifdef PROPAGATE_COREDUMP_SETTINGS
408
+    struct rlimit lim;
409
+    bool have_limit = false;
410
+    if (getrlimit(RLIMIT_CORE, &lim) == 0) have_limit = true;
411
+    int dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
412
+#endif
413
+
402 414
     if(!AmConfig::DaemonGid.empty()){
403 415
       unsigned int gid;
404 416
       if(str2i(AmConfig::DaemonGid, gid)){
... ...
@@ -475,6 +487,13 @@ int main(int argc, char* argv[])
475 487
       goto error;
476 488
     }
477 489
 
490
+#ifdef PROPAGATE_COREDUMP_SETTINGS
491
+    if (have_limit) {
492
+      if (setrlimit(RLIMIT_CORE, &lim) < 0) ERROR("failed to set RLIMIT_CORE\n");
493
+      if (prctl(PR_SET_DUMPABLE, dumpable, 0, 0, 0)<0) ERROR("cannot re-set core dumping to %d!\n", dumpable);
494
+    }
495
+#endif
496
+
478 497
     /* try to replace stdin, stdout & stderr with /dev/null */
479 498
     if (freopen("/dev/null", "r", stdin)==0){
480 499
       ERROR("Cannot replace stdin with /dev/null: %s.\n",
Browse code

new interface config

Allows for signaling-only or media-only interfaces.

The parameter "additional_interfaces" has been renamed to
"interfaces". When not present, SEMS will look for IP config
parameters without any suffixes (sip_ip, media_ip, etc...).

If the "media_ip_[interface name]" is set, the interface is considered
to be a media interface. If the "sip_ip_[interface name]" parameter
is defined, the interface is considered to be a media interface. If
both parameters are defined for the same interface, it is a signaling
and media interface.

Raphael Coeffic authored on 29/10/2012 08:55:54
Showing 1 changed files
... ...
@@ -135,6 +135,36 @@ static bool parse_args(int argc, char* argv[], std::map<char,string>& args)
135 135
     }
136 136
 }
137 137
 
138
+static void set_default_interface(const string& iface_name)
139
+{
140
+  unsigned int idx=0;
141
+  map<string,unsigned short>::iterator if_it = AmConfig::SIP_If_names.find("default");
142
+  if(if_it == AmConfig::SIP_If_names.end()) {
143
+    AmConfig::SIP_interface intf;
144
+    intf.name = "default";
145
+    AmConfig::SIP_Ifs.push_back(intf);
146
+    AmConfig::SIP_If_names["default"] = AmConfig::SIP_Ifs.size()-1;
147
+    idx = AmConfig::SIP_Ifs.size()-1;
148
+  }
149
+  else {
150
+    idx = if_it->second;
151
+  }
152
+  AmConfig::SIP_Ifs[if_it->second].LocalIP = iface_name;
153
+
154
+  if_it = AmConfig::RTP_If_names.find("default");
155
+  if(if_it == AmConfig::RTP_If_names.end()) {
156
+    AmConfig::RTP_interface intf;
157
+    intf.name = "default";
158
+    AmConfig::RTP_Ifs.push_back(intf);
159
+    AmConfig::RTP_If_names["default"] = AmConfig::RTP_Ifs.size()-1;
160
+    idx = AmConfig::RTP_Ifs.size()-1;
161
+  }
162
+  else {
163
+    idx = if_it->second;
164
+  }
165
+  AmConfig::RTP_Ifs[if_it->second].LocalIP = iface_name;
166
+}
167
+
138 168
 /* Note: The function should not use logging because it is called before
139 169
    the logging is initialized. */
140 170
 static bool apply_args(std::map<char,string>& args)
... ...
@@ -144,7 +174,7 @@ static bool apply_args(std::map<char,string>& args)
144 174
 
145 175
     switch( it->first ){
146 176
     case 'd':
147
-      AmConfig::Ifs[0].LocalIP = it->second;
177
+      set_default_interface(it->second);
148 178
       break;
149 179
 
150 180
     case 'D':
... ...
@@ -310,7 +340,7 @@ int main(int argc, char* argv[])
310 340
   }
311 341
 
312 342
   // Init default interface
313
-  AmConfig::Ifs.push_back(AmConfig::IP_interface());
343
+  //AmConfig::Ifs.push_back(AmConfig::IP_interface());
314 344
 
315 345
   /* apply command-line options */
316 346
   if(!apply_args(args)){
Browse code

core: simplified module initialization

Stefan Sayer authored on 02/03/2012 21:12:56
Showing 1 changed files
... ...
@@ -478,6 +478,8 @@ int main(int argc, char* argv[])
478 478
   if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins))
479 479
     goto error;
480 480
 
481
+  AmPlugIn::instance()->registerLoggingPlugins();
482
+
481 483
 #ifdef WITH_ZRTP
482 484
   if (AmZRTP::init()) {
483 485
     ERROR("Cannot initialize ZRTP\n");
Browse code

b/f: dumping transaction table in proper shutdown sequence

(avoiding crash when logging already gone)

Stefan Sayer authored on 03/02/2012 18:21:26
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #endif
42 42
 
43 43
 #include "SipCtrlInterface.h"
44
+#include "sip/trans_table.h"
44 45
 
45 46
 #include "log.h"
46 47
 
... ...
@@ -511,6 +512,10 @@ int main(int argc, char* argv[])
511 512
   INFO("Disposing session container\n");
512 513
   AmSessionContainer::dispose();
513 514
 
515
+  DBG("** Transaction table dump: **\n");
516
+  dumps_transactions();
517
+  DBG("*****************************\n");
518
+
514 519
   INFO("Disposing RTP receiver\n");
515 520
   AmRtpReceiver::dispose();
516 521
 
Browse code

moved app timers into core, using wheeltimer for that purpose

Stefan Sayer authored on 23/11/2011 16:03:08
Showing 1 changed files
... ...
@@ -34,6 +34,7 @@
34 34
 #include "AmRtpReceiver.h"
35 35
 #include "AmEventDispatcher.h"
36 36
 #include "AmSessionProcessor.h"
37
+#include "AmAppTimer.h"
37 38
 
38 39
 #ifdef WITH_ZRTP
39 40
 # include "AmZRTP.h"
... ...
@@ -483,6 +484,9 @@ int main(int argc, char* argv[])
483 484
   }
484 485
 #endif
485 486
 
487
+  INFO("Starting application timer scheduler\n");
488
+  AmAppTimer::instance()->start();
489
+
486 490
   INFO("Starting session container\n");
487 491
   AmSessionContainer::instance()->start();
488 492
   
Browse code

on linux, set PR_SET_DUMPABLE=1 to dump core after setuid

Stefan Sayer authored on 16/11/2011 16:42:20
Showing 1 changed files
... ...
@@ -60,6 +60,9 @@
60 60
 #include <string>
61 61
 using std::string;
62 62
 
63
+#if defined(__linux__)
64
+#include <sys/prctl.h>
65
+#endif
63 66
 
64 67
 const char* progname = NULL;    /**< Program name (actually argv[0])*/
65 68
 int main_pid = 0;               /**< Main process PID */
... ...
@@ -406,6 +409,14 @@ int main(int argc, char* argv[])
406 409
       }
407 410
     }
408 411
 
412
+#if defined(__linux__)
413
+    if(!AmConfig::DaemonUid.empty() || !AmConfig::DaemonGid.empty()){
414
+      if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0) {
415
+	WARN("unable to set daemon to dump core after setuid/setgid\n");
416
+      }
417
+    }
418
+#endif
419
+
409 420
     /* fork to become!= group leader*/
410 421
     int pid;
411 422
     if ((pid=fork())<0){
Browse code

Merge branch 'master' into offer_answer

Raphael Coeffic authored on 18/02/2011 11:36:25
Showing 1 changed files
... ...
@@ -51,20 +51,14 @@
51 51
 #include <grp.h>
52 52
 #include <pwd.h>
53 53
 
54
-#include <sys/wait.h>
55
-#include <sys/ioctl.h>
56
-#include <sys/socket.h>
54
+//#include <sys/wait.h>
55
+//#include <sys/socket.h>
57 56
 #include <sys/types.h>
58 57
 #include <sys/stat.h>
59 58
 #include <fcntl.h>
60 59
 
61
-#include <net/if.h>
62
-#include <netinet/in.h>
63
-#include <arpa/inet.h>
64
-
65 60
 #include <string>
66 61
 using std::string;
67
-using std::make_pair;
68 62
 
69 63
 
70 64
 const char* progname = NULL;    /**< Program name (actually argv[0])*/
... ...
@@ -145,7 +139,7 @@ static bool apply_args(std::map<char,string>& args)
145 139
 
146 140
     switch( it->first ){
147 141
     case 'd':
148
-      AmConfig::LocalIP = it->second;
142
+      AmConfig::Ifs[0].LocalIP = it->second;
149 143
       break;
150 144
 
151 145
     case 'D':
... ...
@@ -226,6 +220,10 @@ static void signal_handler(int sig)
226 220
     return;
227 221
   }
228 222
 
223
+  if (sig == SIGTERM) {
224
+    AmSessionContainer::instance()->enableUncleanShutdown();
225
+  }
226
+
229 227
   if (main_pid == getpid()) {
230 228
     if(!is_shutting_down.get()) {
231 229
       is_shutting_down.set(true);
... ...
@@ -279,127 +277,6 @@ static int write_pid_file()
279 277
 #endif /* !DISABLE_DAEMON_MODE */
280 278
 
281 279
 
282
-/** Get the list of network interfaces with the associated PF_INET addresses */
283
-static bool getInterfaceList(int sd, std::vector<std::pair<string,string> >& if_list)
284
-{
285
-  struct ifconf ifc;
286
-  struct ifreq ifrs[MAX_NET_DEVICES];
287
-
288
-  ifc.ifc_len = sizeof(struct ifreq) * MAX_NET_DEVICES;
289
-  ifc.ifc_req = ifrs;
290
-  memset(ifrs, 0, ifc.ifc_len);
291
-
292
-  if(ioctl(sd, SIOCGIFCONF, &ifc)!=0){
293
-    ERROR("getInterfaceList: ioctl: %s.\n", strerror(errno));
294
-    return false;
295
-  }
296
-
297
-#if !defined(BSD44SOCKETS)
298
-  int n_dev = ifc.ifc_len / sizeof(struct ifreq);
299
-  for(int i=0; i<n_dev; i++){
300
-    if(ifrs[i].ifr_addr.sa_family==PF_INET){
301
-      struct sockaddr_in* sa = (struct sockaddr_in*)&ifrs[i].ifr_addr;
302
-
303
-      // avoid dereferencing type-punned pointer below
304
-      struct sockaddr_in sa4;
305
-      memcpy(&sa4, sa, sizeof(struct sockaddr_in));
306
-      if_list.push_back(make_pair((char*)ifrs[i].ifr_name,
307
-                                  inet_ntoa(sa4.sin_addr)));
308
-    }
309
-  }
310
-#else // defined(BSD44SOCKETS)
311
-  struct ifreq* p_ifr = ifc.ifc_req;
312
-  while((char*)p_ifr - (char*)ifc.ifc_req < ifc.ifc_len){
313
-
314
-    if(p_ifr->ifr_addr.sa_family == PF_INET){
315
-      struct sockaddr_in* sa = (struct sockaddr_in*)&p_ifr->ifr_addr;
316
-      if_list.push_back(make_pair((const char*)p_ifr->ifr_name,
317
-                                  inet_ntoa(sa->sin_addr)));
318
-    }
319
-
320
-    p_ifr = (struct ifreq*)(((char*)p_ifr) + IFNAMSIZ + p_ifr->ifr_addr.sa_len);
321
-  }
322
-#endif
323
-
324
-  return true;
325
-}
326
-
327
-/** Get the PF_INET address associated with the network interface */
328
-static string getLocalIP(const string& dev_name)
329
-{
330
-  string local_ip;
331
-  struct ifreq ifr;
332
-  std::vector<std::pair<string,string> > if_list;
333
-
334
-#ifdef SUPPORT_IPV6
335
-  struct sockaddr_storage ss;
336
-  if(inet_aton_v6(dev_name.c_str(), &ss))
337
-#else
338
-    struct in_addr inp;
339
-  if(inet_aton(dev_name.c_str(), &inp))
340
-#endif
341
-    {
342
-      return dev_name;
343
-    }
344
-
345
-  int sd = socket(PF_INET, SOCK_DGRAM, 0);
346
-  if(sd == -1){
347
-    ERROR("socket: %s.\n", strerror(errno));
348
-    goto error;
349
-  }
350
-
351
-  if(dev_name.empty()) {
352
-    if (!getInterfaceList(sd, if_list)) {
353
-      goto error;
354
-    }
355
-  }
356
-  else {
357
-    memset(&ifr, 0, sizeof(struct ifreq));
358
-    strncpy(ifr.ifr_name, dev_name.c_str(), IFNAMSIZ-1);
359
-
360
-    if(ioctl(sd, SIOCGIFADDR, &ifr)!=0){
361
-      ERROR("ioctl(SIOCGIFADDR): %s.\n", strerror(errno));
362
-      goto error;
363
-    }
364
-
365
-    if(ifr.ifr_addr.sa_family==PF_INET){
366
-      struct sockaddr_in* sa = (struct sockaddr_in*)&ifr.ifr_addr;
367
-
368
-      // avoid dereferencing type-punned pointer below
369
-      struct sockaddr_in sa4;
370
-      memcpy(&sa4, sa, sizeof(struct sockaddr_in));
371
-      if_list.push_back(make_pair((char*)ifr.ifr_name,
372
-				  inet_ntoa(sa4.sin_addr)));
373
-    }
374
-  }
375
-
376
-  for( std::vector<std::pair<string,string> >::iterator it = if_list.begin();
377
-       it != if_list.end(); ++it) {
378
-    memset(&ifr, 0, sizeof(struct ifreq));
379
-    strncpy(ifr.ifr_name, it->first.c_str(), IFNAMSIZ-1);
380
-
381
-    if(ioctl(sd, SIOCGIFFLAGS, &ifr)!=0){
382
-      ERROR("ioctl(SIOCGIFFLAGS): %s.\n", strerror(errno));
383
-      goto error;
384
-    }
385
-
386
-    if( (ifr.ifr_flags & IFF_UP) &&
387
-        (!dev_name.empty() || !(ifr.ifr_flags & IFF_LOOPBACK)) ) {
388
-      local_ip = it->second;
389
-      break;
390
-    }
391
-  }
392
-
393
-  if(ifr.ifr_flags & IFF_LOOPBACK){
394
-    WARN("Media advertising using loopback address!\n"
395
-         "Try to use another network interface if your SEMS "
396
-         "should be accessible from the rest of the world.\n");
397
-  }
398
-
399
- error:
400
-  close(sd);
401
-  return local_ip;
402
-}
403 280
 
404 281
 /*
405 282
  * Main
... ...
@@ -427,6 +304,9 @@ int main(int argc, char* argv[])
427 304
     return 0;
428 305
   }
429 306
 
307
+  // Init default interface
308
+  AmConfig::Ifs.push_back(AmConfig::IP_interface());
309
+
430 310
   /* apply command-line options */
431 311
   if(!apply_args(args)){
432 312
     print_usage(true);
... ...
@@ -449,16 +329,8 @@ int main(int argc, char* argv[])
449 329
     goto error;
450 330
   }
451 331
 
452
-  AmConfig::LocalIP = getLocalIP(AmConfig::LocalIP);
453
-  if (AmConfig::LocalIP.empty()) {
454
-    ERROR("Cannot determine proper local address for media advertising!\n"
455
-          "Try using 'ifconfig -a' to find a proper interface and configure SEMS to use it.\n");
332
+  if(AmConfig::finalizeIPConfig() < 0)
456 333
     goto error;
457
-  }
458
-
459
-  if (AmConfig::LocalSIPIP.empty()) {
460
-    AmConfig::LocalSIPIP = AmConfig::LocalIP;
461
-  }
462 334
 
463 335
   printf("Configuration:\n"
464 336
 #ifdef _DEBUG
... ...
@@ -472,11 +344,6 @@ int main(int argc, char* argv[])
472 344
          "       daemon UID:          %s\n"
473 345
          "       daemon GID:          %s\n"
474 346
 #endif
475
-	 "       local SIP IP:        %s\n"
476
-         "       public media IP:     %s\n"
477
-	 "       local SIP port:      %i\n"
478
-	 "       local media IP:      %s\n"
479
-	 "       out-bound proxy:     %s\n"
480 347
 	 "       application:         %s\n"
481 348
 	 "\n",
482 349
 #ifdef _DEBUG
... ...
@@ -490,13 +357,10 @@ int main(int argc, char* argv[])
490 357
 	 AmConfig::DaemonUid.empty() ? "<not set>" : AmConfig::DaemonUid.c_str(),
491 358
 	 AmConfig::DaemonGid.empty() ? "<not set>" : AmConfig::DaemonGid.c_str(),
492 359
 #endif
493
-	 AmConfig::LocalSIPIP.c_str(),
494
-	 AmConfig::PublicIP.c_str(),
495
-	 AmConfig::LocalSIPPort,
496
-	 AmConfig::LocalIP.c_str(),
497
-	 AmConfig::OutboundProxy.c_str(),
498 360
 	 AmConfig::Application.empty() ? "<not set>" : AmConfig::Application.c_str());
499 361
 
362
+  AmConfig::dump_Ifs();
363
+
500 364
 #ifndef DISABLE_DAEMON_MODE
501 365
 
502 366
   if(AmConfig::DaemonMode){
... ...
@@ -624,9 +488,9 @@ int main(int argc, char* argv[])
624 488
 
625 489
   INFO("Starting SIP stack (control interface)\n");
626 490
   sip_ctrl.load();
627
-  sip_ctrl.run(AmConfig::LocalSIPIP, AmConfig::LocalSIPPort);
628 491
   
629
-  success = true;
492
+  if(sip_ctrl.run() != -1)
493
+    success = true;
630 494
 
631 495
   // session container stops active sessions
632 496
   INFO("Disposing session container\n");
Browse code

b/f: compile fix for threadpool

Stefan Sayer authored on 30/11/2010 17:18:11
Showing 1 changed files
... ...
@@ -33,6 +33,7 @@
33 33
 #include "AmMediaProcessor.h"
34 34
 #include "AmRtpReceiver.h"
35 35
 #include "AmEventDispatcher.h"
36
+#include "AmSessionProcessor.h"
36 37
 
37 38
 #ifdef WITH_ZRTP
38 39
 # include "AmZRTP.h"
Browse code

changed: SEMS won't stop anymore on the first error in config file. changed: the stderr option in config file is now read as the first option, to enable better debug/error log while reading the file.

Raphael Coeffic authored on 07/10/2010 09:08:51
Showing 1 changed files
... ...
@@ -435,7 +435,11 @@ int main(int argc, char* argv[])
435 435
   init_logging();
436 436
 
437 437
   /* load and apply configuration file */
438
-  AmConfig::readConfiguration();
438
+  if(AmConfig::readConfiguration()){
439
+    ERROR("Errors occured while reading configuration file: exiting.");
440
+    return -1;
441
+  }
442
+
439 443
   log_level = AmConfig::LogLevel;
440 444
   log_stderr = AmConfig::LogStderr;
441 445
 
Browse code

added OpenSSL linking exception to license

Stefan Sayer authored on 23/09/2010 14:41:49
Showing 1 changed files
... ...
@@ -1,21 +1,21 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2002-2003 Fhg Fokus
5 3
  *
6
- * This file is part of sems, a free SIP media server.
4
+ * This file is part of SEMS, a free SIP media server.
7 5
  *
8
- * sems is free software; you can redistribute it and/or modify
6
+ * SEMS is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
9
+ * (at your option) any later version. This program is released under
10
+ * the GPL with the additional exemption that compiling, linking,
11
+ * and/or using OpenSSL is allowed.
12 12
  *
13
- * For a license to use the ser software under conditions
13
+ * For a license to use the SEMS software under conditions
14 14
  * other than those described here, or to purchase support for this
15 15
  * software, please contact iptel.org by e-mail at the following addresses:
16 16
  *    info@iptel.org
17 17
  *
18
- * sems is distributed in the hope that it will be useful,
18
+ * SEMS is distributed in the hope that it will be useful,
19 19
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 21
  * GNU General Public License for more details.
Browse code

implements SIGUSR1/SIGUSR2 handling, custom use

SIGUSR1/SIGUSR2 can e.g. be used in DSM calls or systemDSMs

Stefan Sayer authored on 22/09/2010 14:25:24
Showing 1 changed files
... ...
@@ -201,10 +201,12 @@ static AmCondition<bool> is_shutting_down(false);
201 201
 
202 202
 static void signal_handler(int sig)
203 203
 {
204
-  WARN("Signal %s (%d) received.\n", strsignal(sig), sig);
205
-
206
-  if ( sig == SIGHUP) {
207
-    AmSessionContainer::instance()->broadcastShutdown();
204
+  if (sig == SIGUSR1 || sig == SIGUSR2) {
205
+    DBG("brodcasting User event to %u sessions...\n",
206
+	AmSession::getSessionNum());
207
+    AmEventDispatcher::instance()->
208
+      broadcast(new AmSystemEvent(sig == SIGUSR1? 
209
+				  AmSystemEvent::User1 : AmSystemEvent::User2));
208 210
     return;
209 211
   }
210 212
 
... ...
@@ -216,6 +218,13 @@ static void signal_handler(int sig)
216 218
     return;
217 219
   }
218 220
 
221
+  WARN("Signal %s (%d) received.\n", strsignal(sig), sig);
222
+
223
+  if (sig == SIGHUP) {
224
+    AmSessionContainer::instance()->broadcastShutdown();
225
+    return;
226
+  }
227
+
219 228
   if (main_pid == getpid()) {
220 229
     if(!is_shutting_down.get()) {
221 230
       is_shutting_down.set(true);
... ...
@@ -233,7 +242,7 @@ static void signal_handler(int sig)
233 242
 int set_sighandler(void (*handler)(int))
234 243
 {
235 244
   static int sigs[] = {
236
-      SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD, 0
245
+    SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD, SIGUSR1, SIGUSR2, 0
237 246
   };
238 247
 
239 248
   for (int* sig = sigs; *sig; sig++) {
Browse code

handle SIGHUP: stop sessions (send BYE), dont quit

Stefan Sayer authored on 22/09/2010 13:49:04
Showing 1 changed files
... ...
@@ -203,6 +203,11 @@ static void signal_handler(int sig)
203 203
 {
204 204
   WARN("Signal %s (%d) received.\n", strsignal(sig), sig);
205 205
 
206
+  if ( sig == SIGHUP) {
207
+    AmSessionContainer::instance()->broadcastShutdown();
208
+    return;
209
+  }
210
+
206 211
   if (sig == SIGCHLD && AmConfig::IgnoreSIGCHLD) {
207 212
     return;
208 213
   }
Browse code

ignore SIGPIPE (like SIGCHLD)

Stefan Sayer authored on 01/07/2010 23:29:58
Showing 1 changed files
... ...
@@ -207,6 +207,10 @@ static void signal_handler(int sig)
207 207
     return;
208 208
   }
209 209
 
210
+  if (sig == SIGPIPE && AmConfig::IgnoreSIGPIPE) {
211
+    return;
212
+  }
213
+
210 214
   if (main_pid == getpid()) {
211 215
     if(!is_shutting_down.get()) {
212 216
       is_shutting_down.set(true);
Browse code

typo fix in error message

Stefan Sayer authored on 19/06/2010 15:30:15
Showing 1 changed files
... ...
@@ -485,7 +485,7 @@ int main(int argc, char* argv[])
485 485
 	  gid = grnam->gr_gid;
486 486
 	}
487 487
 	else{
488
-	  ERROR("Cannot not find group '%s' in the group database.\n",
488
+	  ERROR("Cannot find group '%s' in the group database.\n",
489 489
 		AmConfig::DaemonGid.c_str());
490 490
 	  goto error;
491 491
 	}
... ...
@@ -506,7 +506,7 @@ int main(int argc, char* argv[])
506 506
 	  uid = pwnam->pw_uid;
507 507
 	}
508 508
 	else{
509
-	  ERROR("Cannot not find user '%s' in the user database.\n",
509
+	  ERROR("Cannot find user '%s' in the user database.\n",
510 510
 		AmConfig::DaemonUid.c_str());
511 511
 	  goto error;
512 512
 	}
Browse code

fix UID and GID parameters processing

fixes a segfault when process UID or GID was configured

Stefan Sayer authored on 19/06/2010 15:14:23
Showing 1 changed files
... ...
@@ -389,7 +389,6 @@ int main(int argc, char* argv[])
389 389
 {
390 390
   int success = false;
391 391
   std::map<char,string> args;
392
-  std::map<char,string>::iterator cfg_arg;
393 392
 
394 393
   progname = strrchr(argv[0], '/');
395 394
   progname = (progname == NULL ? argv[0] : progname + 1);
... ...
@@ -480,14 +479,14 @@ int main(int argc, char* argv[])
480 479
   if(AmConfig::DaemonMode){
481 480
     if(!AmConfig::DaemonGid.empty()){
482 481
       unsigned int gid;
483
-      if(str2i(cfg_arg->second, gid)){
484
-	struct group* grnam = getgrnam(cfg_arg->second.c_str());
482
+      if(str2i(AmConfig::DaemonGid, gid)){
483
+	struct group* grnam = getgrnam(AmConfig::DaemonGid.c_str());
485 484
 	if(grnam != NULL){
486 485
 	  gid = grnam->gr_gid;
487 486
 	}
488 487
 	else{
489 488
 	  ERROR("Cannot not find group '%s' in the group database.\n",
490
-		cfg_arg->second.c_str());
489
+		AmConfig::DaemonGid.c_str());
491 490
 	  goto error;
492 491
 	}
493 492
       }
... ...
@@ -501,14 +500,14 @@ int main(int argc, char* argv[])
501 500
 
502 501
     if(!AmConfig::DaemonUid.empty()){
503 502
       unsigned int uid;
504
-      if(str2i(cfg_arg->second, uid)){
505
-	struct passwd* pwnam = getpwnam(cfg_arg->second.c_str());
503
+      if(str2i(AmConfig::DaemonUid, uid)){
504
+	struct passwd* pwnam = getpwnam(AmConfig::DaemonUid.c_str());
506 505
 	if(pwnam != NULL){
507 506
 	  uid = pwnam->pw_uid;
508 507
 	}
509 508
 	else{
510 509
 	  ERROR("Cannot not find user '%s' in the user database.\n",
511
-		cfg_arg->second.c_str());
510
+		AmConfig::DaemonUid.c_str());
512 511
 	  goto error;
513 512
 	}
514 513
       }
Browse code

fixed shutdown procedure: - session container needs to be stopped first, with everything else still in place, so sessions can stop/send BYE - UDP SIP transport is needed in shutdown procedure - event dispatcher is needed until the end (may be needed to post events while destructing things)

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1916 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 18/05/2010 22:05:09
Showing 1 changed files
...