Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:01 2007

Asterisk developer's documentation :: Codename Pineapple


asterisk.c File Reference


Detailed Description

Top level source file for Asterisk - the Open Source PBX. Implementation of PBX core functions and CLI interface.

Definition in file asterisk.c.

#include "asterisk.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/resource.h>
#include <grp.h>
#include <pwd.h>
#include <sys/stat.h>
#include <regex.h>
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/channel.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/image.h"
#include "asterisk/tdd.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/cdr.h"
#include "asterisk/pbx.h"
#include "asterisk/enum.h"
#include "asterisk/rtp.h"
#include "asterisk/http.h"
#include "asterisk/udptl.h"
#include "asterisk/app.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/io.h"
#include "editline/histedit.h"
#include "asterisk/config.h"
#include "asterisk/version.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/doxyref.h"
#include "../defaults.h"

Include dependency graph for asterisk.c:

Go to the source code of this file.

Data Structures

struct  ast_atexit
struct  console
struct  file_version
struct  profile_data
struct  profile_entry
struct  thread_list_t

Defines

#define AF_LOCAL   AF_UNIX
#define AST_MAX_CONNECTS   128
#define ASTERISK_PROMPT   "*CLI> "
#define ASTERISK_PROMPT2   "%s*CLI> "
#define FORMAT   "%-25.25s %-40.40s\n"
#define NUM_MSGS   64
#define PF_LOCAL   PF_UNIX
#define WELCOME_MESSAGE
 Welcome message when starting a CLI interface.

Functions

static void __quit_handler (int num)
int ast_add_profile (const char *name, uint64_t scale)
 support for event profiling
static int ast_all_zeros (char *s)
static int ast_cli_display_match_list (char **matches, int len, int max)
void ast_console_puts (const char *string)
void ast_console_puts_mutable (const char *string)
 log the string to the console, and all attached console clients
void ast_console_toggle_mute (int fd)
 mute or unmute a console from logging
static int ast_el_add_history (char *)
static int ast_el_initialize (void)
static int ast_el_read_char (EditLine *el, char *cp)
static int ast_el_read_history (char *)
static int ast_el_sort_compare (const void *i1, const void *i2)
static char ** ast_el_strtoarr (char *buf)
static int ast_el_write_history (char *)
static AST_LIST_HEAD_STATIC (thread_list, thread_list_t)
static AST_LIST_HEAD_STATIC (file_versions, file_version)
static AST_LIST_HEAD_STATIC (atexits, ast_atexit)
static int ast_makesocket (void)
int64_t ast_mark (int i, int startstop)
 AST_MUTEX_DEFINE_STATIC (safe_system_lock)
static void ast_network_puts (const char *string)
 write the string to all attached console clients
static void ast_network_puts_mutable (const char *string)
 log the string to all attached console clients
int64_t ast_profile (int i, int64_t delta)
static void ast_readconfig (void)
int ast_register_atexit (void(*func)(void))
 Register a function to be executed before Asterisk exits.
void ast_register_file_version (const char *file, const char *version)
 Register the version of a source code file with the core.
void ast_register_thread (char *name)
static void ast_remotecontrol (char *data)
void ast_replace_sigchld (void)
 Replace the SIGCHLD handler.
static void ast_run_atexits (void)
int ast_safe_system (const char *s)
int ast_set_priority (int pri)
 We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.
static int ast_tryconnect (void)
void ast_unregister_atexit (void(*func)(void))
 Unregister a function registered with ast_register_atexit().
void ast_unregister_file_version (const char *file)
 Unregister a source code file from the core.
void ast_unregister_thread (void *id)
void ast_unreplace_sigchld (void)
 Restore the SIGCHLD handler.
static void child_handler (int sig)
static char * cli_complete (EditLine *el, int ch)
static char * cli_prompt (EditLine *el)
static char * complete_show_version_files (const char *line, const char *word, int pos, int state)
static void console_verboser (const char *s)
static void consolehandler (char *s)
static int fdprint (int fd, const char *s)
static const char * fix_header (char *outbuf, int maxout, const char *s, char *cmp)
static int handle_abort_halt (int fd, int argc, char *argv[])
static int handle_bang (int fd, int argc, char *argv[])
static int handle_restart_gracefully (int fd, int argc, char *argv[])
static int handle_restart_now (int fd, int argc, char *argv[])
static int handle_restart_when_convenient (int fd, int argc, char *argv[])
static int handle_show_profile (int fd, int argc, char *argv[])
static int handle_show_threads (int fd, int argc, char *argv[])
static int handle_show_version_files (int fd, int argc, char *argv[])
 CLI command to list module versions.
static int handle_shutdown_gracefully (int fd, int argc, char *argv[])
static int handle_shutdown_now (int fd, int argc, char *argv[])
static int handle_shutdown_when_convenient (int fd, int argc, char *argv[])
static int handle_version (int fd, int argc, char *argv[])
static void hup_handler (int num)
static void * listener (void *unused)
int main (int argc, char *argv[])
static void * netconsole (void *vconsole)
static void network_verboser (const char *s)
static void null_sig_handler (int signal)
 NULL handler so we can collect the child exit status.
static void quit_handler (int num, int nice, int safeshutdown, int restart)
static __inline uint64_t rdtsc (void)
static int remoteconsolehandler (char *s)
static void set_icon (char *text)
static void set_title (char *text)
 Set an X-term or screen title.
static void set_ulimit (int value)
 Set maximum open files.
static int show_cli_help (void)
static int show_license (int fd, int argc, char *argv[])
static int show_version (void)
static int show_warranty (int fd, int argc, char *argv[])
static void urg_handler (int num)
 Urgent handler.

Variables

static char * _argv [256]
static const char abort_halt_help []
const char * ast_build_date
const char * ast_build_hostname
const char * ast_build_kernel
const char * ast_build_machine
const char * ast_build_os
const char * ast_build_user
char ast_config_AST_AGI_DIR [PATH_MAX]
char ast_config_AST_CONFIG_DIR [PATH_MAX]
char ast_config_AST_CONFIG_FILE [PATH_MAX]
char ast_config_AST_CTL [PATH_MAX] = "asterisk.ctl"
char ast_config_AST_CTL_GROUP [PATH_MAX] = "\0"
char ast_config_AST_CTL_OWNER [PATH_MAX] = "\0"
char ast_config_AST_CTL_PERMISSIONS [PATH_MAX]
char ast_config_AST_DATA_DIR [PATH_MAX]
char ast_config_AST_DB [PATH_MAX]
char ast_config_AST_KEY_DIR [PATH_MAX]
char ast_config_AST_LOG_DIR [PATH_MAX]
char ast_config_AST_MODULE_DIR [PATH_MAX]
char ast_config_AST_MONITOR_DIR [PATH_MAX]
char ast_config_AST_PID [PATH_MAX]
char ast_config_AST_RUN_DIR [PATH_MAX]
char ast_config_AST_RUN_GROUP [PATH_MAX]
char ast_config_AST_RUN_USER [PATH_MAX]
char ast_config_AST_SOCKET [PATH_MAX]
char ast_config_AST_SPOOL_DIR [PATH_MAX]
char ast_config_AST_SYSTEM_NAME [20] = ""
char ast_config_AST_VAR_DIR [PATH_MAX]
static int ast_consock = -1
time_t ast_lastreloadtime
pid_t ast_mainpid
ast_flags ast_options = { AST_DEFAULT_OPTIONS }
static int ast_socket = -1
time_t ast_startuptime
static const char bang_help []
static struct ast_cli_entry cli_asterisk []
console consoles [AST_MAX_CONNECTS]
static pthread_t consolethread = AST_PTHREADT_NULL
char debug_filename [AST_FILENAME_MAX] = ""
char defaultlanguage [MAX_LANGUAGE] = DEFAULT_LANGUAGE
static EditLine * el
static History * el_hist
static const char * license_lines []
static pthread_t lthread
static unsigned int need_reload
int option_debug
int option_maxcalls
double option_maxload
int option_verbose
static struct profile_dataprof_data
static char randompool [256]
char record_cache_dir [AST_CACHE_DIR_LEN] = AST_TMP_DIR
static char * remotehostname
static const char restart_gracefully_help []
static const char restart_now_help []
static const char restart_when_convenient_help []
static int restartnow
static unsigned int safe_system_level = 0
 Keep track of how many threads are currently trying to wait*() on a child process.
static void * safe_system_prev_handler
static const char show_license_help []
static const char show_threads_help []
static const char show_version_files_help []
static const char show_warranty_help []
static const char shutdown_gracefully_help []
static const char shutdown_now_help []
static const char shutdown_when_convenient_help []
static int shuttingdown
static const char version_help []
static const char * warranty_lines []


Define Documentation

#define AF_LOCAL   AF_UNIX
 

Definition at line 130 of file asterisk.c.

Referenced by ast_makesocket(), ast_tryconnect(), and listener().

#define AST_MAX_CONNECTS   128
 

Definition at line 134 of file asterisk.c.

Referenced by ast_console_toggle_mute(), ast_makesocket(), ast_network_puts(), ast_network_puts_mutable(), and listener().

#define ASTERISK_PROMPT   "*CLI> "
 

Definition at line 1495 of file asterisk.c.

#define ASTERISK_PROMPT2   "%s*CLI> "
 

Definition at line 1497 of file asterisk.c.

#define FORMAT   "%-25.25s %-40.40s\n"
 

Referenced by __iax2_show_peers(), __sip_show_channels(), _sip_show_devices(), _sip_show_peers(), dundi_show_mappings(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), handle_show_version_files(), iax2_show_registry(), iax2_show_users(), show_channeltypes(), show_file_formats(), show_image_formats(), sip_show_domains(), sip_show_inuse(), sip_show_registry(), and sip_show_users().

#define NUM_MSGS   64
 

Definition at line 135 of file asterisk.c.

#define PF_LOCAL   PF_UNIX
 

Definition at line 131 of file asterisk.c.

Referenced by ast_makesocket(), and ast_tryconnect().

#define WELCOME_MESSAGE
 

Welcome message when starting a CLI interface.

Definition at line 138 of file asterisk.c.


Function Documentation

static void __quit_handler int  num  )  [static]
 

Definition at line 1211 of file asterisk.c.

References quit_handler().

01212 {
01213    quit_handler(num, 0, 1, 0);
01214 }

int ast_add_profile const char *  name,
uint64_t  scale
 

support for event profiling

Returns:
Returns the identifier of the counter.

Definition at line 364 of file asterisk.c.

References ast_calloc, ast_realloc, ast_strdup, profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, profile_data::max_size, profile_entry::name, prof_data, profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

00365 {
00366    int l = sizeof(struct profile_data);
00367    int n = 10; /* default entries */
00368 
00369    if (prof_data == NULL) {
00370       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00371       if (prof_data == NULL)
00372          return -1;
00373       prof_data->entries = 0;
00374       prof_data->max_size = n;
00375    }
00376    if (prof_data->entries >= prof_data->max_size) {
00377       void *p;
00378       n = prof_data->max_size + 20;
00379       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00380       if (p == NULL)
00381          return -1;
00382       prof_data = p;
00383       prof_data->max_size = n;
00384    }
00385    n = prof_data->entries++;
00386    prof_data->e[n].name = ast_strdup(name);
00387    prof_data->e[n].value = 0;
00388    prof_data->e[n].events = 0;
00389    prof_data->e[n].mark = 0;
00390    prof_data->e[n].scale = scale;
00391    return n;
00392 }

static int ast_all_zeros char *  s  )  [static]
 

Definition at line 1248 of file asterisk.c.

Referenced by ast_el_read_history(), consolehandler(), and remoteconsolehandler().

01249 {
01250    while (*s) {
01251       if (*s > 32)
01252          return 0;
01253       s++;  
01254    }
01255    return 1;
01256 }

static int ast_cli_display_match_list char **  matches,
int  len,
int  max
[static]
 

Definition at line 1821 of file asterisk.c.

References ast_el_sort_compare(), ast_get_termcols(), and free.

01822 {
01823    int i, idx, limit, count;
01824    int screenwidth = 0;
01825    int numoutput = 0, numoutputline = 0;
01826 
01827    screenwidth = ast_get_termcols(STDOUT_FILENO);
01828 
01829    /* find out how many entries can be put on one line, with two spaces between strings */
01830    limit = screenwidth / (max + 2);
01831    if (limit == 0)
01832       limit = 1;
01833 
01834    /* how many lines of output */
01835    count = len / limit;
01836    if (count * limit < len)
01837       count++;
01838 
01839    idx = 1;
01840 
01841    qsort(&matches[0], (size_t)(len), sizeof(char *), ast_el_sort_compare);
01842 
01843    for (; count > 0; count--) {
01844       numoutputline = 0;
01845       for (i=0; i < limit && matches[idx]; i++, idx++) {
01846 
01847          /* Don't print dupes */
01848          if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) {
01849             i--;
01850             free(matches[idx]);
01851             matches[idx] = NULL;
01852             continue;
01853          }
01854 
01855          numoutput++;
01856          numoutputline++;
01857          fprintf(stdout, "%-*s  ", max, matches[idx]);
01858          free(matches[idx]);
01859          matches[idx] = NULL;
01860       }
01861       if (numoutputline > 0)
01862          fprintf(stdout, "\n");
01863    }
01864 
01865    return numoutput;
01866 }

void ast_console_puts const char *  string  ) 
 

write the string to the console, and all attached console clients

Definition at line 757 of file asterisk.c.

References ast_network_puts().

Referenced by chan_misdn_log().

00758 {
00759    fputs(string, stdout);
00760    fflush(stdout);
00761    ast_network_puts(string);
00762 }

void ast_console_puts_mutable const char *  string  ) 
 

log the string to the console, and all attached console clients

Definition at line 734 of file asterisk.c.

References ast_network_puts_mutable().

Referenced by logger_print_normal().

00735 {
00736    fputs(string, stdout);
00737    fflush(stdout);
00738    ast_network_puts_mutable(string);
00739 }

void ast_console_toggle_mute int  fd  ) 
 

mute or unmute a console from logging

Definition at line 699 of file asterisk.c.

References ast_cli(), AST_MAX_CONNECTS, and consoles.

Referenced by handle_logger_mute().

00699                                      {
00700    int x;
00701    for (x = 0;x < AST_MAX_CONNECTS; x++) {
00702       if (fd == consoles[x].fd) {
00703          if (consoles[x].mute) {
00704             consoles[x].mute = 0;
00705             ast_cli(fd, "Console is not muted anymore.\n");
00706          } else {
00707             consoles[x].mute = 1;
00708             ast_cli(fd, "Console is muted.\n");
00709          }
00710          return;
00711       }
00712    }
00713    ast_cli(fd, "Couldn't find remote console.\n");
00714 }

static int ast_el_add_history char *   )  [static]
 

Definition at line 2015 of file asterisk.c.

References ast_el_initialize().

Referenced by ast_el_read_history(), consolehandler(), and remoteconsolehandler().

02016 {
02017    HistEvent ev;
02018 
02019    if (el_hist == NULL || el == NULL)
02020       ast_el_initialize();
02021    if (strlen(buf) > 256)
02022       return 0;
02023    return (history(el_hist, &ev, H_ENTER, buf));
02024 }

static int ast_el_initialize void   )  [static]
 

Definition at line 1980 of file asterisk.c.

References cli_complete(), and cli_prompt().

Referenced by ast_el_add_history(), ast_el_read_history(), ast_el_write_history(), and ast_remotecontrol().

01981 {
01982    HistEvent ev;
01983    char *editor = getenv("AST_EDITOR");
01984 
01985    if (el != NULL)
01986       el_end(el);
01987    if (el_hist != NULL)
01988       history_end(el_hist);
01989 
01990    el = el_init("asterisk", stdin, stdout, stderr);
01991    el_set(el, EL_PROMPT, cli_prompt);
01992 
01993    el_set(el, EL_EDITMODE, 1);      
01994    el_set(el, EL_EDITOR, editor ? editor : "emacs");     
01995    el_hist = history_init();
01996    if (!el || !el_hist)
01997       return -1;
01998 
01999    /* setup history with 100 entries */
02000    history(el_hist, &ev, H_SETSIZE, 100);
02001 
02002    el_set(el, EL_HIST, history, el_hist);
02003 
02004    el_set(el, EL_ADDFN, "ed-complete", "Complete argument", cli_complete);
02005    /* Bind <tab> to command completion */
02006    el_set(el, EL_BIND, "^I", "ed-complete", NULL);
02007    /* Bind ? to command completion */
02008    el_set(el, EL_BIND, "?", "ed-complete", NULL);
02009    /* Bind ^D to redisplay */
02010    el_set(el, EL_BIND, "^D", "ed-redisplay", NULL);
02011 
02012    return 0;
02013 }

static int ast_el_read_char EditLine *  el,
char *  cp
[static]
 

Definition at line 1562 of file asterisk.c.

References ast_opt_exec, pollfd::events, pollfd::fd, and POLLIN.

Referenced by ast_remotecontrol().

01563 {
01564    int num_read = 0;
01565    int lastpos = 0;
01566    struct pollfd fds[2];
01567    int res;
01568    int max;
01569    char buf[512];
01570 
01571    for (;;) {
01572       max = 1;
01573       fds[0].fd = ast_consock;
01574       fds[0].events = POLLIN;
01575       if (!ast_opt_exec) {
01576          fds[1].fd = STDIN_FILENO;
01577          fds[1].events = POLLIN;
01578          max++;
01579       }
01580       res = poll(fds, max, -1);
01581       if (res < 0) {
01582          if (errno == EINTR)
01583             continue;
01584          ast_log(LOG_ERROR, "poll failed: %s\n", strerror(errno));
01585          break;
01586       }
01587 
01588       if (!ast_opt_exec && fds[1].revents) {
01589          num_read = read(STDIN_FILENO, cp, 1);
01590          if (num_read < 1) {
01591             break;
01592          } else 
01593             return (num_read);
01594       }
01595       if (fds[0].revents) {
01596          res = read(ast_consock, buf, sizeof(buf) - 1);
01597          /* if the remote side disappears exit */
01598          if (res < 1) {
01599             fprintf(stderr, "\nDisconnected from Asterisk server\n");
01600             if (!ast_opt_reconnect) {
01601                quit_handler(0, 0, 0, 0);
01602             } else {
01603                int tries;
01604                int reconnects_per_second = 20;
01605                fprintf(stderr, "Attempting to reconnect for 30 seconds\n");
01606                for (tries=0; tries < 30 * reconnects_per_second; tries++) {
01607                   if (ast_tryconnect()) {
01608                      fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
01609                      printf(term_quit());
01610                      WELCOME_MESSAGE;
01611                      break;
01612                   } else
01613                      usleep(1000000 / reconnects_per_second);
01614                }
01615                if (tries >= 30 * reconnects_per_second) {
01616                   fprintf(stderr, "Failed to reconnect for 30 seconds.  Quitting.\n");
01617                   quit_handler(0, 0, 0, 0);
01618                }
01619             }
01620          }
01621 
01622          buf[res] = '\0';
01623 
01624          if (!ast_opt_exec && !lastpos)
01625             write(STDOUT_FILENO, "\r", 1);
01626          write(STDOUT_FILENO, buf, res);
01627          if ((buf[res-1] == '\n') || (buf[res-2] == '\n')) {
01628             *cp = CC_REFRESH;
01629             return(1);
01630          } else
01631             lastpos = 1;
01632       }
01633    }
01634 
01635    *cp = '\0';
01636    return (0);
01637 }

static int ast_el_read_history char *   )  [static]
 

Definition at line 2036 of file asterisk.c.

References ast_all_zeros(), ast_el_add_history(), and ast_el_initialize().

Referenced by ast_remotecontrol().

02037 {
02038    char buf[256];
02039    FILE *f;
02040    int ret = -1;
02041 
02042    if (el_hist == NULL || el == NULL)
02043       ast_el_initialize();
02044 
02045    if ((f = fopen(filename, "r")) == NULL)
02046       return ret;
02047 
02048    while (!feof(f)) {
02049       fgets(buf, sizeof(buf), f);
02050       if (!strcmp(buf, "_HiStOrY_V2_\n"))
02051          continue;
02052       if (ast_all_zeros(buf))
02053          continue;
02054       if ((ret = ast_el_add_history(buf)) == -1)
02055          break;
02056    }
02057    fclose(f);
02058 
02059    return ret;
02060 }

static int ast_el_sort_compare const void *  i1,
const void *  i2
[static]
 

Definition at line 1811 of file asterisk.c.

Referenced by ast_cli_display_match_list().

01812 {
01813    char *s1, *s2;
01814 
01815    s1 = ((char **)i1)[0];
01816    s2 = ((char **)i2)[0];
01817 
01818    return strcasecmp(s1, s2);
01819 }

static char** ast_el_strtoarr char *  buf  )  [static]
 

Definition at line 1776 of file asterisk.c.

References AST_CLI_COMPLETE_EOF, ast_realloc, strdup, and strsep().

Referenced by cli_complete().

01777 {
01778    char **match_list = NULL, *retstr;
01779    size_t match_list_len;
01780    int matches = 0;
01781 
01782    match_list_len = 1;
01783    while ( (retstr = strsep(&buf, " ")) != NULL) {
01784 
01785       if (!strcmp(retstr, AST_CLI_COMPLETE_EOF))
01786          break;
01787       if (matches + 1 >= match_list_len) {
01788          match_list_len <<= 1;
01789          if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(char *)))) {
01790             /* TODO: Handle memory allocation failure */
01791          }
01792       }
01793 
01794       match_list[matches++] = strdup(retstr);
01795    }
01796 
01797    if (!match_list)
01798       return (char **) NULL;
01799 
01800    if (matches >= match_list_len) {
01801       if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *)))) {
01802          /* TODO: Handle memory allocation failure */
01803       }
01804    }
01805 
01806    match_list[matches] = (char *) NULL;
01807 
01808    return match_list;
01809 }

static int ast_el_write_history char *   )  [static]
 

Definition at line 2026 of file asterisk.c.

References ast_el_initialize().

02027 {
02028    HistEvent ev;
02029 
02030    if (el_hist == NULL || el == NULL)
02031       ast_el_initialize();
02032 
02033    return (history(el_hist, &ev, H_SAVE, filename));
02034 }

static AST_LIST_HEAD_STATIC thread_list  ,
thread_list_t 
[static]
 

static AST_LIST_HEAD_STATIC file_versions  ,
file_version 
[static]
 

static AST_LIST_HEAD_STATIC atexits  ,
ast_atexit 
[static]
 

static int ast_makesocket void   )  [static]
 

Definition at line 892 of file asterisk.c.

References AF_LOCAL, ast_log(), AST_MAX_CONNECTS, ast_pthread_create_background, ast_register_verbose(), ast_strlen_zero(), consoles, group, listener(), LOG_WARNING, network_verboser(), and PF_LOCAL.

00893 {
00894    struct sockaddr_un sunaddr;
00895    int res;
00896    int x;
00897    uid_t uid = -1;
00898    gid_t gid = -1;
00899 
00900    for (x = 0; x < AST_MAX_CONNECTS; x++) 
00901       consoles[x].fd = -1;
00902    unlink(ast_config_AST_SOCKET);
00903    ast_socket = socket(PF_LOCAL, SOCK_STREAM, 0);
00904    if (ast_socket < 0) {
00905       ast_log(LOG_WARNING, "Unable to create control socket: %s\n", strerror(errno));
00906       return -1;
00907    }     
00908    memset(&sunaddr, 0, sizeof(sunaddr));
00909    sunaddr.sun_family = AF_LOCAL;
00910    ast_copy_string(sunaddr.sun_path, ast_config_AST_SOCKET, sizeof(sunaddr.sun_path));
00911    res = bind(ast_socket, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
00912    if (res) {
00913       ast_log(LOG_WARNING, "Unable to bind socket to %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
00914       close(ast_socket);
00915       ast_socket = -1;
00916       return -1;
00917    }
00918    res = listen(ast_socket, 2);
00919    if (res < 0) {
00920       ast_log(LOG_WARNING, "Unable to listen on socket %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
00921       close(ast_socket);
00922       ast_socket = -1;
00923       return -1;
00924    }
00925    ast_register_verbose(network_verboser);
00926    ast_pthread_create_background(&lthread, NULL, listener, NULL);
00927 
00928    if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
00929       struct passwd *pw;
00930       if ((pw = getpwnam(ast_config_AST_CTL_OWNER)) == NULL)
00931          ast_log(LOG_WARNING, "Unable to find uid of user %s\n", ast_config_AST_CTL_OWNER);
00932       else
00933          uid = pw->pw_uid;
00934    }
00935       
00936    if (!ast_strlen_zero(ast_config_AST_CTL_GROUP)) {
00937       struct group *grp;
00938       if ((grp = getgrnam(ast_config_AST_CTL_GROUP)) == NULL)
00939          ast_log(LOG_WARNING, "Unable to find gid of group %s\n", ast_config_AST_CTL_GROUP);
00940       else
00941          gid = grp->gr_gid;
00942    }
00943 
00944    if (chown(ast_config_AST_SOCKET, uid, gid) < 0)
00945       ast_log(LOG_WARNING, "Unable to change ownership of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
00946 
00947    if (!ast_strlen_zero(ast_config_AST_CTL_PERMISSIONS)) {
00948       int p1;
00949       mode_t p;
00950       sscanf(ast_config_AST_CTL_PERMISSIONS, "%o", &p1);
00951       p = p1;
00952       if ((chmod(ast_config_AST_SOCKET, p)) < 0)
00953          ast_log(LOG_WARNING, "Unable to change file permissions of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
00954    }
00955 
00956    return 0;
00957 }

int64_t ast_mark int  i,
int  startstop
 

Definition at line 426 of file asterisk.c.

References profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, prof_data, rdtsc(), profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

00427 {
00428    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00429       return 0;
00430    if (startstop == 1)
00431       prof_data->e[i].mark = rdtsc();
00432    else {
00433       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00434       if (prof_data->e[i].scale > 1)
00435          prof_data->e[i].mark /= prof_data->e[i].scale;