~damg/ubuntu/quantal/asterisk/LP1097687

« back to all changes in this revision

Viewing changes to main/asterisk.c

  • Committer: Bazaar Package Importer
  • Author(s): Lorenzo De Liso
  • Date: 2010-10-15 22:24:34 UTC
  • mfrom: (1.2.8 upstream) (8.3.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101015222434-iy328q8in3lajzlv
Tags: 1:1.6.2.9-2ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control:
    + Build-depend on hardening-wrapper
    + Change Maintainer
    + Removed Uploaders field.
    + Removed Debian Vcs-Svn entry and replaced with ubuntu-voip Vcs-Bzr,
      to reflect divergence in packages.
  - debian/rules: Make use of hardening-wrapper
  - debian/asterisk.init: chown /dev/dahdi
  - debian/backports/hardy: add file
  - debian/backports/asterisk.init.hardy: add file
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
#include "asterisk.h"
61
61
 
62
 
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 255955 $")
 
62
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 269747 $")
63
63
 
64
64
#include "asterisk/_private.h"
65
65
 
464
464
        ast_cli(a->fd, "  Transcode via SLIN:          %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled");
465
465
        ast_cli(a->fd, "  Internal timing:             %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING) ? "Enabled" : "Disabled");
466
466
        ast_cli(a->fd, "  Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled");
 
467
        ast_cli(a->fd, "  Generic PLC:                 %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled");
467
468
 
468
469
        ast_cli(a->fd, "\n* Subsystems\n");
469
470
        ast_cli(a->fd, "  -------------\n");
470
471
        ast_cli(a->fd, "  Manager (AMI):               %s\n", check_manager_enabled() ? "Enabled" : "Disabled");
471
472
        ast_cli(a->fd, "  Web Manager (AMI/HTTP):      %s\n", check_webmanager_enabled() ? "Enabled" : "Disabled");
 
473
        ast_cli(a->fd, "  Send Manager FullyBooted:    %s\n", ast_opt_send_fullybooted ? "Enabled" : "Disabled");
472
474
        ast_cli(a->fd, "  Call data records:           %s\n", check_cdr_enabled() ? "Enabled" : "Disabled");
473
475
        ast_cli(a->fd, "  Realtime Architecture (ARA): %s\n", ast_realtime_enabled() ? "Enabled" : "Disabled");
474
476
 
566
568
/*! \brief Give an overview of system statistics */
567
569
static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
568
570
{
569
 
        int64_t physmem, freeram;
570
 
        int totalswap = 0, freeswap = 0, nprocs = 0;
 
571
        uint64_t physmem, freeram;
 
572
        uint64_t freeswap = 0;
 
573
        int totalswap = 0;
 
574
        int nprocs = 0;
571
575
        long uptime = 0;
572
576
#if defined(HAVE_SYSINFO)
573
577
        struct sysinfo sys_info;
574
578
        sysinfo(&sys_info);
575
 
        uptime = sys_info.uptime/3600;
 
579
        uptime = sys_info.uptime / 3600;
576
580
        physmem = sys_info.totalram * sys_info.mem_unit;
577
581
        freeram = (sys_info.freeram * sys_info.mem_unit) / 1024;
578
582
        totalswap = (sys_info.totalswap * sys_info.mem_unit) / 1024;
621
625
        sysctl(mib, 2, &vmtotal, &len, NULL, 0);
622
626
        freeram = (vmtotal.t_free << pageshift);
623
627
        /* generate swap usage and totals */
624
 
        swapmode(&usedswap, &totalswap); 
 
628
        swapmode(&usedswap, &totalswap);
625
629
        freeswap = (totalswap - usedswap);
626
630
        /* grab number of processes */
627
631
#if defined(__OpenBSD__)
645
649
 
646
650
        ast_cli(a->fd, "\nSystem Statistics\n");
647
651
        ast_cli(a->fd, "-----------------\n");
648
 
        ast_cli(a->fd, "  System Uptime:             %ld hours\n", uptime);
649
 
        ast_cli(a->fd, "  Total RAM:                 %ld KiB\n", (long)physmem/1024);
650
 
        ast_cli(a->fd, "  Free RAM:                  %ld KiB\n", (long)freeram);
 
652
        ast_cli(a->fd, "  System Uptime:             %lu hours\n", uptime);
 
653
        ast_cli(a->fd, "  Total RAM:                 %" PRIu64 " KiB\n", physmem / 1024);
 
654
        ast_cli(a->fd, "  Free RAM:                  %" PRIu64 " KiB\n", freeram);
651
655
#if defined(HAVE_SYSINFO)
652
 
        ast_cli(a->fd, "  Buffer RAM:                %ld KiB\n", (sys_info.bufferram * sys_info.mem_unit)/1024);
653
 
#endif
654
 
        ast_cli(a->fd, "  Total Swap Space:          %ld KiB\n", (long)totalswap);
655
 
        ast_cli(a->fd, "  Free Swap Space:           %ld KiB\n\n", (long)freeswap);
 
656
        ast_cli(a->fd, "  Buffer RAM:                %" PRIu64 " KiB\n", ((uint64_t) sys_info.bufferram * sys_info.mem_unit) / 1024);
 
657
#endif
 
658
#if defined (HAVE_SYSCTL) && defined(HAVE_SWAPCTL)
 
659
        ast_cli(a->fd, "  Total Swap Space:          %u KiB\n", totalswap);
 
660
        ast_cli(a->fd, "  Free Swap Space:           %" PRIu64 " KiB\n\n", freeswap);
 
661
#endif
656
662
        ast_cli(a->fd, "  Number of Processes:       %d \n\n", nprocs);
657
663
        return CLI_SUCCESS;
658
664
}
966
972
}
967
973
 
968
974
/*! \brief NULL handler so we can collect the child exit status */
969
 
static void null_sig_handler(int sig)
 
975
static void _null_sig_handler(int sig)
970
976
{
971
977
 
972
978
}
973
979
 
 
980
static struct sigaction null_sig_handler = {
 
981
        .sa_handler = _null_sig_handler,
 
982
        .sa_flags = SA_RESTART,
 
983
};
 
984
 
 
985
static struct sigaction ignore_sig_handler = {
 
986
        .sa_handler = SIG_IGN,
 
987
};
 
988
 
974
989
AST_MUTEX_DEFINE_STATIC(safe_system_lock);
975
990
/*! \brief Keep track of how many threads are currently trying to wait*() on
976
991
 *  a child process */
977
992
static unsigned int safe_system_level = 0;
978
 
static void *safe_system_prev_handler;
 
993
static struct sigaction safe_system_prev_handler;
979
994
 
980
995
void ast_replace_sigchld(void)
981
996
{
985
1000
        level = safe_system_level++;
986
1001
 
987
1002
        /* only replace the handler if it has not already been done */
988
 
        if (level == 0)
989
 
                safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
 
1003
        if (level == 0) {
 
1004
                sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
 
1005
        }
990
1006
 
991
1007
        ast_mutex_unlock(&safe_system_lock);
992
1008
}
999
1015
        level = --safe_system_level;
1000
1016
 
1001
1017
        /* only restore the handler if we are the last one */
1002
 
        if (level == 0)
1003
 
                signal(SIGCHLD, safe_system_prev_handler);
 
1018
        if (level == 0) {
 
1019
                sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
 
1020
        }
1004
1021
 
1005
1022
        ast_mutex_unlock(&safe_system_lock);
1006
1023
}
1433
1450
 system call.  We don't actually need to do anything though.  
1434
1451
 Remember: Cannot EVER ast_log from within a signal handler 
1435
1452
 */
1436
 
static void urg_handler(int num)
 
1453
static void _urg_handler(int num)
1437
1454
{
1438
 
        signal(num, urg_handler);
1439
1455
        return;
1440
1456
}
1441
1457
 
1442
 
static void hup_handler(int num)
 
1458
static struct sigaction urg_handler = {
 
1459
        .sa_handler = _urg_handler,
 
1460
        .sa_flags = SA_RESTART,
 
1461
};
 
1462
 
 
1463
static void _hup_handler(int num)
1443
1464
{
1444
1465
        int a = 0;
1445
1466
        if (option_verbose > 1) 
1452
1473
                        fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
1453
1474
                }
1454
1475
        }
1455
 
        signal(num, hup_handler);
1456
1476
}
1457
1477
 
1458
 
static void child_handler(int sig)
 
1478
static struct sigaction hup_handler = {
 
1479
        .sa_handler = _hup_handler,
 
1480
        .sa_flags = SA_RESTART,
 
1481
};
 
1482
 
 
1483
static void _child_handler(int sig)
1459
1484
{
1460
1485
        /* Must not ever ast_log or ast_verbose within signal handler */
1461
1486
        int n, status;
1467
1492
                ;
1468
1493
        if (n == 0 && option_debug)     
1469
1494
                printf("Huh?  Child handler, but nobody there?\n");
1470
 
        signal(sig, child_handler);
1471
1495
}
1472
1496
 
 
1497
static struct sigaction child_handler = {
 
1498
        .sa_handler = _child_handler,
 
1499
        .sa_flags = SA_RESTART,
 
1500
};
 
1501
 
1473
1502
/*! \brief Set maximum open files */
1474
1503
static void set_ulimit(int value)
1475
1504
{
1668
1697
        sig_flags.need_quit = 1;
1669
1698
        if (sig_alert_pipe[1] != -1) {
1670
1699
                if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) {
1671
 
                        fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
 
1700
                        fprintf(stderr, "quit_handler: write() failed: %s\n", strerror(errno));
1672
1701
                }
1673
1702
        }
1674
1703
        /* There is no need to restore the signal handler here, since the app
2149
2178
 
2150
2179
                        /* Write over the CLI prompt */
2151
2180
                        if (!ast_opt_exec && !lastpos) {
2152
 
                                if (write(STDOUT_FILENO, "\r", 1) < 0) {
 
2181
                                if (write(STDOUT_FILENO, "\r", 5) < 0) {
2153
2182
                                }
2154
2183
                        }
2155
2184
                        if (write(STDOUT_FILENO, buf, res) < 0) {
3002
3031
                        ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
3003
3032
                } else if (!strcasecmp(v->name, "hideconnect")) {
3004
3033
                        ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIDE_CONSOLE_CONNECT);
 
3034
                } else if (!strcasecmp(v->name, "sendfullybooted")) {
 
3035
                        ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_SEND_FULLYBOOTED);
3005
3036
                }
3006
3037
        }
3007
3038
        for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) {
3306
3337
        /* Must install this signal handler up here to ensure that if the canary
3307
3338
         * fails to execute that it doesn't kill the Asterisk process.
3308
3339
         */
3309
 
        signal(SIGCHLD, child_handler);
 
3340
        sigaction(SIGCHLD, &child_handler, NULL);
3310
3341
 
3311
3342
        /* It's common on some platforms to clear /var/run at boot.  Create the
3312
3343
         * socket file directory before we drop privileges. */
3505
3536
                snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
3506
3537
 
3507
3538
                /* Don't let the canary child kill Asterisk, if it dies immediately */
3508
 
                signal(SIGPIPE, SIG_IGN);
 
3539
                sigaction(SIGPIPE, &ignore_sig_handler, NULL);
3509
3540
 
3510
3541
                canary_pid = fork();
3511
3542
                if (canary_pid == 0) {
3552
3583
        sigaddset(&sigs, SIGPIPE);
3553
3584
        sigaddset(&sigs, SIGWINCH);
3554
3585
        pthread_sigmask(SIG_BLOCK, &sigs, NULL);
3555
 
        signal(SIGURG, urg_handler);
 
3586
        sigaction(SIGURG, &urg_handler, NULL);
3556
3587
        signal(SIGINT, __quit_handler);
3557
3588
        signal(SIGTERM, __quit_handler);
3558
 
        signal(SIGHUP, hup_handler);
3559
 
        signal(SIGPIPE, SIG_IGN);
 
3589
        sigaction(SIGHUP, &hup_handler, NULL);
 
3590
        sigaction(SIGPIPE, &ignore_sig_handler, NULL);
3560
3591
 
3561
3592
        /* ensure that the random number generators are seeded with a different value every time
3562
3593
           Asterisk is started
3683
3714
                sig_alert_pipe[0] = sig_alert_pipe[1] = -1;
3684
3715
 
3685
3716
        ast_set_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED);
 
3717
        if (ast_opt_send_fullybooted) {
 
3718
                manager_event(EVENT_FLAG_SYSTEM, "FullyBooted", "Status: Fully Booted\r\n");
 
3719
        }
3686
3720
 
3687
3721
        ast_process_pending_reloads();
3688
3722