From: <ale...@us...> - 2012-03-01 08:38:06
|
Revision: 54068 http://firebird.svn.sourceforge.net/firebird/?rev=54068&view=rev Author: alexpeshkoff Date: 2012-03-01 08:37:55 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Fixed opening read-only databases on unix Modified Paths: -------------- firebird/trunk/builds/posix/Makefile.in firebird/trunk/src/jrd/os/posix/unix.cpp Modified: firebird/trunk/builds/posix/Makefile.in =================================================================== --- firebird/trunk/builds/posix/Makefile.in 2012-03-01 04:50:12 UTC (rev 54067) +++ firebird/trunk/builds/posix/Makefile.in 2012-03-01 08:37:55 UTC (rev 54068) @@ -232,6 +232,7 @@ help.fdb: $(BLD_ROOT)/misc/help.gbak $(GBAK) -MODE read_only -R $< $@ + $(CHMOD) 0444 $@ $(SECURITY_FDB): security.fdb -$(RM) $@ Modified: firebird/trunk/src/jrd/os/posix/unix.cpp =================================================================== --- firebird/trunk/src/jrd/os/posix/unix.cpp 2012-03-01 04:50:12 UTC (rev 54067) +++ firebird/trunk/src/jrd/os/posix/unix.cpp 2012-03-01 08:37:55 UTC (rev 54068) @@ -634,6 +634,20 @@ 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 @@ 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)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |