From 6224f6fd666cb9eb39fe5d4ccf7704fd86f4a86d Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Wed, 5 Jul 2023 16:21:01 +0600 Subject: [PATCH] fix --- source/philos_utils.c | 130 ++++++++++++++-------------- source/philos_utils.h | 1 + source/ubl-settings-resourcequota.c | 71 +++++++++------ source/ubl-settings-resourcequota.h | 1 + source/view_add.c | 58 +++++++------ 5 files changed, 142 insertions(+), 119 deletions(-) diff --git a/source/philos_utils.c b/source/philos_utils.c index da4db9e..28d5be8 100644 --- a/source/philos_utils.c +++ b/source/philos_utils.c @@ -14,84 +14,83 @@ void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char char* STR_TB = array_size_pow[3]; size_t length = strlen(str_find); if (strstr(str_find,"K") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, 0); - } - else { - philos_array_int_pars_to(array_size,0); - } + *array_size = philos_int_append(*array_size, &index, 0); str_find = yon_char_divide(str_find, length-1); str_find = yon_char_unite(str_find, " ", STR_KB, NULL); - if (index!=-1) { - index--; - } + index--; } else if (strstr(str_find,"M") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, 1); - } - else { - philos_array_int_pars_to(array_size,1); - } + *array_size = philos_int_append(*array_size, &index, 1); str_find = yon_char_divide(str_find, length-1); str_find = yon_char_unite(str_find," ", STR_MB, NULL); - if (index!=-1) { - index--; - } + index--; } else if (strstr(str_find,"G") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, 2); - } - else { - philos_array_int_pars_to(array_size,2); - } + *array_size = philos_int_append(*array_size, &index, 2); str_find = yon_char_divide(str_find, length-1); str_find = yon_char_unite(str_find," ", STR_GB, NULL); - if (index!=-1) { - index--; - } + index--; } else if (strstr(str_find,"T") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, 3); - } - else { - philos_array_int_pars_to(array_size,3); - } + *array_size = philos_int_append(*array_size, &index, 3); str_find = yon_char_divide(str_find, length-1); str_find = yon_char_unite(str_find," ", STR_TB, NULL); - if (index!=-1) { - index--; - } + index--; } else if (strstr(str_find,"%%") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, -1); - } - else { - philos_array_int_pars_to(array_size,-1); - } + *array_size = philos_int_append(*array_size, &index, -1); str_find = yon_char_divide(str_find, length-1); - if (index!=-1) { - index--; - } + index--; } else if (strstr(str_find,"-") != NULL) { - if (index!=-1) { - *array_size = philos_int_append(*array_size, &index, -1); - } - else { - philos_array_int_pars_to(array_size,-1); - } - if (index!=-1) { - index--; - } + *array_size = philos_int_append(*array_size, &index, -1); + index--; + } + +} +void philos_set_pow_size_memory_device(char* str_find, int** array_size,int index, char** array_size_pow) { + char* STR_KB = array_size_pow[0]; + char* STR_MB = array_size_pow[1]; + char* STR_GB = array_size_pow[2]; + char* STR_TB = array_size_pow[3]; + size_t length = strlen(str_find); + if (strstr(str_find,"K") != NULL) { + (*array_size)[index] = 0; + str_find = yon_char_divide(str_find, length-1); + str_find = yon_char_unite(str_find, " ", STR_KB, NULL); + index--; + } + else if (strstr(str_find,"M") != NULL) { + (*array_size)[index] = 1; + str_find = yon_char_divide(str_find, length-1); + str_find = yon_char_unite(str_find," ", STR_MB, NULL); + index--; + } + else if (strstr(str_find,"G") != NULL) { + (*array_size)[index] = 2; + str_find = yon_char_divide(str_find, length-1); + str_find = yon_char_unite(str_find," ", STR_GB, NULL); + index--; + } + else if (strstr(str_find,"T") != NULL) { + (*array_size)[index] = 3; + str_find = yon_char_divide(str_find, length-1); + + str_find = yon_char_unite(str_find," ", STR_TB, NULL); + index--; + } + else if (strstr(str_find,"%%") != NULL) { + (*array_size)[index] = -1; + str_find = yon_char_divide(str_find, length-1); + index--; + } + else if (strstr(str_find,"-") != NULL) { + (*array_size)[index] = -1; + index--; } } - void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index) { char* simv_del_array[10] = {"K","M","G","T","k","m","g","t"," ","%"}; for (size_t i = 0; i < 10; i++) { @@ -324,8 +323,11 @@ char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_m else if (pow_size_memory== -1) { return yon_char_unite(str_key, str_value, "%" ,NULL); } + else if (pow_size_memory== -3) { + return yon_char_new("-"); + } else { - return yon_char_unite(str_key, str_value, "-" ,NULL); + return yon_char_new("-"); } } @@ -398,7 +400,7 @@ char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* if (disk && size && array_io && array_io_pow_size) { int index_find = 0; for (int index = 0; index < size; index++) { - if (array_io_pow_size[index] >= 0 && array_io[index]>= 0) { + if (array_io_pow_size[index] >= 0 && array_io[index]>= 0 && !strstr(disk[index], "-")) { char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", array_io[index], array_io_pow_size[index]); if (!strstr(num_and_pow_size, "-")) { cmd_new = yon_char_unite(cmd_new, @@ -532,15 +534,11 @@ void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config, int fl } if ((bool_read == 0 && bool_write == 0 && index_find != -1)) { - ptr_disk = yon_char_parsed_shrink(ptr_disk,&size, index_find); - size++; - _config->i_o_limit_read_size = remove_element_int_array(_config->i_o_limit_read_size,&size, index_find); - size++; - _config->i_o_limit_write_size = remove_element_int_array(_config->i_o_limit_write_size,&size, index_find); - size++; - _config->i_o_limit_read = remove_element_int_array(_config->i_o_limit_read,&size, index_find); - size++; - _config->i_o_limit_write = remove_element_int_array(_config->i_o_limit_write,&size, index_find); + ptr_disk[index_find] = yon_char_new("-"); + _config->i_o_limit_read_size[index_find] = -3; + _config->i_o_limit_write_size[index_find] = -3; + _config->i_o_limit_read[index_find] = -3; + _config->i_o_limit_write[index_find] = -3; } } if (flag_check_array == 0) { diff --git a/source/philos_utils.h b/source/philos_utils.h index b7e680e..61e2786 100644 --- a/source/philos_utils.h +++ b/source/philos_utils.h @@ -82,6 +82,7 @@ void philos_split_size_memory(char* str_value, int* size, char* pow_memory); char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory); char** philos_str_split(char *parameters, int *size, char *divider); void philos_array_str_copy(char*** source, char*** copy); +void philos_set_pow_size_memory_device(char* str_find, int** array_size,int index, char** array_size_pow); void philos_array_int_copy(int** source, int** copy); char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data); char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size, char** disk, int size); diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index a815d45..349b069 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -366,15 +366,13 @@ void init_cfg_array(int index) { index_n2 = 0; main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (index + 1) * sizeof(int*)); main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (index + 1) * sizeof(int*)); - main_config.disk_read = yon_remalloc(main_config.disk_read, (index + 1) * sizeof(char**)); main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (index + 1) * sizeof(int*)); main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_write_size, (index + 1) * sizeof(int*)); main_config.disk_write = yon_remalloc(main_config.disk_write, (index + 1) * sizeof(char**)); - + main_config.disk_read = yon_remalloc(main_config.disk_read, (index + 1) * sizeof(char**)); philos_array_int_copy(&main_config.i_o_limit_read[index], &array_limit); philos_array_int_copy(&main_config.i_o_limit_read_size[index], &array_limit); yon_char_parsed_copy(&main_config.disk_read[index], &array_disk); - philos_array_int_copy(&main_config.i_o_limit_write[index], &array_limit); philos_array_int_copy(&main_config.i_o_limit_write_size[index], &array_limit); yon_char_parsed_copy(&main_config.disk_write[index], &array_disk); @@ -469,6 +467,22 @@ void str_split_value(char* values, int index) { } +void write_value_and_null_config(int index_n1, int* index_n2, char* key_find, char* str_disk) { + char* array_disk = NULL; + if (strstr(key_find, "IOReadBandwidthMax")!=NULL) { + array_disk = main_config.disk_write[index_n1][*index_n2]; + if (strcmp(array_disk, str_disk)!=0 && strcmp(array_disk, "-")!=0) { + (*index_n2)++; + } + } + else if (strstr(key_find, "IOWriteBandwidthMax")!=NULL) { + array_disk = main_config.disk_read[index_n1][*index_n2]; + if (strcmp(array_disk, str_disk)!=0 && strcmp(array_disk, "-")!=0) { + (*index_n2)++; + } + } +} + void get_param_io_limit(char** arr_values, int index_start, int size, int index_n1, char *key_find) { int* array_limit = NULL; char** array_disk = NULL; @@ -496,10 +510,10 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_ if (strstr(arr_values[i], key_find)!=NULL) { // Найден ключ в массив char* disk = yon_char_divide_search(yon_char_new(value), " ", -1); - philos_array_char_pars_to(&array_disk, disk); - index_n2--; - philos_set_pow_size_memory(yon_char_new(value), &array_limit_size, -1, array_size_pow); - set_size_memory_integer(yon_char_new(value), &array_limit, -1); + write_value_and_null_config(index_n1,&index_n2,key_find, disk); + array_disk[index_n2] = yon_char_new(disk); + philos_set_pow_size_memory_device(yon_char_new(value), &array_limit_size, index_n2, array_size_pow); + set_size_memory_integer_device(yon_char_new(value), &array_limit, index_n2); flag_parsed = 1; index_n2++; } @@ -512,10 +526,10 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_ } else if (flag_parsed == 1) { char* disk = yon_char_divide_search(yon_char_new(arr_values[i]), " ", -1); - philos_array_char_pars_to(&array_disk, disk); - index_n2--; - philos_set_pow_size_memory(yon_char_new(arr_values[i]), &array_limit_size, -1, array_size_pow); - set_size_memory_integer(yon_char_new(arr_values[i]), &array_limit, -1); + write_value_and_null_config(index_n1,&index_n2,key_find, disk); + array_disk[index_n2] = yon_char_new(disk); + philos_set_pow_size_memory_device(yon_char_new(arr_values[i]), &array_limit_size, index_n2, array_size_pow); + set_size_memory_integer_device(yon_char_new(arr_values[i]), &array_limit, index_n2); index_n2++; } else if (flag_exit == 1) { @@ -556,23 +570,29 @@ void set_size_memory_integer(char* str_find, int** array_data, int index) { } } if (strstr(str_find, "-")==NULL) { - if (index!=-1) { - *array_data = philos_int_append(*array_data, &index, atoi(str_find)); - } - else { - philos_array_int_pars_to(array_data,atoi(str_find)); - } + *array_data = philos_int_append(*array_data, &index, atoi(str_find)); } else { - if (index!=-1) { - *array_data = philos_int_append(*array_data, &index, -1); - } - else { - philos_array_int_pars_to(array_data,atoi(str_find)); - } + *array_data = philos_int_append(*array_data, &index, -1); } - +} +void set_size_memory_integer_device(char* str_find, int** array_data, int index) { + if (strstr(str_find, " ")) { + yon_char_divide_search(str_find, " ", -1); + } + char* simv_del_array[9] = {"K","M","G","T","k","m","g","t","%"}; + for (size_t i = 0; i < 9; i++) { + if (strstr(str_find, simv_del_array[i])) { + str_find = yon_char_divide_search(str_find, simv_del_array[i], -1); + } + } + if (strstr(str_find, "-")==NULL) { + (*array_data)[index] = atoi(str_find); + } + else { + (*array_data)[index] = -1; + } } void main_cbx_2_event() { @@ -612,7 +632,6 @@ void tree_view_select(GtkWidget *self, main_window *widgets) { void tree_view_add(int index) { main_config.type_quota = yon_char_parsed_append(main_config.type_quota, &main_config.size_tree_view, add_get_quota_object()); - main_config.size_tree_view--; main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &main_config.size_tree_view, add_get_select_device_to_level_2()); main_config.size_tree_view--; main_config.soft_raw_limit = philos_int_append(main_config.soft_raw_limit, &main_config.size_tree_view, add_get_soft()); @@ -1311,8 +1330,8 @@ int main(int argc, char *argv[]){ yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel); if (getuid()!=0) { - yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); load_system_cfg(); + yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); } else { yon_ubl_status_box_render(LOAD_LOCAL_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index 5d5e725..135b7b7 100755 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -199,6 +199,7 @@ void load_global_cfg(); void template_load_cfg(char *cmd); int template_format_str_save(char* source_set_cmd, char* source_remove_cmd); void str_split_value(char *values, int index); +void set_size_memory_integer_device(char* str_find, int** array_data, int index); void set_size_memory_integer(char* str_find, int** array_data, int index); void set_size_memory_integer_char(char* str_find, char*** array_data, int index); void set_pow_size_memory(char* str_find, int** array_size, int index); diff --git a/source/view_add.c b/source/view_add.c index 9ffadd3..80b16b1 100644 --- a/source/view_add.c +++ b/source/view_add.c @@ -179,53 +179,57 @@ char* add_get_select_device_to_level_2() { } int** add_get_read_device() { - obj_add_config.i_o_limit_read = philos_int_append(obj_add_config.i_o_limit_read,&obj_add_config.size_read, -2); - obj_add_config.size_read--; + int start_index = obj_add_config.size_read; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ + obj_add_config.i_o_limit_read = philos_int_append(obj_add_config.i_o_limit_read, &obj_add_config.size_read, -3); + } + obj_add_config.i_o_limit_read = philos_int_append(obj_add_config.i_o_limit_read, &obj_add_config.size_read, -2); + obj_add_config.size_read = start_index; return &obj_add_config.i_o_limit_read; } int** add_get_read_device_size_pow() { - obj_add_config.i_o_limit_read_size = philos_int_append(obj_add_config.i_o_limit_read_size,&obj_add_config.size_read, -2); - obj_add_config.size_read--; + int start_index = obj_add_config.size_read; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ + obj_add_config.i_o_limit_read_size = philos_int_append(obj_add_config.i_o_limit_read_size, &obj_add_config.size_read, -3); + } + obj_add_config.i_o_limit_read_size = philos_int_append(obj_add_config.i_o_limit_read_size, &obj_add_config.size_read, -2); + obj_add_config.size_read = start_index; return &obj_add_config.i_o_limit_read_size; } int** add_get_write_device() { + int start_index = obj_add_config.size_write; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ + obj_add_config.i_o_limit_write = philos_int_append(obj_add_config.i_o_limit_write, &obj_add_config.size_write, -3); + } obj_add_config.i_o_limit_write = philos_int_append(obj_add_config.i_o_limit_write, &obj_add_config.size_write, -2); - obj_add_config.size_write--; + obj_add_config.size_write = start_index; return &obj_add_config.i_o_limit_write; } int** add_get_write_device_size_pow() { - obj_add_config.i_o_limit_write_size = philos_int_append(obj_add_config.i_o_limit_write_size,&obj_add_config.size_write, -2); - obj_add_config.size_write--; + int start_index = obj_add_config.size_write; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ + obj_add_config.i_o_limit_write_size = philos_int_append(obj_add_config.i_o_limit_write_size, &obj_add_config.size_write, -3); + } + obj_add_config.i_o_limit_write_size = philos_int_append(obj_add_config.i_o_limit_write_size, &obj_add_config.size_write, -2); + obj_add_config.size_write = start_index; return &obj_add_config.i_o_limit_write_size; } char*** add_get_select_read_device() { - int flag = 0; - if (obj_add_config.size_read == 0) { + int start_index = obj_add_config.size_read; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ obj_add_config.disk_read = yon_char_parsed_append(obj_add_config.disk_read,&obj_add_config.size_read, "-"); - flag = 1; - } - obj_add_config.disk_read = yon_char_parsed_append(obj_add_config.disk_read,&obj_add_config.size_read, NULL); - if (flag == 1) { - obj_add_config.size_read-=2; - } - else { - obj_add_config.size_read-=1; } + obj_add_config.disk_read = yon_char_parsed_append(obj_add_config.disk_read, &obj_add_config.size_read, NULL); + obj_add_config.size_read = start_index; return &obj_add_config.disk_read; } char*** add_get_select_write_device() { - int flag = 0; - if (obj_add_config.size_read == 0) { + int start_index = obj_add_config.size_write; + for (int index = start_index;index< (get_device_cfg()->size_disk*2);index++){ obj_add_config.disk_write = yon_char_parsed_append(obj_add_config.disk_write,&obj_add_config.size_write, "-"); - flag = 1; - } - obj_add_config.disk_write = yon_char_parsed_append(obj_add_config.disk_write,&obj_add_config.size_write, NULL); - if (flag == 1) { - obj_add_config.size_write-=2; - } - else { - obj_add_config.size_write-=1; } + obj_add_config.disk_write = yon_char_parsed_append(obj_add_config.disk_write, &obj_add_config.size_write, NULL); + obj_add_config.size_write = start_index; return &obj_add_config.disk_write; }