8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:40:38 +01:00

Fixed opening read-only databases on unix

This commit is contained in:
alexpeshkoff 2012-03-01 08:37:55 +00:00
parent 87cfc2f431
commit 6e6c7bcbcd
2 changed files with 16 additions and 2 deletions

View File

@ -232,6 +232,7 @@ $(HELP_FDB): help.fdb
help.fdb: $(BLD_ROOT)/misc/help.gbak
$(GBAK) -MODE read_only -R $< $@
$(CHMOD) 0444 $@
$(SECURITY_FDB): security.fdb
-$(RM) $@

View File

@ -634,6 +634,20 @@ jrd_file* PIO_open(Database* dbb,
Arg::Gds(isc_io_open_err) << Arg::Unix(errno));
}
readOnly = true;
}
else if (geteuid() == 0)
{
// root has too many rights - therefore artificially check for readonly file
struct stat st;
if (fstat(desc, &st) == 0)
{
readOnly = ((st.st_mode & 0222) == 0); // nobody has write permissions
}
}
if (readOnly)
{
// If this is the primary file, set Database flag to indicate that it is
// being opened ReadOnly. This flag will be used later to compare with
// the Header Page flag setting to make sure that the database is set ReadOnly.
@ -641,11 +655,10 @@ jrd_file* PIO_open(Database* dbb,
PageSpace* pageSpace = dbb->dbb_page_manager.findPageSpace(DB_PAGE_SPACE);
if (!pageSpace->file)
dbb->dbb_flags |= DBB_being_opened_read_only;
readOnly = true;
}
const bool shareMode = dbb->dbb_config->getSharedDatabase();
if (!lockDatabaseFile(desc, shareMode))
if (!lockDatabaseFile(desc, shareMode || readOnly))
{
ERR_post(Arg::Gds(isc_io_error) << Arg::Str("lock") << Arg::Str(file_name) <<
Arg::Gds(isc_io_open_err) << Arg::Unix(errno));