Esempio n. 1
0
/* ---------------------- */
struct _cnid_db *cnid_dbd_open(struct cnid_open_args *args)
{
    CNID_bdb_private *db = NULL;
    struct _cnid_db *cdb = NULL;

    if ((cdb = cnid_dbd_new(args->cnid_args_vol)) == NULL) {
        LOG(log_error, logtype_cnid, "cnid_open: Unable to allocate memory for database");
        return NULL;
    }

    if ((db = (CNID_bdb_private *)calloc(1, sizeof(CNID_bdb_private))) == NULL) {
        LOG(log_error, logtype_cnid, "cnid_open: Unable to allocate memory for database");
        goto cnid_dbd_open_fail;
    }

    cdb->cnid_db_private = db;

    db->fd = -1;
    db->vol = args->cnid_args_vol;

    LOG(log_debug, logtype_cnid, "Finished initializing CNID dbd module for volume '%s'",
        args->cnid_args_vol->v_localname);

    return cdb;

cnid_dbd_open_fail:
    if (cdb != NULL)
        free(cdb);
    if (db != NULL)
        free(db);

    return NULL;
}
Esempio n. 2
0
/* ---------------------- */
struct _cnid_db *cnid_dbd_open(struct cnid_open_args *args)
{
    CNID_private *db = NULL;
    struct _cnid_db *cdb = NULL;

    if (!args->dir) {
        return NULL;
    }

    if ((cdb = cnid_dbd_new(args->dir)) == NULL) {
        LOG(log_error, logtype_cnid, "cnid_open: Unable to allocate memory for database");
        return NULL;
    }

    if ((db = (CNID_private *)calloc(1, sizeof(CNID_private))) == NULL) {
        LOG(log_error, logtype_cnid, "cnid_open: Unable to allocate memory for database");
        goto cnid_dbd_open_fail;
    }

    cdb->_private = db;

    /* We keep a copy of the directory in the db structure so that we can
       transparently reconnect later. */
    strcpy(db->db_dir, args->dir);
    db->magic = CNID_DB_MAGIC;
    db->fd = -1;
    db->cnidserver = strdup(args->cnidserver);
    db->cnidport = strdup(args->cnidport);

    LOG(log_debug, logtype_cnid, "cnid_dbd_open: Finished initializing cnid dbd module for volume '%s'", db->db_dir);

    return cdb;

cnid_dbd_open_fail:
    if (cdb != NULL) {
        if (cdb->volpath != NULL) {
            free(cdb->volpath);
        }
        free(cdb);
    }
    if (db != NULL)
        free(db);

    return NULL;
}