⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.cc

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻 CC
📖 第 1 页 / 共 2 页
字号:
/*  Open the logfile, read requested part of the log and send the info  to the client.  SYNOPSYS    Show_instance_log::execute()    net                 The network connection to the client.    connection_id       Client connection ID  DESCRIPTION    Send a table with the content of the log requested. The function also    deals with errro handling, to be verbose.  RETURN   ER_OFFSET_ERROR      We were requested to read negative number of bytes                        from the log   ER_NO_SUCH_LOG       The kind log being read is not enabled in the instance   ER_GUESS_LOGFILE     IM wasn't able to figure out the log placement, while                        it is enabled. Probably user should specify the path                        to the logfile explicitly.   ER_OPEN_LOGFILE      Cannot open the logfile   ER_READ_FILE         Cannot read the logfile   ER_OUT_OF_RESOURCES  We weren't able to allocate some resources*/int Show_instance_log::execute(struct st_net *net, ulong connection_id){  Buffer send_buff;  /* buffer for packets */  LIST name;  LIST *field_list;  NAME_WITH_LENGTH name_field;  uint position= 0;  /* create list of the fileds to be passed to send_fields */  name_field.name= (char*) "Log";  name_field.length= DEFAULT_FIELD_LENGTH;  name.data= &name_field;  field_list= list_add(NULL, &name);  if (!instance_name)    return ER_BAD_INSTANCE_NAME;  /* cannot read negative number of bytes */  if (offset > size)    return ER_OFFSET_ERROR;  send_fields(net, field_list);  {    Instance *instance;    const char *logpath;    File fd;    if ((instance= instance_map->find(instance_name,                                      strlen(instance_name))) == NULL)      goto err;    logpath= instance->options.logs[log_type];    /* Instance has no such log */    if (logpath == NULL)      return ER_NO_SUCH_LOG;    if (*logpath == '\0')      return ER_GUESS_LOGFILE;    if ((fd= my_open(logpath, O_RDONLY | O_BINARY,  MYF(MY_WME))) >= 0)    {      size_t buff_size;      int read_len;      /* calculate buffer size */      MY_STAT file_stat;      Buffer read_buff;      /* my_fstat doesn't use the flag parameter */      if (my_fstat(fd, &file_stat, MYF(0)))        goto err;      buff_size= (size - offset);      read_buff.reserve(0, buff_size);      /* read in one chunk */      read_len= (int)my_seek(fd, file_stat.st_size - size, MY_SEEK_SET, MYF(0));      if ((read_len= my_read(fd, (byte*) read_buff.buffer,                             buff_size, MYF(0))) < 0)        return ER_READ_FILE;      store_to_protocol_packet(&send_buff, read_buff.buffer,                               &position, read_len);      close(fd);    }    else      return ER_OPEN_LOGFILE;    if (my_net_write(net, send_buff.buffer, (uint) position))      goto err;  }  if (send_eof(net) ||  net_flush(net))    goto err;  return 0;err:  return ER_OUT_OF_RESOURCES;}/* implementation for Show_instance_log_files: */Show_instance_log_files::Show_instance_log_files              (Instance_map *instance_map_arg, const char *name, uint len)  :Command(instance_map_arg){  Instance *instance;  /* we make a search here, since we don't want to store the name */  if ((instance= instance_map->find(name, len)))    instance_name= instance->options.instance_name;  else    instance_name= NULL;}/*  The method sends a table with a list of log files  used by the instance.  SYNOPSYS    Show_instance_log_files::execute()    net               The network connection to the client.    connection_id     The ID of the client connection  RETURN    ER_BAD_INSTANCE_NAME  The instance name specified is not valid    ER_OUT_OF_RESOURCES   some error occured    0 - ok*/int Show_instance_log_files::execute(struct st_net *net, ulong connection_id){  Buffer send_buff;  /* buffer for packets */  LIST name, path, size;  LIST *field_list;  NAME_WITH_LENGTH name_field, path_field, size_field;  uint position= 0;  if (!instance_name)    return ER_BAD_INSTANCE_NAME;  /* create list of the fileds to be passed to send_fields */  name_field.name= (char*) "Logfile";  name_field.length= DEFAULT_FIELD_LENGTH;  name.data= &name_field;  path_field.name= (char*) "Path";  path_field.length= DEFAULT_FIELD_LENGTH;  path.data= &path_field;  size_field.name= (char*) "File size";  size_field.length= DEFAULT_FIELD_LENGTH;  size.data= &size_field;  field_list= list_add(NULL, &size);  field_list= list_add(field_list, &path);  field_list= list_add(field_list, &name);  send_fields(net, field_list);  Instance *instance;  if ((instance= instance_map->                 find(instance_name, strlen(instance_name))) == NULL)    goto err;  {    /*      We have alike structure in instance_options.cc. We use such to be able      to loop through the options, which we need to handle in some common way.    */    struct log_files_st    {      const char *name;      const char *value;    } logs[]=    {      {"ERROR LOG", instance->options.logs[IM_LOG_ERROR]},      {"GENERAL LOG", instance->options.logs[IM_LOG_GENERAL]},      {"SLOW LOG", instance->options.logs[IM_LOG_SLOW]},      {NULL, NULL}    };    struct log_files_st *log_files;    for (log_files= logs; log_files->name; log_files++)    {      if (log_files->value != NULL)      {        struct stat file_stat;        /*          Save some more space for the log file names. In fact all          we need is srtlen("GENERAL_LOG") + 1        */        enum { LOG_NAME_BUFFER_SIZE= 20 };        char buff[LOG_NAME_BUFFER_SIZE];        position= 0;        /* store the type of the log in the send buffer */        store_to_protocol_packet(&send_buff, log_files->name, &position);        if (stat(log_files->value, &file_stat))        {          store_to_protocol_packet(&send_buff, "", &position);          store_to_protocol_packet(&send_buff, (char*) "0", &position);        }        else if (MY_S_ISREG(file_stat.st_mode))        {          store_to_protocol_packet(&send_buff,                                   (char*) log_files->value,                                   &position);          int10_to_str(file_stat.st_size, buff, 10);          store_to_protocol_packet(&send_buff, (char*) buff, &position);        }        if (my_net_write(net, send_buff.buffer, (uint) position))          goto err;      }    }  }  if (send_eof(net) || net_flush(net))    goto err;  return 0;err:  return ER_OUT_OF_RESOURCES;}/* implementation for SET instance_name.option=option_value: */Set_option::Set_option(Instance_map *instance_map_arg,                       const char *name, uint len,                       const char *option_arg, uint option_len_arg,                       const char *option_value_arg, uint option_value_len_arg)  :Command(instance_map_arg){  Instance *instance;  /* we make a search here, since we don't want to store the name */  if ((instance= instance_map->find(name, len)))  {    instance_name= instance->options.instance_name;     /* add prefix for add_option */    if ((option_len_arg < MAX_OPTION_LEN - 1) ||        (option_value_len_arg < MAX_OPTION_LEN - 1))    {      strmake(option, option_arg, option_len_arg);      strmake(option_value, option_value_arg, option_value_len_arg);    }    else    {      option[0]= 0;      option_value[0]= 0;    }    instance_name_len= len;  }  else  {    instance_name= NULL;    instance_name_len= 0;  }}/*  The method sends a table with a list of log files  used by the instance.  SYNOPSYS    Set_option::correct_file()    skip     Skip the option, being searched while writing the result file.             That is, to delete it.  DESCRIPTION  Correct the option file. The "skip" option is used to remove the found  option.  RETURN    ER_OUT_OF_RESOURCES     out of resources    ER_ACCESS_OPTION_FILE   Cannot access the option file    0 - ok*/int Set_option::correct_file(int skip){  static const int mysys_to_im_error[]= { 0, ER_OUT_OF_RESOURCES,                                             ER_ACCESS_OPTION_FILE };  int error;  error= modify_defaults_file(Options::config_file, option,                              option_value, instance_name, skip);  DBUG_ASSERT(error >= 0 && error <= 2);  return mysys_to_im_error[error];}/*  The method sets an option in the the default config file (/etc/my.cnf).  SYNOPSYS    Set_option::do_command()    net               The network connection to the client.  RETURN    0 - ok    1 - error occured*/int Set_option::do_command(struct st_net *net){  int error;  /* we must hold the instance_map mutex while changing config file */  instance_map->lock();  error= correct_file(FALSE);  instance_map->unlock();  return error;}int Set_option::execute(struct st_net *net, ulong connection_id){  if (instance_name != NULL)  {    int val;    val= do_command(net);    if (val == 0)      net_send_ok(net, connection_id, NULL);    return val;  }  return ER_BAD_INSTANCE_NAME;}/* the only function from Unset_option we need to Implement */int Unset_option::do_command(struct st_net *net){  return correct_file(TRUE);}/* Implementation for Stop_instance: */Stop_instance::Stop_instance(Instance_map *instance_map_arg,                               const char *name, uint len)  :Command(instance_map_arg){  /* we make a search here, since we don't want to store the name */  if ((instance= instance_map->find(name, len)))    instance_name= instance->options.instance_name;}int Stop_instance::execute(struct st_net *net, ulong connection_id){  uint err_code;  if (instance == 0)    return ER_BAD_INSTANCE_NAME; /* haven't found an instance */  if (!(instance->options.nonguarded))    instance_map->guardian->stop_guard(instance);  if ((err_code= instance->stop()))    return err_code;  net_send_ok(net, connection_id, NULL);  return 0;}int Syntax_error::execute(struct st_net *net, ulong connection_id){  return ER_SYNTAX_ERROR;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -