Asterisk - The Open Source Telephony Project  18.5.0
Functions
bt_open.c File Reference
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../include/db.h"
#include "btree.h"
Include dependency graph for bt_open.c:

Go to the source code of this file.

Functions

int __bt_fd (DB *dbp) const
 
DB__bt_open (char *fname, int flags, int mode, const BTREEINFO *openinfo, int dflags) const
 
static int byteorder __P ((void))
 
static int nroot __P ((BTREE *))
 
static int byteorder ()
 
static int nroot (BTREE *t)
 
static int tmp ()
 

Function Documentation

◆ __bt_fd()

int __bt_fd ( DB dbp) const

Definition at line 439 of file bt_open.c.

References B_INMEM, _btree::bt_fd, _btree::bt_mp, _btree::bt_pinned, errno, F_ISSET, __db::internal, mpool_put(), and NULL.

Referenced by __bt_open().

441 {
442  BTREE *t;
443 
444  t = dbp->internal;
445 
446  /* Toss any page pinned across calls. */
447  if (t->bt_pinned != NULL) {
448  mpool_put(t->bt_mp, t->bt_pinned, 0);
449  t->bt_pinned = NULL;
450  }
451 
452  /* In-memory database can't have a file descriptor. */
453  if (F_ISSET(t, B_INMEM)) {
454  errno = ENOENT;
455  return (-1);
456  }
457  return (t->bt_fd);
458 }
#define F_ISSET(p, f)
Definition: btree.h:42
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
void * internal
Definition: db.h:137
#define NULL
Definition: resample.c:96
Definition: btree.h:312
PAGE * bt_pinned
Definition: btree.h:318
MPOOL * bt_mp
Definition: btree.h:313
int errno
#define B_INMEM
Definition: btree.h:368
int bt_fd
Definition: btree.h:335

◆ __bt_open()

DB* __bt_open ( char *  fname,
int  flags,
int  mode,
const BTREEINFO openinfo,
int  dflags 
) const

Definition at line 90 of file bt_open.c.

References __bt_close(), __bt_defcmp(), __bt_defpfx(), __bt_delete(), __bt_fd(), __bt_get(), __bt_pgin(), __bt_pgout(), __bt_put(), __bt_seq(), __bt_sync(), b, B_DB_LOCK, B_DB_SHMEM, B_DB_TXN, B_INMEM, B_METADIRTY, B_NEEDSWAP, B_NODUPS, B_RDONLY, BIG_ENDIAN, _btree::bt_dbp, _btree::bt_fd, _btree::bt_free, _btree::bt_lorder, _btree::bt_mp, _btree::bt_nrecs, _btree::bt_order, _btree::bt_ovflsize, _btree::bt_psize, _btree::bt_rfd, BTDATAOFF, BTREEMAGIC, BTREEVERSION, byteorder(), BTREEINFO::cachesize, DB_BTREE, DB_LOCK, DB_SHMEM, DB_TXN, dbp, DEFMINKEYPAGE, EFTYPE, errno, F_CLR, F_ISSET, F_SET, BTREEINFO::flags, _btree::flags, free(), __db::internal, LITTLE_ENDIAN, BTREEINFO::lorder, malloc(), MAX_PAGE_OFFSET, MINCACHE, BTREEINFO::minkeypage, MINPSIZE, mpool_filter(), mpool_open(), NBLEAFDBT, NOVFLSIZE, nroot(), NULL, P_INVALID, BTREEINFO::psize, R_DUP, RET_ERROR, SAVEMETA, tmp(), and __db::type.

Referenced by __rec_open(), and dbopen().

94 {
95  struct stat sb;
96  BTMETA m;
97  BTREE *t;
98  BTREEINFO b;
99  DB *dbp;
100  pgno_t ncache;
101  ssize_t nr;
102  int machine_lorder;
103 
104  t = NULL;
105 
106  /*
107  * Intention is to make sure all of the user's selections are okay
108  * here and then use them without checking. Can't be complete, since
109  * we don't know the right page size, lorder or flags until the backing
110  * file is opened. Also, the file's page size can cause the cachesize
111  * to change.
112  */
113  machine_lorder = byteorder();
114  if (openinfo) {
115  b = *openinfo;
116 
117  /* Flags: R_DUP. */
118  if (b.flags & ~(R_DUP))
119  goto einval;
120 
121  /*
122  * Page size must be indx_t aligned and >= MINPSIZE. Default
123  * page size is set farther on, based on the underlying file
124  * transfer size.
125  */
126  if (b.psize &&
127  (b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 ||
128  b.psize & (sizeof(indx_t) - 1)))
129  goto einval;
130 
131  /* Minimum number of keys per page; absolute minimum is 2. */
132  if (b.minkeypage) {
133  if (b.minkeypage < 2)
134  goto einval;
135  } else
137 
138  /* If no comparison, use default comparison and prefix. */
139  if (b.compare == NULL) {
140  b.compare = __bt_defcmp;
141  if (b.prefix == NULL)
142  b.prefix = __bt_defpfx;
143  }
144 
145  if (b.lorder == 0)
146  b.lorder = machine_lorder;
147  } else {
148  b.compare = __bt_defcmp;
149  b.cachesize = 0;
150  b.flags = 0;
151  b.lorder = machine_lorder;
153  b.prefix = __bt_defpfx;
154  b.psize = 0;
155  }
156 
157  /* Check for the ubiquitous PDP-11. */
158  if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN)
159  goto einval;
160 
161  /* Allocate and initialize DB and BTREE structures. */
162  if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
163  goto err;
164  memset(t, 0, sizeof(BTREE));
165  t->bt_fd = -1; /* Don't close unopened fd on error. */
166  t->bt_lorder = b.lorder;
167  t->bt_order = NOT;
168  t->bt_cmp = b.compare;
169  t->bt_pfx = b.prefix;
170  t->bt_rfd = -1;
171 
172  if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL)
173  goto err;
174  memset(t->bt_dbp, 0, sizeof(DB));
175  if (t->bt_lorder != machine_lorder)
176  F_SET(t, B_NEEDSWAP);
177 
178  dbp->type = DB_BTREE;
179  dbp->internal = t;
180  dbp->close = __bt_close;
181  dbp->del = __bt_delete;
182  dbp->fd = __bt_fd;
183  dbp->get = __bt_get;
184  dbp->put = __bt_put;
185  dbp->seq = __bt_seq;
186  dbp->sync = __bt_sync;
187 
188  /*
189  * If no file name was supplied, this is an in-memory btree and we
190  * open a backing temporary file. Otherwise, it's a disk-based tree.
191  */
192  if (fname) {
193  switch (flags & O_ACCMODE) {
194  case O_RDONLY:
195  F_SET(t, B_RDONLY);
196  break;
197  case O_RDWR:
198  break;
199  case O_WRONLY:
200  default:
201  goto einval;
202  }
203 
204  if ((t->bt_fd = open(fname, flags, mode)) < 0)
205  goto err;
206 
207  } else {
208  if ((flags & O_ACCMODE) != O_RDWR)
209  goto einval;
210  if ((t->bt_fd = tmp()) == -1)
211  goto err;
212  F_SET(t, B_INMEM);
213  }
214 
215  if (fcntl(t->bt_fd, F_SETFD, 1) == -1)
216  goto err;
217 
218  if (fstat(t->bt_fd, &sb))
219  goto err;
220  if (sb.st_size) {
221  if ((nr = read(t->bt_fd, &m, sizeof(BTMETA))) < 0)
222  goto err;
223  if (nr != sizeof(BTMETA))
224  goto eftype;
225 
226  /*
227  * Read in the meta-data. This can change the notion of what
228  * the lorder, page size and flags are, and, when the page size
229  * changes, the cachesize value can change too. If the user
230  * specified the wrong byte order for an existing database, we
231  * don't bother to return an error, we just clear the NEEDSWAP
232  * bit.
233  */
234  if (m.magic == BTREEMAGIC)
235  F_CLR(t, B_NEEDSWAP);
236  else {
237  F_SET(t, B_NEEDSWAP);
238  M_32_SWAP(m.magic);
239  M_32_SWAP(m.version);
240  M_32_SWAP(m.psize);
241  M_32_SWAP(m.free);
242  M_32_SWAP(m.nrecs);
243  M_32_SWAP(m.flags);
244  }
245  if (m.magic != BTREEMAGIC || m.version != BTREEVERSION)
246  goto eftype;
247  if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 ||
248  m.psize & (sizeof(indx_t) - 1))
249  goto eftype;
250  if (m.flags & ~SAVEMETA)
251  goto eftype;
252  b.psize = m.psize;
253  F_SET(t, m.flags);
254  t->bt_free = m.free;
255  t->bt_nrecs = m.nrecs;
256  } else {
257  /*
258  * Set the page size to the best value for I/O to this file.
259  * Don't overflow the page offset type.
260  */
261  if (b.psize == 0) {
262 #ifdef _STATBUF_ST_BLKSIZE
263  b.psize = sb.st_blksize;
264 #endif
265  if (b.psize < MINPSIZE)
266  b.psize = MINPSIZE;
267  if (b.psize > MAX_PAGE_OFFSET + 1)
268  b.psize = MAX_PAGE_OFFSET + 1;
269  }
270 
271  /* Set flag if duplicates permitted. */
272  if (!(b.flags & R_DUP))
273  F_SET(t, B_NODUPS);
274 
275  t->bt_free = P_INVALID;
276  t->bt_nrecs = 0;
277  F_SET(t, B_METADIRTY);
278  }
279 
280  t->bt_psize = b.psize;
281 
282  /* Set the cache size; must be a multiple of the page size. */
283  if (b.cachesize && b.cachesize & (b.psize - 1))
284  b.cachesize += (~b.cachesize & (b.psize - 1)) + 1;
285  if (b.cachesize < b.psize * MINCACHE)
286  b.cachesize = b.psize * MINCACHE;
287 
288  /* Calculate number of pages to cache. */
289  ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize;
290 
291  /*
292  * The btree data structure requires that at least two keys can fit on
293  * a page, but other than that there's no fixed requirement. The user
294  * specified a minimum number per page, and we translated that into the
295  * number of bytes a key/data pair can use before being placed on an
296  * overflow page. This calculation includes the page header, the size
297  * of the index referencing the leaf item and the size of the leaf item
298  * structure. Also, don't let the user specify a minkeypage such that
299  * a key/data pair won't fit even if both key and data are on overflow
300  * pages.
301  */
302  t->bt_ovflsize = (t->bt_psize - BTDATAOFF) / b.minkeypage -
303  (sizeof(indx_t) + NBLEAFDBT(0, 0));
304  if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t))
305  t->bt_ovflsize =
306  NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t);
307 
308  /* Initialize the buffer pool. */
309  if ((t->bt_mp =
310  mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL)
311  goto err;
312  if (!F_ISSET(t, B_INMEM))
314 
315  /* Create a root page if new tree. */
316  if (nroot(t) == RET_ERROR)
317  goto err;
318 
319  /* Global flags. */
320  if (dflags & DB_LOCK)
321  F_SET(t, B_DB_LOCK);
322  if (dflags & DB_SHMEM)
323  F_SET(t, B_DB_SHMEM);
324  if (dflags & DB_TXN)
325  F_SET(t, B_DB_TXN);
326 
327  return (dbp);
328 
329 einval: errno = EINVAL;
330  goto err;
331 
332 eftype: errno = EFTYPE;
333  goto err;
334 
335 err: if (t) {
336  if (t->bt_dbp)
337  free(t->bt_dbp);
338  if (t->bt_fd != -1)
339  (void)close(t->bt_fd);
340  free(t);
341  }
342  return (NULL);
343 }
int __bt_close(DB *dbp)
Definition: bt_close.c:64
int bt_rfd
Definition: btree.h:353
#define MINCACHE
Definition: btree.h:55
#define B_DB_TXN
Definition: btree.h:387
#define RET_ERROR
Definition: db.h:51
#define B_DB_SHMEM
Definition: btree.h:386
#define F_SET(p, f)
Definition: btree.h:40
#define F_ISSET(p, f)
Definition: btree.h:42
static int nroot(BTREE *t)
Definition: bt_open.c:355
#define DB_TXN
Definition: db.h:125
#define BTREEVERSION
Definition: db.h:142
static int tmp()
Definition: bt_open.c:389
dflags
Definition: app_dictate.c:63
#define B_RDONLY
Definition: btree.h:372
int __bt_put(DB *dbp, DBT *key, const DBT *data, u_int flags) const
Definition: bt_put.c:67
u_int32_t flags
Definition: btree.h:388
void * internal
Definition: db.h:137
#define F_CLR(p, f)
Definition: btree.h:41
#define NULL
Definition: resample.c:96
#define MINPSIZE
Definition: btree.h:56
#define B_NEEDSWAP
Definition: btree.h:371
u_int16_t indx_t
Definition: db.h:80
recno_t bt_nrecs
Definition: btree.h:360
Definition: btree.h:312
#define NOVFLSIZE
Definition: btree.h:117
Definition: db.h:145
u_long flags
Definition: db.h:147
char * malloc()
void free()
void __bt_pgout(void *t, pgno_t pg, void *pp)
Definition: bt_conv.c:129
#define SAVEMETA
Definition: btree.h:307
u_int cachesize
Definition: db.h:148
Definition: db.h:103
#define DB_LOCK
Definition: db.h:123
#define BIG_ENDIAN
void mpool_filter(MPOOL *mp, void *pgin, void *pgout, void *pgcookie)
Definition: mpool.c:114
void __bt_pgin(void *t, pgno_t pg, void *pp)
Definition: bt_conv.c:61
int bt_lorder
Definition: btree.h:340
#define MAX_PAGE_OFFSET
Definition: db.h:79
MPOOL * bt_mp
Definition: btree.h:313
DBTYPE type
Definition: db.h:130
int __bt_defcmp(DBT *a, DBT *b) const
Definition: bt_utils.c:216
static DB * dbp
Definition: hsearch.c:49
#define B_NODUPS
Definition: btree.h:374
u_int32_t pgno_t
Definition: db.h:78
int errno
#define R_DUP
Definition: db.h:146
#define LITTLE_ENDIAN
#define NBLEAFDBT(ksize, dsize)
Definition: btree.h:195
#define DB_SHMEM
Definition: db.h:124
u_int32_t bt_psize
Definition: btree.h:338
#define EFTYPE
#define DEFMINKEYPAGE
Definition: btree.h:54
int lorder
Definition: db.h:156
enum _btree::@518 bt_order
#define B_METADIRTY
Definition: btree.h:369
int minkeypage
Definition: db.h:150
static int byteorder()
Definition: bt_open.c:421
int __bt_delete(DB *dbp, const DBT *key, u_int flags) const
Definition: bt_delete.c:63
int __bt_sync(DB *dbp, u_int flags) const
Definition: bt_close.c:119
#define B_INMEM
Definition: btree.h:368
#define P_INVALID
Definition: btree.h:63
#define BTREEMAGIC
Definition: db.h:141
#define BTDATAOFF
Definition: btree.h:95
int __bt_get(DB *dbp, const DBT *key, DBT *data, u_int flags) const
Definition: bt_get.c:63
int bt_fd
Definition: btree.h:335
int __bt_seq(DB *dbp, DBT *key, DBT *data, u_int flags) const
Definition: bt_seq.c:77
indx_t bt_ovflsize
Definition: btree.h:339
DB * bt_dbp
Definition: btree.h:315
Definition: db.h:129
static struct test_val b
u_int psize
Definition: db.h:151
MPOOL * mpool_open(void *key, int fd, pgno_t pagesize, pgno_t maxcache)
Definition: mpool.c:74
pgno_t bt_free
Definition: btree.h:337
#define B_DB_LOCK
Definition: btree.h:385
size_t __bt_defpfx(DBT *a, DBT *b) const
Definition: bt_utils.c:246
Definition: btree.h:300
int __bt_fd(DB *dbp) const
Definition: bt_open.c:439

◆ __P() [1/2]

static int tmp __P ( (void)  )
static

◆ __P() [2/2]

static int nroot __P ( (BTREE *)  )
static

◆ byteorder()

static int byteorder ( )
static

Definition at line 421 of file bt_open.c.

References BIG_ENDIAN, and LITTLE_ENDIAN.

Referenced by __bt_open().

422 {
423  u_int32_t x;
424  u_char *p;
425 
426  x = 0x01020304;
427  p = (u_char *)&x;
428  switch (*p) {
429  case 1:
430  return (BIG_ENDIAN);
431  case 4:
432  return (LITTLE_ENDIAN);
433  default:
434  return (0);
435  }
436 }
#define BIG_ENDIAN
#define LITTLE_ENDIAN
unsigned int u_int32_t

◆ nroot()

static int nroot ( BTREE t)
static

Definition at line 355 of file bt_open.c.

References _btree::bt_mp, _btree::bt_psize, BTDATAOFF, errno, _page::flags, _page::lower, env::meta, MPOOL_DIRTY, mpool_get(), mpool_new(), mpool_put(), _page::nextpg, NULL, P_BLEAF, P_INVALID, P_ROOT, _page::pgno, _page::prevpg, RET_ERROR, RET_SUCCESS, and _page::upper.

Referenced by __bt_open().

357 {
358  PAGE *meta, *root;
359  pgno_t npg;
360 
361  if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) {
362  mpool_put(t->bt_mp, meta, 0);
363  return (RET_SUCCESS);
364  }
365  if (errno != EINVAL) /* It's OK to not exist. */
366  return (RET_ERROR);
367  errno = 0;
368 
369  if ((meta = mpool_new(t->bt_mp, &npg)) == NULL)
370  return (RET_ERROR);
371 
372  if ((root = mpool_new(t->bt_mp, &npg)) == NULL)
373  return (RET_ERROR);
374 
375  if (npg != P_ROOT)
376  return (RET_ERROR);
377  root->pgno = npg;
378  root->prevpg = root->nextpg = P_INVALID;
379  root->lower = BTDATAOFF;
380  root->upper = t->bt_psize;
381  root->flags = P_BLEAF;
382  memset(meta, 0, t->bt_psize);
383  mpool_put(t->bt_mp, meta, MPOOL_DIRTY);
384  mpool_put(t->bt_mp, root, MPOOL_DIRTY);
385  return (RET_SUCCESS);
386 }
Definition: btree.h:75
#define RET_ERROR
Definition: db.h:51
pgno_t pgno
Definition: btree.h:76
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
indx_t lower
Definition: btree.h:89
#define NULL
Definition: resample.c:96
indx_t upper
Definition: btree.h:90
#define MPOOL_DIRTY
Definition: mpool.h:61
meta
below block is needed for mssql
Definition: env.py:22
void * mpool_get(MPOOL *mp, pgno_t pgno, u_int flags)
Definition: mpool.c:165
u_int32_t flags
Definition: btree.h:87
#define RET_SUCCESS
Definition: db.h:52
MPOOL * bt_mp
Definition: btree.h:313
u_int32_t pgno_t
Definition: db.h:78
pgno_t nextpg
Definition: btree.h:78
int errno
pgno_t prevpg
Definition: btree.h:77
u_int32_t bt_psize
Definition: btree.h:338
#define P_ROOT
Definition: btree.h:65
#define P_INVALID
Definition: btree.h:63
#define BTDATAOFF
Definition: btree.h:95
void * mpool_new(MPOOL *mp, pgno_t *pgnoaddr)
Definition: mpool.c:130
#define P_BLEAF
Definition: btree.h:81

◆ tmp()

static int tmp ( )
static
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 389 of file bt_open.c.

References free(), malloc(), and NULL.

Referenced by __aco_option_register(), __ast_channel_alloc_ap(), __ast_channel_internal_alloc(), __ast_context_create(), __ast_context_destroy(), __ast_dummy_channel_alloc(), __ast_format_def_register(), __ast_internal_context_destroy(), __ast_pthread_mutex_lock(), __ast_pthread_mutex_trylock(), __ast_register_translator(), __ast_rwlock_rdlock(), __ast_rwlock_timedrdlock(), __ast_rwlock_timedwrlock(), __ast_rwlock_tryrdlock(), __ast_rwlock_trywrlock(), __ast_rwlock_wrlock(), __bt_open(), _build_port_config(), _macro_exec(), _parse(), _sip_tcp_helper_thread(), acf_curlopt_write(), acf_odbc_read(), acf_rand_exec(), action_dahdishowchannels(), action_login(), action_originate(), actual_load_config(), add_crypto_to_stream(), add_date(), add_digit(), add_expires(), add_menu_entry(), add_pri(), add_priority(), add_rpid(), add_ssrc_to_stream(), adpcmtolin_framein(), adsi_process(), aes_helper(), alsa_new(), alsa_request(), aMYSQL_set(), append_date(), append_event(), append_ha_core(), append_int(), append_mailbox(), aqm_exec(), ast_add_extension2(), ast_add_extension2_lockopt(), ast_alertpipe_flush(), ast_alertpipe_read(), ast_alertpipe_write(), ast_app_group_split_group(), ast_append_acl(), ast_ari_asterisk_get_global_var(), ast_bucket_alloc(), ast_bucket_file_alloc(), ast_callerid_parse(), ast_callerid_split(), ast_callid_threadstorage_auto(), ast_cli_command_full(), ast_config_hook_unregister(), ast_config_option(), ast_context_find(), ast_context_find_or_create(), ast_format_def_unregister(), ast_get_enum(), ast_get_hint(), ast_hashtab_hash_string(), ast_hashtab_hash_string_nocase(), ast_iax2_new(), ast_jb_read_conf(), ast_loader_register(), ast_media_cache_create_or_update(), ast_merge_contexts_and_delete(), ast_mkdir(), ast_monitor_stop(), ast_privacy_check(), ast_privacy_set(), ast_read_image(), ast_register_application2(), ast_register_switch(), ast_remotecontrol(), ast_sched_add_variable(), ast_sched_context_create(), ast_sip_create_dialog_uac(), ast_sip_create_rdata_with_contact(), ast_sip_set_outbound_proxy(), ast_sorcery_changeset_create(), ast_sorcery_objectset_create2(), ast_sorcery_objectset_json_create(), ast_srtp_policy_alloc(), ast_str_encode_mime(), ast_str_get_hint(), ast_strftime_locale(), AST_TEST_DEFINE(), ast_unregister_translator(), ast_uri_decode(), ast_utf8_validator_new(), ast_variables_dup(), ast_xmldoc_printable(), auth_exec(), background_detect_exec(), bucket_file_wizard_retrieve(), bucket_wizard_retrieve(), build_channels(), build_contact(), build_peer(), build_radius_record(), build_rand_pad(), build_secret(), cache_lookup(), caldav_add_event(), calendar_join_attendees(), callstate2str(), cb_events(), cdr_handler(), chan_misdn_log(), channel_spy(), chanspy_exec(), check_peer_ok(), check_user_full(), check_via(), cli_fax_show_session(), cli_prompt(), cli_show_module_options(), cli_show_module_type(), cli_show_module_types(), codec2_destroy_stuff(), codec2_new(), codec2tolin_framein(), common_exec(), complete_queue_remove_member(), conf_get_pin(), config_module(), console_dial(), console_transfer(), control2str(), controlplayback_exec(), copy_all_header(), copy_header(), copy_plain_file(), copy_rules(), copy_vars(), cpeid_setstatus(), create_client(), create_followme_number(), create_jb(), create_outgoing_sdp_stream(), create_queue_member(), crypto_get_attrib(), custom_presence_callback(), dahdi_cc_callback(), dahdi_new(), dahdi_request(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), device2str(), dial_exec_full(), dialgroup_read(), disa_exec(), do_monitor(), do_pktccops(), dump_answer(), dump_ies(), dump_prov_ies(), dump_samprate(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_ie_append_answer(), dundi_ie_append_cause(), dundi_ie_append_encdata(), dundi_ie_append_hint(), dundi_ie_append_raw(), dundi_lookup_local(), dundi_parse_ies(), dundi_reject(), dundi_showframe(), eivr_comm(), epoch_to_exchange_time(), export_ch(), extenspy_exec(), fetch_response_reader(), find_by_mark(), find_channel(), find_queue_by_name_rt(), find_result(), find_subchannel_and_lock(), free_zone(), function_enum(), g722tolin16_new(), g722tolin_framein(), g722tolin_new(), g726aal2tolin_framein(), g726tolin_framein(), generate_fmtp_attr(), generate_rtpmap_attr(), generator_force(), get_also_info(), get_chan_by_ast_name(), get_destination(), get_extension_data(), get_in_brackets(), get_in_brackets_full(), get_multiple_fields_as_var_list(), get_name_from_variable(), get_rdnis(), get_rpid(), get_single_field_as_var_list(), get_token(), gr_say_number_female(), gsm_destroy_stuff(), gsm_new(), gsmtolin_framein(), handle_call_forward(), handle_characters(), handle_cli_check_permissions(), handle_cli_confbridge_show_bridge_profile(), handle_cli_database_get(), handle_cli_iax2_show_cache(), handle_cli_keys_init(), handle_cli_misdn_send_digit(), handle_cli_misdn_send_display(), handle_cli_misdn_send_facility(), handle_cli_misdn_toggle_echocancel(), handle_dahdi_show_cadences(), handle_minivm_show_users(), handle_request_info(), handle_select_option(), handle_setcallerid(), handle_speechrecognize(), has_voicemail(), hash_string(), hashkeys_read2(), heap_swap(), iax2_call(), iax2_datetime(), iax2_devicestate(), iax2_transfer(), iax2_trunk_queue(), iax_ie_append_raw(), iax_parse_ies(), iax_provision_build(), iax_provision_version(), iax_showframe(), iax_template_parse(), icalendar_add_event(), ilbctolin_framein(), ilbctolin_new(), import_ch(), inboxcount2(), init_acf_query(), init_phone_step2(), internal_format_cap_identical(), io_context_create(), io_grow(), jingle_add_ice_udp_candidates_to_transport(), jingle_add_payloads_to_description(), launch_script(), leave_voicemail(), lin16tog722_new(), lintoadpcm_framein(), lintoadpcm_frameout(), lintocodec2_framein(), lintocodec2_frameout(), lintog722_framein(), lintog722_new(), lintog726_framein(), lintog726_new(), lintog726aal2_framein(), lintogsm_framein(), lintogsm_frameout(), lintoilbc_framein(), lintoilbc_frameout(), lintoilbc_new(), lintolpc10_framein(), lintolpc10_frameout(), lintospeex_feedback(), lintospeex_framein(), lintospeex_frameout(), load_config(), load_module(), load_password(), load_values_config(), local_read(), loopback_subst(), lpc10_dec_new(), lpc10_enc_new(), lpc10tolin_framein(), lua_pbx_exec(), main(), manage_calls(), manager_action(), manager_dbget(), manager_login(), mgcp_devicestate(), mgcp_new(), mgcp_request(), mgcp_senddigit_end(), minivm_accmess_exec(), minivm_greet_exec(), minivm_mwi_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_answer(), misdn_call(), misdn_cfg_get_ports_string(), misdn_chan_is_valid(), misdn_new(), misdn_read(), misdn_send_text(), misdn_set_opt_exec(), mixmonitor_save_prep(), mkif(), mkintf(), moh_files_write_format_change(), my_load_config_number(), my_load_config_string(), nbs_new(), nbs_request(), new_iax(), normalise_history(), odbc_load_module(), odbc_log(), ogg_vorbis_rewrite(), ooh323_request(), open_history(), optimize_transactions(), osp_create_uuid(), osp_get_varfloat(), osp_get_varint(), osp_lookup(), osp_report_qos(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), P2(), page_exec(), parse_hint_device(), parse_hint_presence(), parse_tag(), parse_uri_cb(), pbx_builtin_importvar(), pbx_builtin_saynumber(), pbx_extension_helper(), pbx_find_extension(), pbx_load_users(), pbx_outgoing_attempt(), pbx_substitute_variables_helper_full(), peer_set_srcaddr(), phone_new(), phone_request(), playback_exec(), presence_write(), process_dahdi(), process_my_load_module(), process_sdp_a_audio(), prov_ver_calc(), pw_cb(), random_binaural_pos_change(), rcv_mac_addr(), read_exec(), read_mf_exec(), read_sf_exec(), realtime_directory(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_peer(), realtime_peer_by_name(), realtime_user(), rebuild_channels(), record_exec(), register_verify(), reload_config(), reload_followme(), reload_module(), reload_single_member(), reply_digest(), reqprep(), request(), res_sdp_crypto_parse_offer(), res_sdp_srtp_get_attr(), restart_monitor(), rxqcheck(), save_secret(), sched_alloc(), send_eivr_event(), send_raw_client(), send_request(), send_response(), sendmail(), sendurl_exec(), set_config(), set_remote_mslabel_and_stream_group(), show_config_description(), show_phone_number(), sip_devicestate(), sip_dialog_create_contact(), sip_dialog_create_from(), sip_new(), sip_outbound_publisher_set_uri(), sip_outbound_registration_regc_alloc(), sip_prune_realtime(), sip_request_call(), sip_tcptls_write(), skel_exec(), skinny_devicestate(), skinny_new(), skinny_request(), skinny_senddigit_end(), smb_pitch_shift(), socket_receive_file_to_buff(), softmix_mixing_array_grow(), sorcery_config_open(), sorcery_realtime_open(), sort_items(), speech_background(), speech_read(), speech_score(), speex_decoder_construct(), speex_encoder_construct(), speextolin_framein(), sqlite3_escape_column_op(), sqlite3_escape_string_helper(), start_monitor_exec(), start_resource(), StateConstructW(), StateSearchW(), store_tone_zone_ring_cadence(), substate2str(), time2sub(), timesub(), to_string(), transfer_redirect(), transfer_refer(), transmit_connect(), transmit_connect_with_sdp(), transmit_modify_request(), transmit_modify_with_sdp(), transmit_notify_with_sipfrag(), transmit_register(), transmit_response_with_auth(), transmit_response_with_minexpires(), transmit_state_notify(), try_calling(), try_redirect(), unistim_line_copy(), unistim_new(), unistim_request(), unistim_sendtext(), unistim_sp(), unistimsock_read(), uri_parse_and_default(), ustmtext(), vm_allocate_dh(), vm_change_password(), vm_exec(), vq(), wav_open(), wav_read(), wav_rewrite(), wav_write(), while_continue_exec(), write_history(), xml_encode_str(), xmldoc_get_formatted(), xmldoc_get_syntax_config_object(), xmldoc_parse_para(), xmldoc_parse_variable(), xmldoc_parse_variablelist(), xmldoc_reverse_helper(), xmldoc_string_wrap(), and xmldoc_update_config_type().

390 {
391  sigset_t set, oset;
392  int fd;
393  const char *envtmp;
394  char *path;
395  static const char fmt[] = "%s/bt.XXXXXX";
396  size_t n;
397 
398  envtmp = getenv("TMPDIR");
399  if (!envtmp)
400  envtmp = "/tmp";
401  n = strlen (envtmp) + sizeof fmt;
402 #ifdef __GNUC__
403  path = __builtin_alloca(n);
404 #else
405  path = malloc(n);
406 #endif
407  (void)snprintf(path, n, fmt, envtmp ? envtmp : "/tmp");
408 
409  (void)sigfillset(&set);
410  (void)sigprocmask(SIG_BLOCK, &set, &oset);
411  if ((fd = mkstemp(path)) != -1)
412  (void)unlink(path);
413  (void)sigprocmask(SIG_SETMASK, &oset, NULL);
414 #ifndef __GNUC__
415  free(path);
416 #endif
417  return(fd);
418 }
#define NULL
Definition: resample.c:96
char * malloc()
void free()