diff options
author | unknown <serg@serg.mylan> | 2004-09-07 15:18:53 +0200 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2004-09-07 15:18:53 +0200 |
commit | 77a86154880e0e4b8528f2363317c480dff62fe0 (patch) | |
tree | eb69e64fb069e7468a92e59eca620860f68aff61 /sql | |
parent | b5c6ac6a03efa7c56795a37f9b35a140e8b7af1d (diff) | |
parent | 6b1444d7ba70a286f3fc543ab5bc8927106f5638 (diff) | |
download | mariadb-git-77a86154880e0e4b8528f2363317c480dff62fe0.tar.gz |
merged
BitKeeper/etc/ignore:
auto-union
client/mysqlcheck.c:
Auto merged
myisammrg/myrg_open.c:
Auto merged
scripts/mysqld_safe.sh:
Auto merged
sql/sql_analyse.cc:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/log.cc | 34 | ||||
-rw-r--r-- | sql/mysqld.cc | 109 | ||||
-rw-r--r-- | sql/sql_analyse.cc | 7 | ||||
-rw-r--r-- | sql/sql_class.h | 21 | ||||
-rw-r--r-- | sql/sql_table.cc | 44 |
5 files changed, 116 insertions, 99 deletions
diff --git a/sql/log.cc b/sql/log.cc index 08c1b31ed0d..1a3807cbfe6 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1426,15 +1426,6 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", if (e.write(file)) goto err; } -#if MYSQL_VERSION_ID < 40100 - if (thd->variables.convert_set) - { - Query_log_event e(thd, "SET CHARACTER SET DEFAULT", 25, 0); - e.set_log_pos(this); - if (e.write(file)) - goto err; - } -#endif } /* @@ -1932,19 +1923,6 @@ void MYSQL_LOG::set_max_size(ulong max_size_arg) } -Disable_binlog::Disable_binlog(THD *thd_arg) : - thd(thd_arg), save_options(thd_arg->options) -{ - thd_arg->options&= ~OPTION_BIN_LOG; -} - - -Disable_binlog::~Disable_binlog() -{ - thd->options= save_options; -} - - /* Check if a string is a valid number @@ -2009,12 +1987,12 @@ void print_buffer_to_file(enum loglevel level, const char *buffer) localtime_r(&skr, &tm_tmp); start=&tm_tmp; fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n", - start->tm_year % 100, - start->tm_mon+1, - start->tm_mday, - start->tm_hour, - start->tm_min, - start->tm_sec, + start->tm_year % 100, + start->tm_mon+1, + start->tm_mday, + start->tm_hour, + start->tm_min, + start->tm_sec, (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? "WARNING" : "INFORMATION"), buffer); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 90b6d6319bf..d978069a823 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -327,6 +327,7 @@ const char *opt_date_time_formats[3]; char *language_ptr, *default_collation_name, *default_character_set_name; char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home; +struct passwd *user_info; char server_version[SERVER_VERSION_LENGTH]; char *mysqld_unix_port, *opt_mysql_tmpdir; char *my_bind_addr_str; @@ -1047,65 +1048,72 @@ static void set_ports() #ifndef EMBEDDED_LIBRARY /* Change to run as another user if started with --user */ -static void set_user(const char *user) +static struct passwd *check_user(const char *user) { #if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) - struct passwd *ent; + struct passwd *user_info; uid_t user_id= geteuid(); - // don't bother if we aren't superuser + // Don't bother if we aren't superuser if (user_id) { if (user) { - /* Don't give a warning, if real user is same as given with --user */ - struct passwd *user_info= getpwnam(user); + // Don't give a warning, if real user is same as given with --user + user_info= getpwnam(user); if ((!user_info || user_id != user_info->pw_uid) && global_system_variables.log_warnings) sql_print_warning( "One can only use the --user switch if running as root\n"); } - return; + return NULL; } if (!user) { if (!opt_bootstrap) { - fprintf(stderr,"Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n"); + sql_print_error("Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n"); unireg_abort(1); } - return; + return NULL; } if (!strcmp(user,"root")) - return; // Avoid problem with dynamic libraries + return NULL; // Avoid problem with dynamic libraries - uid_t uid; - if (!(ent = getpwnam(user))) + if (!(user_info= getpwnam(user))) { - // allow a numeric uid to be used + // Allow a numeric uid to be used const char *pos; - for (pos=user; my_isdigit(mysqld_charset,*pos); pos++) ; - if (*pos) // Not numeric id - { - fprintf(stderr,"Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n",user); - unireg_abort(1); - } - uid=atoi(user); // Use numberic uid + for (pos= user; my_isdigit(mysqld_charset,*pos); pos++) ; + if (*pos) // Not numeric id + goto err; + if (!(user_info= getpwuid(atoi(user)))) + goto err; + else + return user_info; } else - { + return user_info; + +err: + sql_print_error("Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n",user); +#endif + return NULL; +} + +static void set_user(const char *user, struct passwd *user_info) +{ +#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) + DBUG_ASSERT(user_info); #ifdef HAVE_INITGROUPS - initgroups((char*) user,ent->pw_gid); + initgroups((char*) user,user_info->pw_gid); #endif - if (setgid(ent->pw_gid) == -1) - { - sql_perror("setgid"); - unireg_abort(1); - } - uid=ent->pw_uid; + if (setgid(user_info->pw_gid) == -1) + { + sql_perror("setgid"); + unireg_abort(1); } - - if (setuid(uid) == -1) + if (setuid(user_info->pw_uid) == -1) { sql_perror("setuid"); unireg_abort(1); @@ -1113,6 +1121,25 @@ static void set_user(const char *user) #endif } + +static void set_effective_user(struct passwd *user_info) +{ +#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) + DBUG_ASSERT(user_info); + if (setegid(user_info->pw_gid) == -1) + { + sql_perror("setegid"); + unireg_abort(1); + } + if (seteuid(user_info->pw_uid) == -1) + { + sql_perror("seteuid"); + unireg_abort(1); + } +#endif +} + + /* Change root user if started with --chroot */ static void set_root(const char *path) @@ -1188,7 +1215,16 @@ static void server_init(void) unireg_abort(1); } } - set_user(mysqld_user); // Works also with mysqld_user==NULL + + if ((user_info= check_user(mysqld_user))) + { +#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) + if (locked_in_memory) // getuid() == 0 here + set_effective_user(user_info); + else +#endif + set_user(mysqld_user, user_info); + } #ifdef __NT__ /* create named pipe */ @@ -2619,18 +2655,25 @@ server."); dflt_key_cache= sql_key_cache; #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) - if (locked_in_memory && !geteuid()) + if (locked_in_memory && !getuid()) { + if (seteuid(0) == -1) + { // this should never happen + sql_perror("seteuid"); + unireg_abort(1); + } if (mlockall(MCL_CURRENT)) { if (global_system_variables.log_warnings) sql_print_warning("Failed to lock memory. Errno: %d\n",errno); locked_in_memory= 0; } + if (user_info) + set_user(mysqld_user, user_info); } -#else - locked_in_memory=0; + else #endif + locked_in_memory=0; ft_init_stopwords(); diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 3f75dadb6f0..1e0aebbc1ec 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -799,6 +799,13 @@ void field_real::get_opt_type(String *answer, if (min_arg >= 0) answer->append(" UNSIGNED"); } + else if (item->decimals == NOT_FIXED_DEC) + { + if (min_arg >= -FLT_MAX && max_arg <= FLT_MAX) + answer->append("FLOAT", 5); + else + answer->append("DOUBLE", 6); + } else { if (min_arg >= -FLT_MAX && max_arg <= FLT_MAX) diff --git a/sql/sql_class.h b/sql/sql_class.h index a8035cffd96..1c4a0af6f23 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1020,27 +1020,6 @@ public: #define SYSTEM_THREAD_SLAVE_SQL 4 /* - Disables binary logging for one thread, and resets it back to what it was - before being disabled. - Some functions (like the internal mysql_create_table() when it's called by - mysql_alter_table()) must NOT write to the binlog (binlogging is done at the - at a later stage of the command already, and must be, for locking reasons); - so we internally disable it temporarily by creating the Disable_binlog - object and reset the state by destroying the object (don't forget that! or - write code so that the object gets automatically destroyed when leaving a - block, see example in sql_table.cc). -*/ -class Disable_binlog { -private: - THD *thd; - ulong save_options; -public: - Disable_binlog(THD *thd_arg); - ~Disable_binlog(); -}; - - -/* Used to hold information about file and file structure in exchainge via non-DB file (...INTO OUTFILE..., ...LOAD DATA...) XXX: We never call destructor for objects of this class. diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a1760261f94..129d63ff529 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -29,7 +29,14 @@ #include <io.h> #endif -const char *primary_key_name= "PRIMARY"; +#define tmp_disable_binlog(A) \ + ulong save_options= (A)->options; \ + (A)->options&= ~OPTION_BIN_LOG; + +#define reenable_binlog(A) (A)->options= save_options; + +//extern HASH open_cache; // leftover from the merge. to be deleted +static const char *primary_key_name="PRIMARY"; static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end); static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end); @@ -1348,10 +1355,9 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, MYSQL_LOCK **lock) { TABLE tmp_table; // Used during 'create_field()' - TABLE *table; + TABLE *table= 0; tmp_table.table_name=0; uint select_field_count= items->elements; - Disable_binlog disable_binlog(thd); DBUG_ENTER("create_table_from_items"); /* Add selected items to field list */ @@ -1381,23 +1387,26 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, extra_fields->push_back(cr_field); } /* create and lock table */ - /* QQ: This should be done atomic ! */ - /* We don't log the statement, it will be logged later */ - if (mysql_create_table(thd,db,name,create_info,*extra_fields, - *keys,0,select_field_count)) - DBUG_RETURN(0); + /* QQ: create and open should be done atomic ! */ /* + We don't log the statement, it will be logged later. If this is a HEAP table, the automatic DELETE FROM which is written to the binlog when a HEAP table is opened for the first time since startup, must not be written: 1) it would be wrong (imagine we're in CREATE SELECT: we don't want to delete from it) 2) it would be written before the CREATE - TABLE, which is a wrong order. So we keep binary logging disabled. + TABLE, which is a wrong order. So we keep binary logging disabled when we + open_table(). */ - if (!(table=open_table(thd,db,name,name,(bool*) 0))) + tmp_disable_binlog(thd); + if (mysql_create_table(thd,db,name,create_info,*extra_fields, + *keys,0,select_field_count)) { - quick_rm_table(create_info->db_type,db,table_case_name(create_info,name)); - DBUG_RETURN(0); + if (!(table=open_table(thd,db,name,name,(bool*) 0))) + quick_rm_table(create_info->db_type,db,table_case_name(create_info,name)); } + reenable_binlog(thd); + if (!table) + DBUG_RETURN(0); table->reginfo.lock_type=TL_WRITE; if (!((*lock)=mysql_lock_tables(thd,&table,1))) { @@ -3018,11 +3027,12 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, else create_info->data_file_name=create_info->index_file_name=0; { - /* We don't log the statement, it will be logged later */ - Disable_binlog disable_binlog(thd); - if ((error=mysql_create_table(thd, new_db, tmp_name, - create_info, - create_list,key_list,1,0))) + /* We don't log the statement, it will be logged later. */ + tmp_disable_binlog(thd); + error= mysql_create_table(thd, new_db, tmp_name, + create_info,create_list,key_list,1,0); + reenable_binlog(thd); + if (error) DBUG_RETURN(error); } if (table->tmp_table) |