On Wed, 10 Oct 2007, Joe Wilson wrote:
> > At Schrodinger, we added two functions to our version of sqlite3:
> >
> > /* The sqlite3 APIs to get file descriptors fo the open files */
> > int sqlite3_get_database_file_fd( sqlite3* sqlite3_db_ptr );
> > int sqlite3_get_journal_file_fd( sqlite3* sqlite3_db_ptr );
>
> Do your functions always just return the fd of the first database "main"?
>
Hi Joe.
I'm not sure what you mean by database "main", and I did not
write the functions.
The functions use the pager to access the file descriptors:
In pager.c:
int sqlite3pager_get_database_file_fd(Pager *pPager)
{
return sqlite3OsFileHandle(pPager->fd);
}
int sqlite3pager_get_journal_file_fd(Pager *pPager)
{
if ( !pPager->journalOpen )
return -1;
return sqlite3OsFileHandle(pPager->jfd);
}
In fds.c (file added by Schrodinger):
int sqlite3_get_database_file_fd( sqlite3* sqlite3_db_p )
{
Pager *pPager;
if ( !sqlite3_db_p || !sqlite3_db_p->aDb || !sqlite3_db_p->aDb[0].pBt)
return -1;
pPager = sqlite3BtreePager(sqlite3_db_p->aDb[0].pBt);
if ( !pPager )
return -1;
return sqlite3pager_get_database_file_fd(pPager);
}
int sqlite3_get_journal_file_fd( sqlite3* sqlite3_db_p )
{
Pager *pPager;
if ( !sqlite3_db_p || !sqlite3_db_p->aDb || !sqlite3_db_p->aDb[0].pBt)
return -1;
pPager = sqlite3BtreePager(sqlite3_db_p->aDb[0].pBt);
if ( !pPager )
return -1;
return sqlite3pager_get_journal_file_fd(pPager);
}
> SQLite3 now has this code in os_unix.c:
>
> #ifdef FD_CLOEXEC
> fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC);
> #endif
>
That's good to know. Our version (3.3.4, and later 3.4.0) did not
have this.
> Is that your only use for requiring the file descriptor?
Yes.
We set FD_CLOEXEC for the database fd when the database is opened,
and for the journal fd in the pthread_atfork handler.
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------