From 044e5d773d5507a54b110082c1032e46c763229f Mon Sep 17 00:00:00 2001 From: elshad Date: Tue, 28 Jul 2015 02:16:54 +0500 Subject: [PATCH 1/2] add sql/mysqld.h --- sql/mysqld.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/mysqld.h b/sql/mysqld.h index 999ca48..fbed452 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -95,6 +95,7 @@ void my_init_signals(); bool gtid_server_init(); void gtid_server_cleanup(); const char *fixup_enforce_gtid_consistency_command_line(char *value_arg); +int is_filesystem_read_only(char const* path); extern "C" MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info; extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ; From fabb740e95cdf21e5cf9732e38250edfb758f03b Mon Sep 17 00:00:00 2001 From: elshad Date: Tue, 28 Jul 2015 02:17:23 +0500 Subject: [PATCH 2/2] add sql/mysqld.cc --- sql/mysqld.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f657c96..b302afb 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -21,6 +21,8 @@ #include #include #include +#include // this library will help us to detect file system status +#include #include #include @@ -4389,6 +4391,21 @@ static void test_lc_time_sz() } #endif//DBUG_OFF +// checks if file system is read-only +int is_filesystem_read_only(char const* name) { + if (access(name, W_OK) == -1) { + if (access(name, R_OK) == 0) { + return R_OK; // read only + } else if (access(name, F_OK) == 0) { + return F_OK; // file exists but have not any access + } else { + return -1; // file does not exist + } + } else { + return W_OK; // read/write + } +} + #ifdef _WIN32 int win_main(int argc, char **argv) #else @@ -4411,6 +4428,19 @@ int mysqld_main(int argc, char **argv) my_message_local(ERROR_LEVEL, "my_init() failed."); return 1; } + + // Get --datadir value to check if filesystem is read-only + for (int i = 1; i < argc; i++) { + if (strstr(argv[i], "--datadir")) { + std::string str(argv[i]); + char const* dataDirPath = str.substr(10, str.length()).c_str(); + if (is_filesystem_read_only(dataDirPath) == R_OK) { + my_message_local(ERROR_LEVEL, "File system (%s) is read-only", dataDirPath); + return 1; + } + break; + } + } #endif /* _WIN32 */ orig_argc= argc;