diff --git a/sql/mysqld.cc b/sql/mysqld.cc --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -202,6 +202,14 @@ typedef fp_except fp_except_t; #define fcntl(X,Y,Z) 0 #endif +#ifndef EMBEDDED_LIBRARY +#define ALT_CHROOT +#endif + +#ifdef ALT_CHROOT +#include // For tzset(3) +#endif + inline void setup_fpu() { #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT) @@ -2228,12 +2236,24 @@ static void set_effective_user(struct passwd *user_info_arg) static void set_root(const char *path) { #if !defined(_WIN32) +#ifdef ALT_CHROOT + tzset(); +#endif + if (chroot(path) == -1) { sql_perror("chroot"); unireg_abort(1); } +#ifndef ALT_CHROOT my_setwd("/", MYF(0)); +#else + if (chdir("/") == -1) + { + sql_perror("chdir"); + unireg_abort(1); + } +#endif #endif } @@ -5674,6 +5694,10 @@ int mysqld_main(int argc, char **argv) /* We have enough space for fiddling with the argv, continue */ +#ifdef ALT_CHROOT + init_ssl(); + network_init(); +#endif check_data_home(mysql_real_data_home); if (my_setwd(mysql_real_data_home, opt_abort ? 0 : MYF(MY_WME)) && !opt_abort) unireg_abort(1); /* purecov: inspected */ @@ -5681,7 +5705,11 @@ int mysqld_main(int argc, char **argv) /* Atomic write initialization must be done as root */ my_init_atomic_write(); +#ifndef ALT_CHROOT if ((user_info= check_user(mysqld_user))) +#else + if (user_info) +#endif { #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) if (locked_in_memory) // getuid() == 0 here @@ -5707,8 +5735,10 @@ int mysqld_main(int argc, char **argv) if (init_server_components()) unireg_abort(1); +#ifndef ALT_CHROOT init_ssl(); network_init(); +#endif #ifdef WITH_WSREP // Recover and exit. @@ -8577,6 +8607,12 @@ static int get_options(int *argc_ptr, char ***argv_ptr) /* Set global MyISAM variables from delay_key_write_options */ fix_delay_key_write(0, 0, OPT_GLOBAL); +#ifdef ALT_CHROOT + if (fix_paths()) + return 1; + user_info = check_user(mysqld_user); +#endif + #ifndef EMBEDDED_LIBRARY if (mysqld_chroot) set_root(mysqld_chroot); @@ -8585,8 +8621,10 @@ static int get_options(int *argc_ptr, char ***argv_ptr) max_allowed_packet= global_system_variables.max_allowed_packet; net_buffer_length= global_system_variables.net_buffer_length; #endif +#ifndef ALT_CHROOT if (fix_paths()) return 1; +#endif /* Set some global variables from the global_system_variables