[LCP]Berkeley DB Woes

Matthew Vanecek linux4us at earthlink.net
Thu Aug 2 12:31:44 UTC 2001


On 31 Jul 2001 20:23:35 +0930, David Lloyd wrote:
> 
> I can't get this to work:
> 
> 
> #include <stdio.h>
> #include <errno.h>
> 
> #include <db.h>
> 
> int main(int argc, char *argv[]) {
> 	DB *dbp;
> 
> 	DBT key;
> 	DBT data;
> 
> 	DBC *dbc;
> 
> 	int t_ret, ret;
> 
> /* Now we do some initialisation tasks */
> 
> 	memset(&key, 0, sizeof(key));
> 	memset(&data, 0, sizeof(data));
> 
> 
> /* First we create the actual database */
> 
> 	if ((ret=db_create(&dbp, NULL, 0) != 0)) {
> 		fprintf(stderr, "vote: %s\n", db_strerror(ret));
> 	}
> 
> /* Now we'll open it */
> 
> 	if ((ret=dbp->open(dbp, "vote.dbm", "vote", DB_HASH, DB_CREATE, 0664)
> != 0)) {
> 		dbp->err(dbp, ret, "vote->db_open:");
> 		goto err;
> 	}
> 
> /* Now we'll start to store some values */
> 
> 	key.data="author";
> 	key.size=sizeof("author");
> 	data.data="David Lloyd";
> 	data.size=sizeof("David Lloyd");
> 
> 	if ((ret=dbp->put(dbp, NULL, &key, &data, 0) != 0)) {
> 		dbp->err(dbp, ret, "vote->put:");
> 		goto err;
> 	} else {
> 		printf("Key: %s and Data: %s\n", (char *)key.data, (char *)data.data);
> 	}
> 
> /* Now we'll deliberately crash the get function */
> 
> 	key.data="foo";
> 	key.size=sizeof("foo");
> 
> 	if ((ret=dbp->get(dbp, NULL, &key, &data, 0) != 0)) {
> 		switch(ret) {
> 			case DB_NOTFOUND:
> 				dbp->err(dbp, ret, "vote->get: NOT FOUND ");
> 				break;
> 
> 			case EINVAL:
> 				dbp->err(dbp, ret, "vote->get: EINVAL ");
> 				goto err;
> 
> 			default:
> 				dbp->err(dbp, ret, "vote->get: %d", ret);
> 				goto err;
> 		}
> 	}
> 
> /* Close the database and exit gracefully */
> err:
> 	if ((t_ret=dbp->close(dbp, 0) != 0) && (ret == 0)) {
> 		ret=t_ret;
> 	}
> 
> 	return (ret);
> }
> 
> Making this and running it returns:
> 
> (computer output)
> vote->get: 1: Operation not permitted
> 
> However, vote.dbm is able to be read by the user and group and I can't
> see what's wrong.
> 
> (I'm on RH 7.1)
> 
> DSL

Are you using db1 or db3?  A return of 1 is expected for DB->get() in
db1 when there's a not-found condition.  Perhaps this is a bug in db3?

I wonder if any Debian/SuSe/etc users can reproduce this?  I have RH
7.1, too, but I downloaded/compiled db3 my own self, so I got the
original stuffs, and still get David's error.

What happens if you create the dbm as 0666?

-- 
Matthew Vanecek
perl -e 'print
$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
********************************************************************************
For 93 million miles, there is nothing between the sun and my shadow
except me.
I'm always getting in the way of something...




More information about the linuxCprogramming mailing list