dbTalk Databases Forums  

segmentation fault with db->open()

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss segmentation fault with db->open() in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Aydin Buluc
 
Posts: n/a

Default segmentation fault with db->open() - 11-05-2006 , 09:55 PM






Hi all,
I am new to Berkeley DB and I tried to get the getting_started example
running as the first task. However it keeps giving segmentation faults
right after the call to db->open() is made. Here is how I compile and
run:

cc -O -c gettingstarted_common.c
cc -O -c example_database_load.c
cc -L $HOME/db-4.5.20/build_unix/.libs/ -o example_database_load
gettingstarted_common.o example_database_load.o -ldb-4.5
env LD_LIBRARY_PATH="$HOME/db-4.5.20/build_unix/.libs"
../example_database_load


I suspected the example first and ran a much much simpler one. Still
gives me seg. faults, the simpler example is like the following:

#include "db.h"

#define DATABASE "access.db"

int
main()
{
DB *dbp;
DBT key, data;
int ret, t_ret;
/* Create the database handle and open the underlying database. */
fprintf (stderr,"test 1");
if ((ret = db_create(&dbp, NULL, 0)) != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}
fprintf(stderr,"test 2");
if ((ret = dbp->open(dbp,NULL, DATABASE, NULL, DB_BTREE,
DB_CREATE, 0664)) != 0) {
dbp->err(dbp, ret, "%s", DATABASE);
goto err;
}
fprintf(stderr,"test 3");

....
}


That never achieves to print "test 3"

I suspect the libraries but I don't know how to approach the problem.

Any suggestions would be extremely useful.

Thanks a lot.

-- Aydin


Reply With Quote
  #2  
Old   
Philip Guenther
 
Posts: n/a

Default Re: segmentation fault with db->open() - 11-11-2006 , 08:03 PM






On Nov 5, 8:55 pm, "Aydin Buluc" <aydinbu... (AT) gmail (DOT) com> wrote:
....
Quote:
cc -O -c gettingstarted_common.c
cc -O -c example_database_load.c
cc -L $HOME/db-4.5.20/build_unix/.libs/ -o example_database_load
You may need to pass a -I option to the compiler so that it finds the
db.h include for the db-4.5.20 library instead of one included with
your system. Given how the DB structure handle changes between
versions, that could _easily_ explain your problem.


....
Quote:
I suspected the example first and ran a much much simpler one. Still
gives me seg. faults, the simpler example is like the following:

#include "db.h"

#define DATABASE "access.db"

int
main()
{
DB *dbp;
DBT key, data;
int ret, t_ret;
/* Create the database handle and open the underlying database. */
fprintf (stderr,"test 1");
if ((ret = db_create(&dbp, NULL, 0)) != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}
fprintf(stderr,"test 2");
if ((ret = dbp->open(dbp,NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
dbp->err(dbp, ret, "%s", DATABASE);
goto err;
}
fprintf(stderr,"test 3");

....

}
That never achieves to print "test 3"
That code, replacing the "..." with a call to dbp->close(dbp, 0), works
just fine for me. Do the segmentation violations occurs when the
access.db file does *NOT* exist when you run the program? If not (they
only occur when the access.db file exist), then I would guess that
you're not called dbp->close() as needed. Since you're not using
transactions, failure to close the database correctly before exiting
may leave the file in a state that causes later attempts to operate on
it to crash.


Philip Guenther



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.