MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / read_available_comdb2db_configs

Function read_available_comdb2db_configs

cdb2api/cdb2api.c:1604–1667  ·  view source on GitHub ↗

Read all available comdb2 configuration files. The function returns -1 if the config file path is longer than PATH_MAX; returns 0 otherwise. */

Source from the content-addressed store, hash-verified

1602 The function returns -1 if the config file path is longer than PATH_MAX;
1603 returns 0 otherwise. */
1604static int read_available_comdb2db_configs(cdb2_hndl_tp *hndl, char comdb2db_hosts[][CDB2HOSTNAME_LEN],
1605 const char *comdb2db_name, int *num_hosts, int *comdb2db_num,
1606 const char *dbname, char db_hosts[][CDB2HOSTNAME_LEN], int *num_db_hosts,
1607 int *dbnum, int noLock, int defaultOnly)
1608{
1609 char filename[PATH_MAX];
1610 SBUF2 *s;
1611 int fallback_on_bb_bin = 1;
1612
1613 if (hndl)
1614 debugprint("entering\n");
1615
1616 if (!noLock) pthread_mutex_lock(&cdb2_cfg_lock);
1617
1618 if (num_hosts)
1619 *num_hosts = 0;
1620 if (num_db_hosts)
1621 *num_db_hosts = 0;
1622 int *send_stack = hndl ? (&hndl->send_stack) : NULL;
1623
1624 if (!defaultOnly && CDB2DBCONFIG_BUF != NULL) {
1625 read_comdb2db_cfg(NULL, NULL, comdb2db_name, CDB2DBCONFIG_BUF,
1626 comdb2db_hosts, num_hosts, comdb2db_num, dbname,
1627 db_hosts, num_db_hosts, dbnum, send_stack);
1628 fallback_on_bb_bin = 0;
1629 } else {
1630 if (!defaultOnly && *CDB2DBCONFIG_NOBBENV != '\0') {
1631 s = sbuf2openread(CDB2DBCONFIG_NOBBENV);
1632 if (s != NULL) {
1633 read_comdb2db_cfg(NULL, s, comdb2db_name, NULL, comdb2db_hosts,
1634 num_hosts, comdb2db_num, dbname, db_hosts,
1635 num_db_hosts, dbnum, send_stack);
1636 sbuf2close(s);
1637 fallback_on_bb_bin = 0;
1638 }
1639 }
1640 }
1641
1642 /* This is a temporary solution. There's no clear plan for how comdb2db.cfg
1643 * will be deployed to non-dbini machines. In the meantime, we have
1644 * programmers who want to use the API on dbini/mini machines. So if we
1645 * can't find the file in any standard location, look at /bb/bin
1646 * Once deployment details for comdb2db.cfg solidify, this will go away. */
1647 if (fallback_on_bb_bin) {
1648 s = sbuf2openread(CDB2DBCONFIG_TEMP_BB_BIN);
1649 if (s != NULL) {
1650 read_comdb2db_cfg(NULL, s, comdb2db_name, NULL, comdb2db_hosts,
1651 num_hosts, comdb2db_num, dbname, db_hosts,
1652 num_db_hosts, dbnum, send_stack);
1653 sbuf2close(s);
1654 }
1655 }
1656
1657 if (get_config_file(dbname, filename, sizeof(filename)) == 0) {
1658 s = sbuf2openread(filename);
1659 if (s != NULL) {
1660 read_comdb2db_cfg(hndl, s, comdb2db_name, NULL, comdb2db_hosts, num_hosts, comdb2db_num, dbname, db_hosts,
1661 num_db_hosts, dbnum, send_stack);

Callers 2

get_comdb2db_hostsFunction · 0.70
only_read_configFunction · 0.70

Calls 3

read_comdb2db_cfgFunction · 0.85
sbuf2openreadFunction · 0.85
get_config_fileFunction · 0.85

Tested by

no test coverage detected