mirror of
https://github.com/owntone/owntone-server.git
synced 2025-07-16 12:21:59 -04:00
fix db_init after dropping privs
This commit is contained in:
parent
c83f091dc7
commit
451b522dfd
@ -182,19 +182,40 @@ void db_init_once(void) {
|
|||||||
pthread_rwlock_init(&db_rwlock,NULL);
|
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
|
* db_init
|
||||||
*
|
*
|
||||||
* Initialize the database. Parameter is the directory
|
* Initialize the database. Parameter is the directory
|
||||||
* of the database files
|
* of the database files
|
||||||
*/
|
*/
|
||||||
int db_init(char *parameters) {
|
int db_init(void) {
|
||||||
MP3FILE mp3file;
|
MP3FILE mp3file;
|
||||||
datum tmp_key,tmp_nextkey,song_data;
|
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) {
|
if((db_removed=rbinit(db_compare_rb_nodes,NULL)) == NULL) {
|
||||||
errno=ENOMEM;
|
errno=ENOMEM;
|
||||||
@ -203,15 +224,6 @@ int db_init(char *parameters) {
|
|||||||
|
|
||||||
pl_register();
|
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_version_no=1;
|
||||||
db_song_count=0;
|
db_song_count=0;
|
||||||
|
|
||||||
|
@ -75,7 +75,8 @@ pthread_once_t db_initlock=PTHREAD_ONCE_INIT;
|
|||||||
int db_start_initial_update(void);
|
int db_start_initial_update(void);
|
||||||
int db_end_initial_update(void);
|
int db_end_initial_update(void);
|
||||||
int db_is_empty(void);
|
int db_is_empty(void);
|
||||||
int db_init(char *parameters);
|
int db_open(char *parameters);
|
||||||
|
int db_init();
|
||||||
int db_deinit(void);
|
int db_deinit(void);
|
||||||
int db_version(void);
|
int db_version(void);
|
||||||
int db_add(MP3FILE *mp3file);
|
int db_add(MP3FILE *mp3file);
|
||||||
@ -114,13 +115,23 @@ void db_init_once(void) {
|
|||||||
pthread_rwlock_init(&db_rwlock,NULL);
|
pthread_rwlock_init(&db_rwlock,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* db_open
|
||||||
|
*
|
||||||
|
* We'll wait for db_init
|
||||||
|
*/
|
||||||
|
void db_open(char *parameters) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* db_init
|
* db_init
|
||||||
*
|
*
|
||||||
* Initialize the database. For the in-memory db
|
* Initialize the database. For the in-memory db
|
||||||
* the parameters are insignificant
|
* the parameters are insignificant
|
||||||
*/
|
*/
|
||||||
int db_init(char *parameters) {
|
int db_init(void) {
|
||||||
db_root.next=NULL;
|
db_root.next=NULL;
|
||||||
db_version_no=1;
|
db_version_no=1;
|
||||||
db_song_count=0;
|
db_song_count=0;
|
||||||
|
@ -29,7 +29,8 @@ typedef void* ENUMHANDLE;
|
|||||||
extern int db_start_initial_update(void);
|
extern int db_start_initial_update(void);
|
||||||
extern int db_end_initial_update(void);
|
extern int db_end_initial_update(void);
|
||||||
extern int db_is_empty(void);
|
extern int db_is_empty(void);
|
||||||
extern int db_init(char *parameters);
|
extern int db_open(char *parameters);
|
||||||
|
extern int db_init(void);
|
||||||
extern int db_deinit(void);
|
extern int db_deinit(void);
|
||||||
extern int db_version(void);
|
extern int db_version(void);
|
||||||
extern int db_add(MP3FILE *mp3file);
|
extern int db_add(MP3FILE *mp3file);
|
||||||
|
11
src/main.c
11
src/main.c
@ -472,13 +472,20 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((config.use_mdns) && (!parseonly)) {
|
if((config.use_mdns) && (!parseonly)) {
|
||||||
fprintf(stderr,"Starting rendezvous daemon\n");
|
fprintf(stderr,"Starting rendezvous daemon -- indexing "
|
||||||
|
"mp3 files... wait.\n");
|
||||||
if(rend_init(config.runas)) {
|
if(rend_init(config.runas)) {
|
||||||
perror("rend_init");
|
perror("rend_init");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(db_open(config.db_dir)) {
|
||||||
|
perror("db_open");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Drop privs here
|
// Drop privs here
|
||||||
if(drop_privs(config.runas)) {
|
if(drop_privs(config.runas)) {
|
||||||
perror("drop_privs");
|
perror("drop_privs");
|
||||||
@ -501,7 +508,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the database before starting */
|
/* Initialize the database before starting */
|
||||||
if(db_init(config.dbdir)) {
|
if(db_init()) {
|
||||||
perror("db_init");
|
perror("db_init");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user