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");
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");
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)
569
int64_t physmem, freeram;
570
int totalswap = 0, freeswap = 0, nprocs = 0;
571
uint64_t physmem, freeram;
572
uint64_t freeswap = 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__)
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);
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);
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);
656
662
ast_cli(a->fd, " Number of Processes: %d \n\n", nprocs);
657
663
return CLI_SUCCESS;
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)
980
static struct sigaction null_sig_handler = {
981
.sa_handler = _null_sig_handler,
982
.sa_flags = SA_RESTART,
985
static struct sigaction ignore_sig_handler = {
986
.sa_handler = SIG_IGN,
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;
980
995
void ast_replace_sigchld(void)
985
1000
level = safe_system_level++;
987
1002
/* only replace the handler if it has not already been done */
989
safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
1004
sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
991
1007
ast_mutex_unlock(&safe_system_lock);
999
1015
level = --safe_system_level;
1001
1017
/* only restore the handler if we are the last one */
1003
signal(SIGCHLD, safe_system_prev_handler);
1019
sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
1005
1022
ast_mutex_unlock(&safe_system_lock);
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
1436
static void urg_handler(int num)
1453
static void _urg_handler(int num)
1438
signal(num, urg_handler);
1442
static void hup_handler(int num)
1458
static struct sigaction urg_handler = {
1459
.sa_handler = _urg_handler,
1460
.sa_flags = SA_RESTART,
1463
static void _hup_handler(int num)
1445
1466
if (option_verbose > 1)
1452
1473
fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
1455
signal(num, hup_handler);
1458
static void child_handler(int sig)
1478
static struct sigaction hup_handler = {
1479
.sa_handler = _hup_handler,
1480
.sa_flags = SA_RESTART,
1483
static void _child_handler(int sig)
1460
1485
/* Must not ever ast_log or ast_verbose within signal handler */
1468
1493
if (n == 0 && option_debug)
1469
1494
printf("Huh? Child handler, but nobody there?\n");
1470
signal(sig, child_handler);
1497
static struct sigaction child_handler = {
1498
.sa_handler = _child_handler,
1499
.sa_flags = SA_RESTART,
1473
1502
/*! \brief Set maximum open files */
1474
1503
static void set_ulimit(int value)
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));
1674
1703
/* There is no need to restore the signal handler here, since the app
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[0K", 5) < 0) {
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);
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.
3309
signal(SIGCHLD, child_handler);
3340
sigaction(SIGCHLD, &child_handler, NULL);
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);
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);
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);
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;
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");
3687
3721
ast_process_pending_reloads();