当前位置: 首页>>代码示例>>C++>>正文


C++ DB_ENV::set_errpfx方法代码示例

本文整理汇总了C++中DB_ENV::set_errpfx方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::set_errpfx方法的具体用法?C++ DB_ENV::set_errpfx怎么用?C++ DB_ENV::set_errpfx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB_ENV的用法示例。


在下文中一共展示了DB_ENV::set_errpfx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
bdb_open(void)
{
	DB *db;
	DBC *dbc;
	DB_ENV *dbenv;

	assert(db_env_create(&dbenv, 0) == 0);
	dbenv->set_errpfx(dbenv, "bdb");
	dbenv->set_errfile(dbenv, stderr);
	assert(dbenv->mutex_set_max(dbenv, 10000) == 0);
	assert(dbenv->set_cachesize(dbenv, 0, 50 * 1024 * 1024, 1) == 0);
	assert(dbenv->open(dbenv, NULL,
	    DB_CREATE |
	    (g.c_delete_pct == 0 && g.c_insert_pct == 0 && g.c_write_pct == 0 ?
	    0 : DB_INIT_LOCK) |
	    DB_INIT_MPOOL | DB_PRIVATE, 0) == 0);
	assert(db_create(&db, dbenv, 0) == 0);

	if (g.c_file_type == ROW && g.c_reverse)
		assert(db->set_bt_compare(db, bdb_compare_reverse) == 0);

	assert(db->open(db, NULL, "__bdb", NULL, DB_BTREE, DB_CREATE, 0) == 0);
	g.bdb = db;
	assert(db->cursor(db, NULL, &dbc, 0) == 0);
	g.dbc = dbc;

	key_gen_setup(&keybuf);
}
开发者ID:qixin,项目名称:wiredtiger,代码行数:29,代码来源:bdb.c

示例2: TestSetThreadCount

int TestSetThreadCount(CuTest *ct) { /* SKIP */
/* Run this test only when hash is supported. */
#ifdef HAVE_HASH
	DB_ENV *dbenv;
	DB *db;

	CuAssert(ct, "db_env_create", db_env_create(&dbenv, 0) == 0);

	dbenv->set_errpfx(dbenv, "TestSetThreadCount");
	CuAssert(ct, "set_thread_count", dbenv->set_thread_count(dbenv, 2) == 0);
	CuAssert(ct, "env->open", dbenv->open(dbenv, ".",
			DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |
			DB_INIT_TXN | DB_PRIVATE | DB_THREAD, 0) == 0);

	CuAssert(ct, "db_create", db_create(&db, dbenv, 0) == 0);
	CuAssert(ct, "DB->open", db->open(
	    db, NULL, NULL, "TestSetThreadCount", DB_HASH, DB_CREATE, 0) == 0);

	db->close(db, 0);
	dbenv->close(dbenv, 0);
#else
	printf("TestSetThreadCount is not supported by the build.\n");
#endif /* HAVE_HASH */
	return (0);
}
开发者ID:Pakrik,项目名称:libdb,代码行数:25,代码来源:TestEnvMethod.c

示例3:

DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok)
{
	DB_ENV *env = NULL;    
	int     err;
	u_int32_t	envFlags;

	err = db_env_create( &env, 0 );

	if ( err ) {
#ifdef LDAP_SYSLOG
		syslog( LOG_INFO, "ldbm_initialize_env(): "
			"FATAL error in db_env_create() : %s (%d)\n",
			db_strerror( err ), err );
#endif
		return NULL;
	}

#if DB_VERSION_X >= 0x030300
	/* This interface appeared in 3.3 */
	env->set_alloc( env, ldbm_malloc, NULL, NULL );
#endif

	env->set_errcall( env, ldbm_db_errcall );
	env->set_errpfx( env, "==>" );
	if (dbcachesize) {
		env->set_cachesize( env, 0, dbcachesize, 0 );
	}

	envFlags = DB_CREATE | DB_INIT_MPOOL | DB_USE_ENVIRON;
#ifdef DB_PRIVATE
	envFlags |= DB_PRIVATE;
#endif
#ifdef DB_MPOOL_PRIVATE
	envFlags |= DB_MPOOL_PRIVATE;
#endif
#ifdef HAVE_BERKELEY_DB_THREAD
	envFlags |= DB_THREAD;
#endif

#if DB_VERSION_X >= 0x030100
	err = env->open( env, home, envFlags, 0 );
#else
	/* 3.0.x requires an extra argument */
	err = env->open( env, home, NULL, envFlags, 0 );
#endif

	if ( err != 0 ) {
#ifdef LDAP_SYSLOG
		syslog(	LOG_INFO, "ldbm_initialize_env(): "
			"FATAL error in dbEnv->open() : %s (%d)\n",
			db_strerror( err ), err );
#endif
		env->close( env, 0 );
		return NULL;
	}

	*envdirok = 1;
	return env;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:59,代码来源:ldbm.c

示例4: bdblib_create_dbenv

int bdblib_create_dbenv(DB_ENV **_dbenv, char* _home)
{
	DB_ENV *env;
	char *progname;
	int rc, flags;
	
	progname = "kamailio";
	
	/* Create an environment and initialize it for additional error * reporting. */ 
	if ((rc = db_env_create(&env, 0)) != 0) 
	{
		ERR("db_env_create failed! bdb error: %s.\n", db_strerror(rc)); 
		return (rc);
	}
 
	env->set_errpfx(env, progname);

	/*  Specify the shared memory buffer pool cachesize */ 
	if ((rc = env->set_cachesize(env, 0, _bdb_parms->cache_size, 0)) != 0) 
	{
		ERR("dbenv set_cachsize failed! bdb error: %s.\n", db_strerror(rc));
		env->err(env, rc, "set_cachesize"); 
		goto err; 
	}

	/* Concurrent Data Store flags */
	flags = DB_CREATE |
		DB_INIT_CDB |
		DB_INIT_MPOOL |
		DB_THREAD;
	
	/* Transaction Data Store flags ; not supported yet */
	/*
	flags = DB_CREATE |
		DB_RECOVER |
		DB_INIT_LOG | 
		DB_INIT_LOCK |
		DB_INIT_MPOOL |
		DB_THREAD |
		DB_INIT_TXN;
	*/
	
	/* Open the environment */ 
	if ((rc = env->open(env, _home, flags, 0)) != 0) 
	{ 
		ERR("dbenv is not initialized! bdb error: %s.\n",db_strerror(rc));
		env->err(env, rc, "environment open: %s", _home); 
		goto err; 
	}
	
	*_dbenv = env;
	return (0);

err: (void)env->close(env, 0);
	return (rc);
}
开发者ID:SibghatullahSheikh,项目名称:kamailio,代码行数:56,代码来源:bdb_lib.c

示例5:

void
env_open(DB_ENV **dbenvp)
{
	DB_ENV *dbenv;
	int ret;

	/* Create the environment handle. */
	if ((ret = db_env_create(&dbenv, 0)) != 0) {
		fprintf(stderr,
		    "txnapp: db_env_create: %s\n", db_strerror(ret));
		exit (1);
	}

	/* Set up error handling. */
	dbenv->set_errpfx(dbenv, "txnapp");
	dbenv->set_errfile(dbenv, stderr);

	// match lladd's defaults...
	dbenv->set_lg_bsize(dbenv, 1024*1024);
	// match lladd's defaults...
	dbenv->set_cachesize(dbenv, 0, 8204288, 0);


	/* Do deadlock detection internally. */
	/*	if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT)) != 0) {
		dbenv->err(dbenv, ret, "set_lk_detect: DB_LOCK_DEFAULT");
		exit (1);
		}*/

	dbenv->set_tx_max(dbenv, 32000);
	unsigned int max;
	dbenv->get_tx_max(dbenv, &max);
	printf("Max xact count: %d\n", max);


	/*
	 * Open a transactional environment:
	 *	create if it doesn't exist
	 *	free-threaded handle
	 *	run recovery
	 *	read/write owner only
	 */
	if ((ret = dbenv->open(dbenv, ENV_DIRECTORY,
			       DB_CREATE |/* DB_INIT_LOCK |*/ DB_INIT_LOG |  DB_PRIVATE | 
			       DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_THREAD,
			       S_IRUSR | S_IWUSR)) != 0) {
		dbenv->err(dbenv, ret, "dbenv->open: %s", ENV_DIRECTORY);
		exit (1);
	}

	*dbenvp = dbenv;
}
开发者ID:DreamtoucherN01,项目名称:stasis,代码行数:52,代码来源:genericBerkeleyDBCode.c

示例6: fprintf

void
env_open(DB_ENV **dbenvp)
{
        DB_ENV *dbenv;
        int ret;




        /* Create the environment handle. */
        if ((ret = db_env_create(&dbenv, 0)) != 0) {
                fprintf(stderr,
                    "txnapp: db_env_create: %s\n", db_strerror(ret));
                exit (1);
        }




        /* Set up error handling. */
        dbenv->set_errpfx(dbenv, "txnapp");
        dbenv->set_errfile(dbenv, stderr);




        /*
         * Open a transactional environment:
         *      create if it doesn't exist
         *      free-threaded handle
         *      run recovery
         *      read/write owner only
         */
        if ((ret = dbenv->open(dbenv, ENV_DIRECTORY,
            DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
            DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER ,
            S_IRUSR | S_IWUSR)) != 0) {
                (void)dbenv->close(dbenv, 0);
                fprintf(stderr, "dbenv->open: %s: %s\n",
                    ENV_DIRECTORY, db_strerror(ret));
                exit (1);
        }




        *dbenvp = dbenv;
}
开发者ID:Zhoutall,项目名称:stasis,代码行数:48,代码来源:jbhashmany.c

示例7: return

/* Create and configure an environment handle. */
int
create_env(const char *progname, DB_ENV **dbenvp)
{
    DB_ENV *dbenv;
    int ret;

    if ((ret = db_env_create(&dbenv, 0)) != 0) {
	fprintf(stderr, "can't create env handle: %s\n",
	    db_strerror(ret));
	return (ret);
    }

    dbenv->set_errfile(dbenv, stderr);
    dbenv->set_errpfx(dbenv, progname);

    *dbenvp = dbenv;
    return (0);
}
开发者ID:kanbang,项目名称:Colt,代码行数:19,代码来源:simple_txn.c

示例8:

void
env_open(DB_ENV **dbenvp)
{
	DB_ENV *dbenv;
	int ret;

	/* Create the environment handle. */
	if ((ret = db_env_create(&dbenv, 0)) != 0) {
		fprintf(stderr,
		    "txnapp: db_env_create: %s\n", db_strerror(ret));
		exit (1);
	}

	/* Set up error handling. */
	dbenv->set_errpfx(dbenv, "txnapp");
	dbenv->set_errfile(dbenv, stderr);

	/* Do deadlock detection internally. */
	if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT)) != 0) {
		dbenv->err(dbenv, ret, "set_lk_detect: DB_LOCK_DEFAULT");
		exit (1);
	}

	/*
	 * Open a transactional environment:
	 *	create if it doesn't exist
	 *	free-threaded handle
	 *	run recovery
	 *	read/write owner only
	 */
	if ((ret = dbenv->open(dbenv, ENV_DIRECTORY,
	    DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
	    DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_THREAD,
	    S_IRUSR | S_IWUSR)) != 0) {
		dbenv->err(dbenv, ret, "dbenv->open: %s", ENV_DIRECTORY);
		exit (1);
	}

	*dbenvp = dbenv;
}
开发者ID:Zhoutall,项目名称:stasis,代码行数:40,代码来源:bdbHash.c

示例9: return

/*
 * db_init --
 *      Initialize the environment.
 */
int
db_init(char *home, DB_ENV **dbenvp)
{
  int ret;
  DB_ENV *dbenv;

  if ((ret = db_env_create(&dbenv, 0)) != 0) 
    return (ret);
  
  /* dbenv->set_lk_max(dbenv, 10000); */
  dbenv->set_cachesize(dbenv, 0, 16 * 1024 * 1024, 0);
  /* new version only ... dbenv->set_flags(dbenv, DB_CDB_ALLDB, 1); */
  
  if (home == NULL) {
    home = getenv("CHESHIRE_DB_HOME");
    if (home == NULL) {
      fprintf(stderr, "CHESHIRE_DB_HOME must be set OR config file <DBENV> set\n");
      fprintf(LOGFILE, "CHESHIRE_DB_HOME must be set OR config file <DBENV> set\n");
      return(1);
    }
  }
  if ((ret = dbenv->open(dbenv, home,
			 DB_INIT_MPOOL | DB_INIT_CDB
			 | DB_CREATE | DB_USE_ENVIRON, 
			 0)) == 0) {
    *dbenvp = dbenv;
    dbenv->set_errfile(dbenv, LOGFILE);
    dbenv->set_errpfx(dbenv, "BerkeleyDB");
    return (0);
  }
  /* this goes to stdout and screws up z39.50 connections -- hangs them */
  /* dbenv->err(dbenv, ret, "Could not open DB environment: %s", home); */
  fprintf(LOGFILE,"Could not open DB environment: %s\n",home);
  (void)dbenv->close(dbenv, 0);
  return (ret);
}
开发者ID:snac-cooperative,项目名称:cheshire,代码行数:40,代码来源:DumpContDB.c

示例10: return

/*
 * env_init --
 *	Initialize the environment.
 */
DB_ENV * env_init( char *home, char *prefix, int cachesize)
{
    DB_ENV *dbenv;
    int ret;

    if ((ret = db_env_create(&dbenv, 0)) != 0) {
        dbenv->err(dbenv, ret, "db_env_create");
        return (NULL);
    }
    dbenv->set_errfile(dbenv, stderr);
    dbenv->set_errpfx(dbenv, prefix);
    if ((ret = dbenv->set_cachesize(dbenv, 0, cachesize, 0)) != 0) {
        dbenv->err(dbenv, ret, "DB_ENV->set_cachesize");
        return (NULL);
    }

    if ((ret = dbenv->open(dbenv, home, DB_CREATE | DB_INIT_MPOOL |
                           DB_INIT_TXN | DB_INIT_LOCK, 0)) != 0) {
        dbenv->err(dbenv, ret, "DB_ENV->open: %s", home);
        (void)dbenv->close(dbenv, 0);
        return (NULL);
    }
    return (dbenv);
}
开发者ID:msng4t,项目名称:network-etc,代码行数:28,代码来源:Bulk.cpp

示例11: main

///////////////////
//               //
// Main Function //
//               //
///////////////////
int main(int argc, char *argv[]) {

   /* Declare local vars */			/***********************************/
      DB_ENV *dbenv;				/* pointer to database environment */
      DB *dbp1;					/* pointer to 1st database         */
      DB *dbp2;					/* pointer to 2nd database         */
      DBT key1, data1;				/* Database key and data variables */
      DBT key2, data2;				/* Database key and data variables */
      int ret;					/* return code/message             */

   /* Creates the DB environment */
      if ((ret = db_env_create(&dbenv, 0)) != 0) {
         fprintf(stderr, "%s: %s\n", argv[0], db_strerror(ret));
         return(1);
      };
      dbenv->set_errfile(dbenv, stderr);
      dbenv->set_errpfx(dbenv, argv[0]);

   /* Set shared memory buffer pool cachesize: 5MB.            */
   /* Databases are in a subdirectory of the environment home. */
      if ((ret = dbenv->set_cachesize(dbenv, 0, 5 * 1024 * 1024, 0)) != 0) {
         dbenv->err(dbenv, ret, "set_cachesize");
         dbenv->close(dbenv, 0);
         return(1);
      };
      if ((ret = dbenv->set_data_dir(dbenv, MY_DBENV_DIR_DATA)) != 0) {
         dbenv->err(dbenv, ret, "set_data_dir: %s", MY_DBENV_DIR_DATA);
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Open the environment with full transactional support. */
      dbenv->open(
         dbenv, 
         MY_DBENV_DIR_HOME, 
         DB_CREATE 
         | DB_INIT_LOG 
         | DB_INIT_LOCK 
         | DB_INIT_MPOOL 
         | DB_INIT_TXN, 
         0
      );
      if (ret != 0) {
         dbenv->err(dbenv, ret, "environment open: %s", MY_DBENV_DIR_HOME);
         dbenv->close(dbenv, 0);
         return(1);
      };
      

   /* Create first Database handle */
      if ((ret = db_create(&dbp1, dbenv, 0)) != 0) {
         dbenv->err(dbenv, ret, "database create");
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Opens first database */
      if ((ret = dbp1->open(dbp1, NULL, MY_DB1_FILE, NULL, DB_BTREE, DB_CREATE, 0640)) != 0) {
         dbenv->err(dbenv, ret, "DB->open: %s", MY_DB1_FILE);
         dbp1->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return (ret);
      };

   /* Create second Database handle */
      if ((ret = db_create(&dbp2, dbenv, 0)) != 0) {
         dbenv->err(dbenv, ret, "database create");
         dbp1->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Opens second database */
      if ((ret = dbp2->open(dbp2, NULL, MY_DB2_FILE, NULL, DB_BTREE, DB_CREATE, 0640)) != 0) {
         dbenv->err(dbenv, ret, "DB->open: %s", MY_DB2_FILE);
         dbp1->close(dbp1, 0);
         dbp2->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return (ret);
      };

   /* Clears variables to avoid garbage */
      memset(&key1, 0, sizeof(key1));
      memset(&data1, 0, sizeof(data1));
      memset(&key2, 0, sizeof(key2));
      memset(&data2, 0, sizeof(data2));

   /* Preps data to be added to first database */
      key1.data = "fruit";
      key1.size = sizeof("fruit");
      data1.data = "apple";
      data1.size = sizeof("apple");

   /* pushes data into first database */
      if ((ret = dbp1->put(dbp1, NULL, &key1, &data1, 0)) == 0) {
//.........这里部分代码省略.........
开发者ID:syzdek,项目名称:spear,代码行数:101,代码来源:simple-bdbenv.c

示例12: getopt

int
main(int argc, char *const* argv)
{
	const char *progname = "dbxml_dump";
	DB_ENV *dbenv;
	XmlManager *xmlDb;
	u_int32_t cache;
	int ch, exitval, is_private, keyflag, nflag, ret, Rflag, rflag;
	char *home, *passwd;

	if ((ret = version_check(progname)) != 0)
		return (ret);

	dbenv = NULL;
	xmlDb = NULL;
	exitval = nflag = rflag = Rflag = 0;
	keyflag = 0;
	cache = MEGABYTE;
	is_private = 0;
	home = passwd = NULL;

	while ((ch = getopt(argc, argv, "f:h:NP:rRV")) != EOF)
		switch (ch) {
		case 'f':
			if (freopen(optarg, "wb", stdout) == NULL) {
				fprintf(stderr, "%s: %s: reopen: %s\n",
					progname, optarg, strerror(errno));
				return (EXIT_FAILURE);
			}
			break;
		case 'h':
			home = optarg;
			break;
		case 'N':
			nflag = 1;
			break;
		case 'P':
			passwd = strdup(optarg);
			memset(optarg, 0, strlen(optarg));
			if (passwd == NULL) {
				fprintf(stderr, "%s: strdup: %s\n",
					progname, strerror(errno));
				return (EXIT_FAILURE);
			}
			break;
		case 'R':
			Rflag = 1;
			/* DB_AGGRESSIVE requires DB_SALVAGE */
			/* FALLTHROUGH */
		case 'r':
			rflag = 1;
			break;
		case 'V':
			printf("%s\n", DbXml::dbxml_version(NULL, NULL, NULL));
			printf("%s\n", db_version(NULL, NULL, NULL));
			return (EXIT_SUCCESS);
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (argc != 1)
		return (usage());

	/* Handle possible interruptions. */
	SigBlock sb;

	/*
	 * Create an environment object and initialize it for error
	 * reporting.
	 */
	if ((ret = db_env_create(&dbenv, 0)) != 0) {
		fprintf(stderr,
			"%s: db_env_create: %s\n", progname, db_strerror(ret));
		goto err;
	}

	dbenv->set_errfile(dbenv, stderr);
	dbenv->set_errpfx(dbenv, progname);
	if (nflag) {
		if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
			dbenv->err(dbenv, ret, "set_flags: DB_NOLOCKING");
			goto err;
		}
		if ((ret = dbenv->set_flags(dbenv, DB_NOPANIC, 1)) != 0) {
			dbenv->err(dbenv, ret, "set_flags: DB_NOPANIC");
			goto err;
		}
	}
	if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
				     passwd, DB_ENCRYPT_AES)) != 0) {
		dbenv->err(dbenv, ret, "set_passwd");
		goto err;
	}

	/* Initialize the environment. */
	if ((ret = db_init(dbenv, home, rflag, cache, &is_private)) != 0) {
		dbenv->err(dbenv, ret, "db_init");
//.........这里部分代码省略.........
开发者ID:kanbang,项目名称:Colt,代码行数:101,代码来源:dbxml_dump.cpp

示例13: db_init

static int db_init(rpmdb rdb, const char * dbhome)
{
    DB_ENV *dbenv = NULL;
    int rc, xx;
    int retry_open = 2;
    int lockfd = -1;
    struct dbConfig_s * cfg = &rdb->cfg;
    /* This is our setup, thou shall not have other setups before us */
    uint32_t eflags = (DB_CREATE|DB_INIT_MPOOL|DB_INIT_CDB);

    if (rdb->db_dbenv != NULL) {
	rdb->db_opens++;
	return 0;
    } else {
	/* On first call, set backend description to something... */
	free(rdb->db_descr);
	rasprintf(&rdb->db_descr, "db%u", DB_VERSION_MAJOR);
    }

    /*
     * Both verify and rebuild are rather special, if for different reasons:
     * On rebuild we dont want to be affected by eg paniced environment, and
     * CDB only slows things down there. Verify is a quirky beast unlike
     * anything else in BDB, and does not like shared env or CDB.
     */
    if (rdb->db_flags & (RPMDB_FLAG_VERIFYONLY|RPMDB_FLAG_REBUILD)) {
	eflags |= DB_PRIVATE;
	eflags &= ~DB_INIT_CDB;
    }

    rc = db_env_create(&dbenv, 0);
    rc = dbapi_err(rdb, "db_env_create", rc, _debug);
    if (dbenv == NULL || rc)
	goto errxit;

    dbenv->set_alloc(dbenv, rmalloc, rrealloc, NULL);
    dbenv->set_errcall(dbenv, NULL);
    dbenv->set_errpfx(dbenv, _errpfx);
    dbenv->set_msgcall(dbenv, warnlog);

    /* 
     * These enable automatic stale lock removal. 
     * thread_count 8 is some kind of "magic minimum" value...
     */
    dbenv->set_thread_count(dbenv, 8);
    dbenv->set_isalive(dbenv, isalive);

    dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK,
	    (cfg->db_verbose & DB_VERB_DEADLOCK));
    dbenv->set_verbose(dbenv, DB_VERB_RECOVERY,
	    (cfg->db_verbose & DB_VERB_RECOVERY));
    dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR,
	    (cfg->db_verbose & DB_VERB_WAITSFOR));

    if (cfg->db_mmapsize) {
	xx = dbenv->set_mp_mmapsize(dbenv, cfg->db_mmapsize);
	xx = dbapi_err(rdb, "dbenv->set_mp_mmapsize", xx, _debug);
    }

    if (cfg->db_cachesize) {
	xx = dbenv->set_cachesize(dbenv, 0, cfg->db_cachesize, 0);
	xx = dbapi_err(rdb, "dbenv->set_cachesize", xx, _debug);
    }

    /*
     * Serialize shared environment open (and clock) via fcntl() lock.
     * Otherwise we can end up calling dbenv->failchk() while another
     * process is joining the environment, leading to transient
     * DB_RUNRECOVER errors. Also prevents races wrt removing the
     * environment (eg chrooted operation). Silently fall back to
     * private environment on failure to allow non-privileged queries
     * to "work", broken as it might be.
     */
    if (!(eflags & DB_PRIVATE)) {
	lockfd = serialize_env(dbhome);
	if (lockfd < 0) {
	    eflags |= DB_PRIVATE;
	    retry_open--;
	    rpmlog(RPMLOG_DEBUG, "serialize failed, using private dbenv\n");
	}
    }

    /*
     * Actually open the environment. Fall back to private environment
     * if we dont have permission to join/create shared environment or
     * system doesn't support it..
     */
    while (retry_open) {
	char *fstr = prDbiOpenFlags(eflags, 1);
	rpmlog(RPMLOG_DEBUG, "opening  db environment %s %s\n", dbhome, fstr);
	free(fstr);

	rc = (dbenv->open)(dbenv, dbhome, eflags, rdb->db_perms);
	if ((rc == EACCES || rc == EROFS) || (rc == EINVAL && errno == rc)) {
	    eflags |= DB_PRIVATE;
	    retry_open--;
	} else {
	    retry_open = 0;
	}
    }
//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:rpm,代码行数:101,代码来源:db3.c

示例14: strlen

int
wiredtiger_extension_init(WT_CONNECTION *connection, WT_CONFIG_ARG *config)
{
	/*
	 * List of the WT_DATA_SOURCE methods -- it's static so it breaks at
	 * compile-time should the structure changes underneath us.
	 */
	static WT_DATA_SOURCE wtds = {
		kvs_session_create,		/* session.create */
		NULL,				/* No session.compaction */
		kvs_session_drop,		/* session.drop */
		kvs_session_open_cursor,	/* session.open_cursor */
		kvs_session_rename,		/* session.rename */
		NULL,				/* No session.salvage */
		kvs_session_truncate,		/* session.truncate */
		NULL,				/* No range_truncate */
		kvs_session_verify,		/* session.verify */
		NULL,				/* session.checkpoint */
		kvs_terminate			/* termination */
	};
	DATA_SOURCE *ds;
	DB_ENV *dbenv;
	WT_EXTENSION_API *wt_api;
	size_t len;
	int ret = 0;
	const char *home;
	char *path;

	(void)config;				/* Unused parameters */

	ds = NULL;
	dbenv = NULL;
	path = NULL;
						/* Acquire the extension API */
	wt_api = connection->get_extension_api(connection);

	/* Allocate the local data-source structure. */
	if ((ds = calloc(1, sizeof(DATA_SOURCE))) == NULL)
		return (os_errno());
	ds->wt_api = wt_api;
						/* Configure the global lock */
	if ((ret = lock_init(wt_api, NULL, &ds->rwlock)) != 0)
		goto err;

	ds->wtds = wtds;			/* Configure the methods */

						/* Berkeley DB environment */
	if ((ret = db_env_create(&dbenv, 0)) != 0) {
		ESET(wt_api,
		    NULL, WT_ERROR, "db_env_create: %s", db_strerror(ret));
		goto err;
	}
	dbenv->set_errpfx(dbenv, "bdb");
	dbenv->set_errfile(dbenv, stderr);

	home = connection->get_home(connection);
	len = strlen(home) + 10;
	if ((path = malloc(len)) == NULL)
		goto err;
	(void)snprintf(path, len, "%s/KVS", home);
	if ((ret = dbenv->open(dbenv, path,
	    DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_PRIVATE, 0)) != 0) {
		ESET(wt_api,
		    NULL, WT_ERROR, "DbEnv.open: %s", db_strerror(ret));
		goto err;
	}
	ds->dbenv = dbenv;

	if ((ret =				/* Add the data source */
	    connection->add_data_source(
	    connection, "kvsbdb:", (WT_DATA_SOURCE *)ds, NULL)) != 0) {
		ESET(wt_api, NULL, ret, "WT_CONNECTION.add_data_source");
		goto err;
	}

	if (0) {
err:		if (dbenv != NULL)
			(void)dbenv->close(dbenv, 0);
		free(ds);
	}
	free(path);
	return (ret);
}
开发者ID:Machyne,项目名称:mongo,代码行数:83,代码来源:kvs_bdb.c

示例15: TestKeyExistErrorReturn

int TestKeyExistErrorReturn(CuTest *ct) {
	DB *pdbp;
	DB *sdbp;
	DB_ENV *dbenv;

	const char *sec_db_file = "secondary.db";
	const char *pri_db_file = "primary.db";
	const char *env_dir = "TESTDIR";
	int i;
	thread_t writer_threads[NUMWRITERS];
	u_int32_t db_flags, env_flags;

	pdbp = sdbp = NULL;
	dbenv = NULL;
	db_flags = DB_CREATE | DB_AUTO_COMMIT | DB_READ_UNCOMMITTED;
	env_flags = DB_CREATE | DB_RECOVER | DB_INIT_LOCK | DB_INIT_LOG |
	    DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD;

	TestEnvConfigTestSetup(ct);

	CuAssert(ct, "db_env_create", db_env_create(&dbenv, 0) == 0);

	dbenv->set_errfile(dbenv, stderr);
	dbenv->set_errpfx(dbenv, "TestKeyExistErrorReturn");

	/* Run deadlock detector on every lock conflict. */
	CuAssert(ct, "dbenv->set_lk_detect",
	    dbenv->set_lk_detect(dbenv, DB_LOCK_MINWRITE) == 0);

	CuAssert(ct, "dbenv->open",
	    dbenv->open(dbenv, env_dir, env_flags, 0) == 0);

	CuAssert(ct, "db_create", db_create(&pdbp, dbenv, 0) == 0);
	CuAssert(ct, "pdbp->open", pdbp->open(pdbp, NULL,
	    pri_db_file, NULL, DB_BTREE, db_flags, 0) == 0);

	CuAssert(ct, "db_create", db_create(&sdbp, dbenv, 0) == 0);
	CuAssert(ct, "sdbp->set_flags", sdbp->set_flags(sdbp,
	    DB_DUPSORT) == 0);
	CuAssert(ct, "sdbp->open", sdbp->open(sdbp, NULL, sec_db_file,
	    NULL, DB_BTREE, db_flags, 0) == 0);

	CuAssert(ct, "DB->associate", pdbp->associate(pdbp, NULL, sdbp,
	    assoc_callback, DB_AUTO_COMMIT) == 0);

	/* Initialize a mutex. Used to help provide thread ids. */
	(void)mutex_init(&thread_num_lock, NULL);

	for (i = 0; i < NUMWRITERS; ++i)
		(void)thread_create(&writer_threads[i], NULL,
		    writer_thread, (void *)pdbp);

	for (i = 0; i < NUMWRITERS; ++i)
		(void)thread_join(writer_threads[i], NULL);

	if (sdbp != NULL) 
		CuAssert(ct, "sdbp->close", sdbp->close(sdbp, 0) == 0);
	if (pdbp != NULL)
		CuAssert(ct, "pdbp->close", pdbp->close(pdbp, 0) == 0);
	if (dbenv != NULL)
		CuAssert(ct, "dbenv->close", dbenv->close(dbenv, 0) == 0);

	TestEnvConfigTestTeardown(ct);

	return (EXIT_SUCCESS);
}
开发者ID:tux-mind,项目名称:platform_external_bdb,代码行数:66,代码来源:TestKeyExistErrorReturn.c


注:本文中的DB_ENV::set_errpfx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。