Merge pull request 'Fixed quota saving and editng' (#72) from YanTheKaller/ubl-settings-resourcequota:master into master

Reviewed-on: #72
master v2.35
Dmitry Razumov 1 month ago
commit eb0ede883c

@ -72,8 +72,9 @@ void on_quota_configuration_update(GtkWidget *, quota_window *window){
char *read_devices = "";
dictionary *dict;
for_dictionaries(dict,window->devices){
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->read)
if (!strstr(yon_dictionary_get_data(dict,device_limits*)->read," 0 "))
device_limits *limits = yon_dictionary_get_data(dict,device_limits*);
if (dict->data&&limits->read)
if (!strstr(limits->read," 0 "))
read_devices = yon_char_unite(read_devices,"IOReadBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,",",NULL);
}
if (read_devices[strlen(read_devices)-1]==',') read_devices[strlen(read_devices)-1]='\0';
@ -83,8 +84,9 @@ void on_quota_configuration_update(GtkWidget *, quota_window *window){
char *write_limit = "";
char *write_devices = "";
for_dictionaries(dict,window->devices){
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write)
if (!strstr(yon_dictionary_get_data(dict,device_limits*)->write," 0 "))
device_limits *limits = yon_dictionary_get_data(dict,device_limits*);
if (dict->data&&limits->write)
if (!strstr(limits->write," 0 "))
write_devices = yon_char_unite(write_devices,"IOWriteBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,",",NULL);
}
if (write_devices[strlen(write_devices)-1]==',') write_devices[strlen(write_devices)-1]='\0';
@ -260,10 +262,10 @@ void on_device_set(GtkWidget *self, quota_window *window){
}
char *value_str = yon_char_from_long(value);
char *full_str = yon_char_unite(value_str,yon_size_get_mod(gtk_combo_box_get_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo))),NULL);
if (!yon_char_is_empty(limits->read)) free(limits->read);
limits->read=full_str;
if (!yon_char_is_empty(limits->write)) free(limits->write);
limits->write=full_str;
} else {
limits->read=NULL;
limits->write=NULL;
}
}
}
@ -279,9 +281,17 @@ void on_device_current_changed(GtkWidget *, quota_window *window){
char *read = limits->read;
char *write = limits->write;
if (!yon_char_is_empty(read)) {
int size_mult = yon_get_size_get_from_letter(read[strlen(read)-1]);
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<size_mult+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)),hard_current_max);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_device_set),window);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),atoi(read));
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_device_set),window);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1);
switch (read[strlen(read)-1]){
default:
case 'K': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),0);
break;
case 'M': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),1);
@ -297,9 +307,17 @@ void on_device_current_changed(GtkWidget *, quota_window *window){
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),0);
}
if (!yon_char_is_empty(write)) {
int size_mult = yon_get_size_get_from_letter(write[strlen(write)-1]);
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<size_mult+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)),hard_current_max);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),atoi(write));
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1);
switch (write[strlen(write)-1]){
default:
case 'K': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),0);
break;
case 'M': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),1);
@ -340,26 +358,30 @@ void on_quotas_save(GtkWidget *self, dictionary *windows){
char *hard = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->HardRestrictionCombo))) : NULL;
char *paging = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin))),get_size_mod(GTK_COMBO_BOX(window->PagingLimitCombo))) : NULL;
char *cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->CpuLimitSpin))),"%") : NULL;
char *read_limit = NULL;
char *read_devices = NULL;
int size_read=0;
int size_write=0;
config_str limits_read = NULL;
config_str limits_write = NULL;
dictionary *dict;
for_dictionaries(dict,window->devices){
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->read)
read_devices = yon_char_unite(read_devices?read_devices:"","",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,"\n",NULL);
device_limits *limit = yon_dictionary_get_data(dict,device_limits*);
if (limit&&limit->read){
char *temp = yon_char_unite(dict->key," ",limit->read,NULL);
yon_char_parsed_add_or_create_if_exists(limits_read,&size_read,temp);
free(temp);
}
if (limit&&limit->write){
char *temp = yon_char_unite(dict->key," ",limit->write,NULL);
yon_char_parsed_add_or_create_if_exists(limits_write,&size_write,temp);
free(temp);
}
}
if (!yon_char_is_empty(read_devices)&&read_devices[strlen(read_devices)-1]=='\n') read_devices[strlen(read_devices)-1]='\0';
read_limit = yon_char_unite(read_limit?read_limit:"",read_devices,NULL);
char *write_limit = NULL;
char *write_devices = NULL;
for_dictionaries(dict,window->devices){
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write)
write_devices = yon_char_unite(write_devices?write_devices:"","",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,"\n",NULL);
}
if (!yon_char_is_empty(write_devices)&&write_devices[strlen(write_devices)-1]=='\n') write_devices[strlen(write_devices)-1]='\0';
write_limit = yon_char_unite(write_limit?write_limit:"",write_devices,NULL);
gtk_list_store_append(main_config.list,&iter);
gtk_list_store_set(main_config.list,&iter,0,type,1,target,2,soft,3,hard,4,paging,5,cpu,6,read_limit,7,write_limit,8,string,-1);
gtk_list_store_set(main_config.list,&iter,0,type,1,target,2,soft,3,hard,4,paging,5,cpu,6,yon_char_parsed_to_string(limits_read,size_read,"\n"),7,yon_char_parsed_to_string(limits_write,size_write,"\n"),8,string,-1);
yon_char_parsed_free(limits_read,size_read);
yon_char_parsed_free(limits_write,size_write);
yon_config_register(CGROUP_QUOTA((char*)target),CGROUP_QUOTA_comd((char*)target),yon_char_new((char*)string));
on_subwindow_close(self);
yon_ubl_status_box_render(SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
@ -704,66 +726,15 @@ void on_filters_opened(GtkWidget *, main_window *widgets) {
}
void on_add_open(GtkWidget *, main_window *widgets){
GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path);
quota_window *window = g_malloc0(sizeof(quota_window));
window->Window = yon_gtk_builder_get_widget(builder,"QuotasWindow");
window->TitleLabel = yon_gtk_builder_get_widget(builder,"TitleLabel");
window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
window->BlockUiBox = yon_gtk_builder_get_widget(builder,"BlockUiBox");
window->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
window->AddQuotaTargetBox = yon_gtk_builder_get_widget(builder,"AddQuotaTargetBox");
window->EditQuotaTargetBox = yon_gtk_builder_get_widget(builder,"EditQuotaTargetBox");
window->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
window->TargetLabel = yon_gtk_builder_get_widget(builder,"TargetLabel");
window->SoftRestrictionCheck = yon_gtk_builder_get_widget(builder,"SoftRestrictionCheck");
window->SoftRestrictionSpin = yon_gtk_builder_get_widget(builder,"SoftRestrictionSpin");
window->SoftRestrictionCombo = yon_gtk_builder_get_widget(builder,"SoftRestrictionCombo");
window->HardRestrictionCheck = yon_gtk_builder_get_widget(builder,"HardRestrictionCheck");
window->HardRestrictionSpin = yon_gtk_builder_get_widget(builder,"HardRestrictionSpin");
window->HardRestrictionCombo = yon_gtk_builder_get_widget(builder,"HardRestrictionCombo");
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder,"PagingLimitCheck");
window->PagingLimitSpin = yon_gtk_builder_get_widget(builder,"PagingLimitSpin");
window->PagingLimitCombo = yon_gtk_builder_get_widget(builder,"PagingLimitCombo");
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder,"CpuLimitCheck");
window->CpuLimitSpin = yon_gtk_builder_get_widget(builder,"CpuLimitSpin");
window->DeviceLimitCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitCombo");
window->DeviceLimitReadCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCheck");
window->DeviceLimitReadSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitReadSpin");
window->DeviceLimitReadCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCombo");
window->DeviceLimitWriteCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCheck");
window->DeviceLimitWriteSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteSpin");
window->DeviceLimitWriteCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCombo");
window->ApplyChangesButton = yon_gtk_builder_get_widget(builder,"ApplyChangesButton");
window->ManualInputEntry = yon_gtk_builder_get_widget(builder,"ManualInputEntry");
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
window->devices = NULL;
quota_window *window = yon_quota_window_new();
gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
dictionary *windows = NULL;
yon_dictionary_add_or_create_if_exists_with_data(windows,"window",window);
yon_dictionary_add_or_create_if_exists_with_data(windows,"widgets",widgets);
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_quotas_save),windows);
g_signal_connect(G_OBJECT(window->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)),main_config.avaliable_ram);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->HardRestrictionSpin)),main_config.avaliable_ram);
@ -772,82 +743,6 @@ void on_add_open(GtkWidget *, main_window *widgets){
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)),main_config.avaliable_ram);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)),main_config.avaliable_ram);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(on_device_current_changed),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->TargetCombo),"changed",G_CALLBACK(on_target_check_chosen),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"change-value",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitReadSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->CpuLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitReadCheck);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitWriteCheck);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->ManualInputEntry),"activate",G_CALLBACK(on_quota_manual_input),window);
g_signal_connect(G_OBJECT(window->ManualInputEntry),"focus-out-event",G_CALLBACK(on_quota_manual_input_focus),window);
yon_get_devices(window);
dictionary *dict;
for_dictionaries(dict,window->devices){
char *temp = yon_char_new(yon_dictionary_get_data(dict,device_limits*)->device_name);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key,temp);
}
main_config.users = yon_ubl_get_all_users(&main_config.users_size);
main_config.processes = yon_config_load(get_processes_command,&main_config.processes_size);
main_config.slices = yon_config_load(get_slices_command,&main_config.slices_size);
for(int i=0;i<main_config.users_size;i++){
yon_char_remove_last_symbol(main_config.users[i],'\n');
}
for(int i=0;i<main_config.processes_size;i++){
yon_char_remove_last_symbol(main_config.processes[i],'\n');
}
for(int i=0;i<main_config.slices_size;i++){
yon_char_remove_last_symbol(main_config.slices[i],'\n');
}
for (int i=0; i<main_config.users_size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
}
gtk_widget_show(window->Window);
}
@ -963,274 +858,327 @@ void yon_widget_set_sensitive(GtkComboBox *toggle, GtkWidget *target){
}
}
void on_edit_open(GtkWidget *, main_window *widgets){
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
GtkTreeIter iter;
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){
char *type;
char *target;
char *soft;
char *hard;
char *swap;
char *cpu;
char *read;
char *write;
int soft_size=-1;
int hard_size=-1;
int swap_size=-1;
gtk_tree_model_get(model,&iter,0,&type,1,&target,2,&soft,3,&hard,4,&swap,5,&cpu,6,&read,7,&write,-1);
if (soft&&strcmp(soft,"")!=0){
soft_size = yon_get_size_request_from_letter(soft[strlen(soft)-1]);
soft[strlen(soft)-1]='\0';
}
if (hard&&strcmp(hard,"")!=0){
hard_size=yon_get_size_request_from_letter(hard[strlen(hard)-1]);
hard[strlen(hard)-1]='\0';
}
if (swap&&strcmp(swap,"")!=0){
swap_size=yon_get_size_request_from_letter(swap[strlen(swap)-1]);
swap[strlen(swap)-1]='\0';
}
void on_manual_edit(GtkWidget *, quota_window *window){
yon_quota_update(window);
}
quota_window *yon_quota_window_new(){
GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path);
quota_window *window = g_malloc0(sizeof(quota_window));
window->Window = yon_gtk_builder_get_widget(builder,"QuotasWindow");
window->TitleLabel = yon_gtk_builder_get_widget(builder,"TitleLabel");
window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
window->BlockUiBox = yon_gtk_builder_get_widget(builder,"BlockUiBox");
window->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
window->AddQuotaTargetBox = yon_gtk_builder_get_widget(builder,"AddQuotaTargetBox");
window->EditQuotaTargetBox = yon_gtk_builder_get_widget(builder,"EditQuotaTargetBox");
window->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
window->TargetLabel = yon_gtk_builder_get_widget(builder,"TargetLabel");
window->TypeLabel = yon_gtk_builder_get_widget(builder,"TypeLabel");
window->SoftRestrictionCheck = yon_gtk_builder_get_widget(builder,"SoftRestrictionCheck");
window->SoftRestrictionSpin = yon_gtk_builder_get_widget(builder,"SoftRestrictionSpin");
window->SoftRestrictionCombo = yon_gtk_builder_get_widget(builder,"SoftRestrictionCombo");
window->HardRestrictionCheck = yon_gtk_builder_get_widget(builder,"HardRestrictionCheck");
window->HardRestrictionSpin = yon_gtk_builder_get_widget(builder,"HardRestrictionSpin");
window->HardRestrictionCombo = yon_gtk_builder_get_widget(builder,"HardRestrictionCombo");
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder,"PagingLimitCheck");
window->PagingLimitSpin = yon_gtk_builder_get_widget(builder,"PagingLimitSpin");
window->PagingLimitCombo = yon_gtk_builder_get_widget(builder,"PagingLimitCombo");
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder,"CpuLimitCheck");
window->CpuLimitSpin = yon_gtk_builder_get_widget(builder,"CpuLimitSpin");
window->DeviceLimitCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitCombo");
window->DeviceLimitReadCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCheck");
window->DeviceLimitReadSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitReadSpin");
window->DeviceLimitReadCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCombo");
window->DeviceLimitWriteCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCheck");
window->DeviceLimitWriteSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteSpin");
window->DeviceLimitWriteCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCombo");
window->ApplyChangesButton = yon_gtk_builder_get_widget(builder,"ApplyChangesButton");
window->ManualInputEntry = yon_gtk_builder_get_widget(builder,"ManualInputEntry");
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
window->devices = NULL;
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->CpuLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitReadCheck);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitWriteCheck);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitReadSpin);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitCombo),0);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(on_device_current_changed),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->TargetCombo),"changed",G_CALLBACK(on_target_check_chosen),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"change-value",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window);
g_signal_connect(G_OBJECT(window->ManualInputEntry),"changed",G_CALLBACK(on_manual_edit),window);
yon_get_devices(window);
window->devices=window->devices->first;
dictionary *dict;
for_dictionaries(dict,window->devices){
char *temp = yon_char_new(yon_dictionary_get_data(dict,device_limits*)->device_name);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key,temp);
}
main_config.users = yon_ubl_get_all_users(&main_config.users_size);
main_config.processes = yon_config_load(get_processes_command,&main_config.processes_size);
main_config.slices = yon_config_load(get_slices_command,&main_config.slices_size);
for(int i=0;i<main_config.users_size;i++){
yon_char_remove_last_symbol(main_config.users[i],'\n');
}
for(int i=0;i<main_config.processes_size;i++){
yon_char_remove_last_symbol(main_config.processes[i],'\n');
}
for(int i=0;i<main_config.slices_size;i++){
yon_char_remove_last_symbol(main_config.slices[i],'\n');
}
for (int i=0; i<main_config.users_size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
}
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
gtk_widget_show(window->Window);
return window;
}
void yon_quota_update(quota_window *window){
g_signal_handlers_block_by_func(G_OBJECT(window->SoftRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->SoftRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->HardRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->HardRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->PagingLimitSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->PagingLimitCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->CpuLimitSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->SoftRestrictionCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->HardRestrictionCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->PagingLimitCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->CpuLimitCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_block_by_func(G_OBJECT(window->TargetTypeCombo),G_CALLBACK(on_quota_target_type_changed),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_device_set),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_device_set),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadCombo),G_CALLBACK(on_device_set),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteCheck),G_CALLBACK(on_device_set),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window);
g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_device_set),window);
char *parameter = yon_char_new(gtk_entry_get_text(GTK_ENTRY(window->ManualInputEntry)));
int size;
config_str parsed = yon_char_parse(parameter,&size,",");
long soft_restr=0;
long hard_restr=0;
long swap_restr=0;
int cpu=0;
for (int i=0;i<size;i++){
int parsed_size=0;
config_str parsed_parameter = yon_char_parse(parsed[i],&parsed_size,"=");
if (parsed_size){
if (!strcmp(parsed_parameter[0],"MemoryHigh")&&parsed_size>1){
soft_restr = atol(parsed_parameter[1]);
int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]);
if (size_mult==-1) size_mult=0;
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<size_mult+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)),hard_current_max);
if (soft_restr) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),soft_restr);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),size_mult);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
} else {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),0);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),0);
GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path);
quota_window *window = g_malloc0(sizeof(quota_window));
window->Window = yon_gtk_builder_get_widget(builder,"QuotasWindow");
window->TitleLabel = yon_gtk_builder_get_widget(builder,"TitleLabel");
window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox");
window->BlockUiBox = yon_gtk_builder_get_widget(builder,"BlockUiBox");
window->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
window->AddQuotaTargetBox = yon_gtk_builder_get_widget(builder,"AddQuotaTargetBox");
window->EditQuotaTargetBox = yon_gtk_builder_get_widget(builder,"EditQuotaTargetBox");
window->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
window->TargetLabel = yon_gtk_builder_get_widget(builder,"TargetLabel");
window->TypeLabel = yon_gtk_builder_get_widget(builder,"TypeLabel");
window->SoftRestrictionCheck = yon_gtk_builder_get_widget(builder,"SoftRestrictionCheck");
window->SoftRestrictionSpin = yon_gtk_builder_get_widget(builder,"SoftRestrictionSpin");
window->SoftRestrictionCombo = yon_gtk_builder_get_widget(builder,"SoftRestrictionCombo");
window->HardRestrictionCheck = yon_gtk_builder_get_widget(builder,"HardRestrictionCheck");
window->HardRestrictionSpin = yon_gtk_builder_get_widget(builder,"HardRestrictionSpin");
window->HardRestrictionCombo = yon_gtk_builder_get_widget(builder,"HardRestrictionCombo");
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder,"PagingLimitCheck");
window->PagingLimitSpin = yon_gtk_builder_get_widget(builder,"PagingLimitSpin");
window->PagingLimitCombo = yon_gtk_builder_get_widget(builder,"PagingLimitCombo");
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder,"CpuLimitCheck");
window->CpuLimitSpin = yon_gtk_builder_get_widget(builder,"CpuLimitSpin");
window->DeviceLimitCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitCombo");
window->DeviceLimitReadCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCheck");
window->DeviceLimitReadSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitReadSpin");
window->DeviceLimitReadCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCombo");
window->DeviceLimitWriteCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCheck");
window->DeviceLimitWriteSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteSpin");
window->DeviceLimitWriteCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCombo");
window->ApplyChangesButton = yon_gtk_builder_get_widget(builder,"ApplyChangesButton");
window->ManualInputEntry = yon_gtk_builder_get_widget(builder,"ManualInputEntry");
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
window->devices = NULL;
gtk_window_set_title(GTK_WINDOW(window->Window),EDITING_LABEL);
gtk_label_set_text(GTK_LABEL(window->TitleLabel),EDITING_LABEL);
gtk_widget_show(window->EditQuotaTargetBox);
gtk_widget_hide(window->AddQuotaTargetBox);
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
dictionary *windows = NULL;
yon_dictionary_add_or_create_if_exists_with_data(windows,"window",window);
yon_dictionary_add_or_create_if_exists_with_data(windows,"widgets",widgets);
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_quotas_edit),windows);
g_signal_connect(G_OBJECT(window->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window);
long swap_current_max = main_config.avaliable_swap;
for (int i=0;i<swap_size+1;i++)
swap_current_max=swap_current_max/1024;
long soft_current_max = main_config.avaliable_ram;
for (int i=0;i<soft_size+1;i++)
soft_current_max=soft_current_max/1024;
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<hard_size+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)),soft_current_max);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->HardRestrictionSpin)),hard_current_max);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->PagingLimitSpin)),swap_current_max);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->CpuLimitSpin)),main_config.cores*100);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->CpuLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitReadCheck);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_widget_set_sensitive),window->DeviceLimitWriteCheck);
yon_get_devices(window);
dictionary *dict;
gtk_widget_set_sensitive(window->BlockUiBox,1);
gtk_label_set_text(GTK_LABEL(window->TypeLabel),type);
gtk_label_set_text(GTK_LABEL(window->TargetLabel),target);
int read_size=0;
config_str read_parsed = yon_char_parse(read,&read_size,"\n");
int write_size=0;
config_str write_parsed = yon_char_parse(write,&write_size,"\n");
for_dictionaries(dict,window->devices){
char *temp = yon_char_new(yon_dictionary_get_data(dict,device_limits*)->device_name);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key,temp);
if (read_parsed)
for (int i=0; i<read_size;i++){
char *read_limit = yon_char_new(read_parsed[i]);
char *read_cur = yon_char_divide_search(read_limit," ",-1);
if (strstr(temp,read_cur)){
if(!dict->data){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
((device_limits*)dict->data)->read=read_limit;
}
}
else{
char *read_limit = yon_char_new(read);
char *read_cur = yon_char_divide_search(read_limit," ",-1);
if (strstr(temp,read_cur)){
if(!dict->data){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
((device_limits*)dict->data)->read=read_limit;
} else if (!strcmp(parsed_parameter[0],"MemoryMax")&&parsed_size>1){
hard_restr = atol(parsed_parameter[1]);
int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]);
if (size_mult==-1) size_mult=0;
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<size_mult+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->HardRestrictionSpin)),hard_current_max);
if (hard_restr){
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),hard_restr);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),size_mult);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
} else {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),0);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),0);
}
}
if (write_parsed)
for (int i=0; i<write_size;i++){
char *write_limit = yon_char_new(write_parsed[i]);
char *write_cur = yon_char_divide_search(write_limit," ",-1);
if (strstr(temp,write_cur)){
if(!dict->data){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
((device_limits*)dict->data)->write=write_limit;
}
} else if (!strcmp(parsed_parameter[0],"MemorySwapMax")&&parsed_size>1){
swap_restr = atol(parsed_parameter[1]);
int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]);
if (size_mult==-1) size_mult=0;
long hard_current_max = main_config.avaliable_swap;
for (int i=0;i<size_mult+1;i++)
hard_current_max=hard_current_max/1024;
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->PagingLimitSpin)),hard_current_max);
if (swap_restr){
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),swap_restr);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),size_mult);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1);
} else {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),0);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),0);
}
else{
char *write_limit = yon_char_new(write);
char *write_cur = yon_char_divide_search(write_limit," ",-1);
if (strstr(temp,write_cur)){
if(!dict->data){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
((device_limits*)dict->data)->write=write_limit;
} else if (!strcmp(parsed_parameter[0],"CPUQuota")&&parsed_size>1){
cpu = atoi(parsed_parameter[1]);
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->CpuLimitSpin)),main_config.cores*100);
if (cpu){
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),cpu);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1);
} else {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),0);
}
} else if (!strcmp(parsed_parameter[0],"IOReadBandwidthMax")&&parsed_size>1){
char *device = yon_char_divide_search(parsed_parameter[1]," ",-1);
dictionary *dict = yon_dictionary_get(&window->devices,device);
if (dict){
device_limits *limit = yon_dictionary_get_data(dict,device_limits*);
limit->read = yon_char_new(parsed_parameter[1]);
}
} else if (!strcmp(parsed_parameter[0],"IOWriteBandwidthMax")&&parsed_size>1){
char *device = yon_char_divide_search(parsed_parameter[1]," ",-1);
dictionary *dict = yon_dictionary_get(&window->devices,device);
if (dict){
device_limits *limit = yon_dictionary_get_data(dict,device_limits*);
limit->write = yon_char_new(parsed_parameter[1]);
}
}
}
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitReadSpin);
window->devices=window->devices->first;
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitCombo),0);
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(on_device_current_changed),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"value-changed",G_CALLBACK(on_device_set),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_device_set),window);
if (((device_limits*)window->devices->data)->read&&strcmp(((device_limits*)window->devices->data)->read,"")!=0){
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1);
char *rd = ((device_limits*)window->devices->data)->read;
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),yon_get_size_request_from_letter(rd[strlen(rd)-1]));
rd[strlen(rd)-1]='\0';
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),strtol(((device_limits*)window->devices->data)->read,NULL,10));
}
else ((device_limits*)window->devices->data)->read=NULL;
if (((device_limits*)window->devices->data)->write&&strcmp(((device_limits*)window->devices->data)->write,"")!=0){
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1);
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),yon_get_size_request_from_letter(((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]));
((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]='\0';
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),strtol(((device_limits*)window->devices->data)->write,NULL,10));
} else ((device_limits*)window->devices->data)->write=NULL;
if (soft&&strcmp(soft,"")!=0) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(soft,NULL,10));
gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),soft_size);
}
if (hard&&strcmp(hard,"")!=0) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),strtol(hard,NULL,10));
gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),hard_size);
}
if (cpu&&strcmp(cpu,"")!=0) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),strtol(cpu,NULL,10));
}
if (swap&&strcmp(swap,"")!=0) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),strtol(swap,NULL,10));
gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),swap_size);
}
for (int i=0; i<main_config.users_size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
}
}
if (!soft_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),0);
if (!hard_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),0);
if (!swap_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),0);
if (!cpu) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),0);
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
g_signal_handlers_unblock_by_func(G_OBJECT(window->SoftRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->SoftRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->HardRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->HardRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->PagingLimitSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->PagingLimitCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->CpuLimitSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->SoftRestrictionCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->HardRestrictionCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->PagingLimitCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->CpuLimitCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteCheck),G_CALLBACK(on_quota_configuration_update),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->TargetTypeCombo),G_CALLBACK(on_quota_target_type_changed),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_device_set),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_device_set),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadCombo),G_CALLBACK(on_device_set),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteCheck),G_CALLBACK(on_device_set),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window);
g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_device_set),window);
}
g_signal_connect(G_OBJECT(window->TargetCombo),"changed",G_CALLBACK(on_target_check_chosen),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->SoftRestrictionCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->SoftRestrictionSpin);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->HardRestrictionCombo);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->HardRestrictionSpin);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"change-value",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitCombo);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitSpin);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitReadCombo);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteCombo);
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
gtk_widget_show(window->Window);
}
void on_edit_open(GtkWidget *, main_window *widgets){
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
GtkTreeIter iter;
if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)) return;
quota_window *window = yon_quota_window_new();
gtk_widget_set_sensitive(window->BlockUiBox,1);
char *target, *type;
gtk_tree_model_get(model,&iter,0,&type,1,&target,-1);
gtk_label_set_text(GTK_LABEL(window->TypeLabel),type);
gtk_label_set_text(GTK_LABEL(window->TargetLabel),target);
gtk_window_set_title(GTK_WINDOW(window->Window),EDITING_LABEL);
gtk_label_set_text(GTK_LABEL(window->TitleLabel),EDITING_LABEL);
gtk_widget_show(window->EditQuotaTargetBox);
gtk_widget_hide(window->AddQuotaTargetBox);
char *parameter = config(CGROUP_QUOTA(target));
gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),parameter);
yon_quota_update(window);
dictionary *windows = NULL;
yon_dictionary_add_or_create_if_exists_with_data(windows,"window",window);
yon_dictionary_add_or_create_if_exists_with_data(windows,"widgets",widgets);
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_quotas_edit),windows);
}
gboolean on_dispatcher_update(GtkWidget *,main_window *widgets){

@ -225,3 +225,6 @@ void on_quota_configuration_update(GtkWidget *self, quota_window *window);
void on_device_limits_update(GtkWidget *, quota_window *window);
void yon_widget_set_sensitive(GtkComboBox *toggle, GtkWidget *target);
void on_device_set(GtkWidget *self, quota_window *window);
quota_window *yon_quota_window_new();
void yon_quota_update(quota_window *window);
void on_manual_edit(GtkWidget *, quota_window *window);
Loading…
Cancel
Save