fix db_init after dropping privs

This commit is contained in:
Ron Pedde
2004-04-06 13:44:26 +00:00
parent c83f091dc7
commit 451b522dfd
4 changed files with 49 additions and 18 deletions

View File

@@ -182,19 +182,40 @@ void db_init_once(void) {
pthread_rwlock_init(&db_rwlock,NULL);
}
/*
* db_open
*
* Open the database, so we can drop privs
*/
int db_open(char *parameters) {
char db_path[PATH_MAX + 1];
if(pthread_once(&db_initlock,db_init_once))
return -1;
snprintf(db_path,sizeof(db_path),"%s/%s",parameters,"songs.gdb");
db_songs=gdbm_open(db_path,0,GDBM_WRCREAT | GDBM_SYNC | GDBM_NOLOCK,
0600,NULL);
if(!db_songs) {
DPRINTF(ERR_FATAL,"Could not open songs database (%s)\n",
db_path);
return -1;
}
return 0;
}
/*
* db_init
*
* Initialize the database. Parameter is the directory
* of the database files
*/
int db_init(char *parameters) {
int db_init(void) {
MP3FILE mp3file;
datum tmp_key,tmp_nextkey,song_data;
char db_path[PATH_MAX + 1];
if(pthread_once(&db_initlock,db_init_once))
return -1;
if((db_removed=rbinit(db_compare_rb_nodes,NULL)) == NULL) {
errno=ENOMEM;
@@ -203,15 +224,6 @@ int db_init(char *parameters) {
pl_register();
snprintf(db_path,sizeof(db_path),"%s/%s",parameters,"songs.gdb");
db_songs=gdbm_open(db_path,0,GDBM_WRCREAT | GDBM_SYNC | GDBM_NOLOCK,
0600,NULL);
if(!db_songs) {
DPRINTF(ERR_FATAL,"Could not open songs database (%s)\n",
gdbm_strerror(errno));
return -1;
}
db_version_no=1;
db_song_count=0;