Memory fixes; changes

pull/87/head
YanTheKaller 7 days ago
parent 30d5133a55
commit fe8d8b3192

@ -64,47 +64,72 @@ void on_quota_configuration_update(GtkWidget *, quota_window *window){
long hrd = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin));
long pgl = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin));
long cpu = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->CpuLimitSpin));
char *soft_limit = "";
char *hard_limit = "";
char *paging_limit = "";
char *cpu_limit = "";
char *soft_limit = NULL;
char *hard_limit = NULL;
char *paging_limit = NULL;
char *cpu_limit = NULL;
if (sft) soft_limit = yon_char_unite("MemoryHigh=",yon_char_from_long(sft),get_size_mod(GTK_COMBO_BOX(window->SoftRestrictionCombo)),NULL);
if (hrd) hard_limit = yon_char_unite("MemoryMax=",yon_char_from_long(hrd),get_size_mod(GTK_COMBO_BOX(window->HardRestrictionCombo)),NULL);
if (pgl) paging_limit = yon_char_unite("MemorySwapMax=",yon_char_from_long(pgl),get_size_mod(GTK_COMBO_BOX(window->PagingLimitCombo)),NULL);
if (cpu) cpu_limit = yon_char_unite("CPUQuota=",yon_char_from_long(cpu),"%",NULL);
char *read_limit = "";
char *read_devices = "";
char *read_devices = NULL;
dictionary *dict;
for_dictionaries(dict,window->devices){
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 (!strstr(limits->read," 0 ")) {
char *tmp = yon_char_unite(read_devices ? read_devices : "","IOReadBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",limits->read,",",NULL);
free(read_devices);
read_devices = tmp;
}
}
if (read_devices[strlen(read_devices)-1]==',') read_devices[strlen(read_devices)-1]='\0';
read_limit = yon_char_unite(read_limit,read_devices,NULL);
if (read_devices && strlen(read_devices) > 0 && read_devices[strlen(read_devices)-1]==',')
read_devices[strlen(read_devices)-1]='\0';
char *write_limit = "";
char *write_devices = "";
char *write_devices = NULL;
for_dictionaries(dict,window->devices){
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 (!strstr(limits->write," 0 ")) {
char *tmp = yon_char_unite(write_devices ? write_devices : "","IOWriteBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",limits->write,",",NULL);
free(write_devices);
write_devices = tmp;
}
}
if (write_devices[strlen(write_devices)-1]==',') write_devices[strlen(write_devices)-1]='\0';
write_limit = yon_char_unite(write_limit,write_devices,NULL);
output_line = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck))? yon_char_append(soft_limit,","): "",
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck))? yon_char_append(hard_limit,","):"",
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck))? yon_char_append(paging_limit,","):"",
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck))? yon_char_append(cpu_limit,","):"",
(read_devices && strcmp(read_devices,"")!=0 ) ? yon_char_append(read_limit,","):"",
(write_devices && strcmp(write_devices,"")!=0 ) ? yon_char_append(write_limit,","):"",NULL);
if (write_devices && strlen(write_devices) > 0 && write_devices[strlen(write_devices)-1]==',')
write_devices[strlen(write_devices)-1]='\0';
char *soft_part = NULL;
char *hard_part = NULL;
char *paging_part = NULL;
char *cpu_part = NULL;
char *read_part = NULL;
char *write_part = NULL;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck)) && soft_limit) soft_part = yon_char_unite(soft_limit,",",NULL);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck)) && hard_limit) hard_part = yon_char_unite(hard_limit,",",NULL);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck)) && paging_limit) paging_part = yon_char_unite(paging_limit,",",NULL);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck)) && cpu_limit) cpu_part = yon_char_unite(cpu_limit,",",NULL);
if (read_devices && strcmp(read_devices,"")!=0) read_part = yon_char_unite(read_devices,",",NULL);
if (write_devices && strcmp(write_devices,"")!=0) write_part = yon_char_unite(write_devices,",",NULL);
output_line = yon_char_unite(soft_part ? soft_part : "",hard_part ? hard_part : "",paging_part ? paging_part : "",cpu_part ? cpu_part : "",read_part ? read_part : "",write_part ? write_part : "",NULL);
if (output_line&&strcmp(output_line,"")!=0&&output_line[strlen(output_line)-1] == ',') output_line[strlen(output_line)-1] = '\0';
gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),output_line);
gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),output_line ? output_line : "");
free(output_line);
free(soft_limit);
free(hard_limit);
free(paging_limit);
free(cpu_limit);
free(read_devices);
free(write_devices);
free(soft_part);
free(hard_part);
free(paging_part);
free(cpu_part);
free(read_part);
free(write_part);
}
void on_limit_manual_input(GtkWidget *self, double *, quota_window *window){
@ -118,12 +143,12 @@ void on_check_maximum(GtkWidget *self, GtkWidget *pair){
if (main_config.avaliable_ram==0){
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.avaliable_ram = (long)inf.totalram * inf.mem_unit;
main_config.avaliable_swap = (long)inf.totalswap * inf.mem_unit;
}
double cur_ram = main_config.avaliable_ram;
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(self));
for (int i=0;i<required_size;i++)
for (int i=0;i<required_size+1;i++)
cur_ram=cur_ram/1024;
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(self));
gtk_adjustment_set_upper(adj,cur_ram);
@ -136,8 +161,8 @@ void on_check_maximum(GtkWidget *self, GtkWidget *pair){
if (main_config.avaliable_ram==0){
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.avaliable_ram = (long)inf.totalram * inf.mem_unit;
main_config.avaliable_swap = (long)inf.totalswap * inf.mem_unit;
}
double cur_ram = main_config.avaliable_ram;
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(pair));
@ -155,14 +180,14 @@ void on_check_maximum_cpu(GtkWidget *self, GtkWidget *pair){
if (GTK_IS_SPIN_BUTTON(self)){
if (GTK_IS_COMBO_BOX(pair)){
int required_size = gtk_combo_box_get_active(GTK_COMBO_BOX(pair));
if (main_config.avaliable_ram==0){
if (main_config.avaliable_swap==0){
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_swap=inf.totalswap;
}
double cur_ram = main_config.avaliable_swap;
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(self));
for (int i=0;i<required_size;i++)
for (int i=0;i<required_size+1;i++)
cur_ram=cur_ram/1024;
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(self));
gtk_adjustment_set_upper(adj,cur_ram);
@ -194,19 +219,19 @@ void on_quota_target_type_changed(GtkWidget *self, quota_window *window){
if (active == 0) {
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
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_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i],main_config.users[i]);
}
}
if (active == 1) {
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
for (int i=0; i<main_config.processes_size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.processes[i]);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.processes[i],main_config.processes[i]);
}
}
if (active == 2) {
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
for (int i=0; i<main_config.slices_size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.slices[i]);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.slices[i],main_config.slices[i]);
}
}
}
@ -224,9 +249,10 @@ void yon_get_devices(quota_window *window){
for (int i=0; i<size;i++){
yon_char_remove_last_symbol(devices_parsed[i],'\n');
char *pa = strstr(devices_parsed[i],"/");
if (!pa) continue;
char *device_name = yon_char_new(pa);
char *id = yon_char_divide_search(device_name," ",-1);
free(device_name);
if (!yon_char_is_empty(device_name)||id != device_name) free(device_name);
device_limits *limits = malloc(sizeof(device_limits));
limits->device_name = yon_char_new(pa);
limits->read=NULL;
@ -400,7 +426,7 @@ int yon_get_size_request_from_letter(char size){
break;
case 'G': return 2;
break;
case 'T': return 0;
case 'T': return 3;
break;
default: return -1;
break;
@ -569,10 +595,10 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){
if (rtn){
for (int i=0; i<size; i++){
char *value = yon_char_new(rtn[i]);
if (!value || !*value) { free(value); continue; }
yon_char_divide_search(value,"=",-1);
int size = yon_get_size_request_from_letter(value[strlen(value)-1]);
if (size!=-1||strstr(rtn[i],"CPUQuota=")){
// value[strlen(value)-1]='\0';
if (strstr(rtn[i],"MemoryHigh=")){
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(value,NULL,10));
@ -601,7 +627,10 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
if (((device_limits*)dict->data)->read) free(((device_limits*)dict->data)->read);
((device_limits*)dict->data)->read = value;
value = NULL;
break;
}
}
@ -615,20 +644,23 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
if (((device_limits*)dict->data)->write) free(((device_limits*)dict->data)->write);
((device_limits*)dict->data)->write = value;
value = NULL;
break;
}
}
} else return;
} else { free(value); free(string); return; }
}
free(value);
}
} else {
char *value = yon_char_new(string);
if (!value || !*value) { free(value); return; }
yon_char_divide_search(value,"=",-1);
int size = yon_get_size_request_from_letter(value[strlen(value)-1]);
if (size!=-1||strstr(string,"CPUQuota=")){
// value[strlen(value)-1]='\0';
if (strstr(string,"MemoryHigh=")){
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(value,NULL,10));
@ -651,13 +683,15 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){
char *name = yon_char_divide_search(value, " ",-1);
dictionary *dict;
for_dictionaries(dict,window->devices){
if (strstr(dict->key,name)){
if (!strcmp(dict->key,name)){
if (!((device_limits*)dict->data)){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
if (((device_limits*)dict->data)->read) free(((device_limits*)dict->data)->read);
((device_limits*)dict->data)->read = value;
value = NULL;
break;
}
}
@ -666,19 +700,24 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){
char *name = yon_char_divide_search(value, " ",-1);
dictionary *dict;
for_dictionaries(dict,window->devices){
if (strstr(dict->key,name)){
if (!strcmp(dict->key,name)){
if (!((device_limits*)dict->data)){
dict->data = g_malloc0(sizeof(device_limits));
((device_limits*)dict->data)->write=NULL;
((device_limits*)dict->data)->read=NULL;
}
if (((device_limits*)dict->data)->write) free(((device_limits*)dict->data)->write);
((device_limits*)dict->data)->write = value;
value = NULL;
break;
}
}
} else return;
} else { free(value); free(string); return; }
}
if (!yon_char_is_empty(value)) free(value);
}
if (!yon_char_is_empty(string)) free(string);
}
void on_quota_manual_input_focus (GtkWidget *self, GdkEventFocus *, quota_window *window){
@ -726,6 +765,7 @@ void on_filters_opened(GtkWidget *, main_window *widgets) {
void on_add_open(GtkWidget *, main_window *widgets){
quota_window *window = yon_quota_window_new();
yon_gtk_window_setup(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->Window),NULL,icon_path,"quota_window");
gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
@ -769,7 +809,7 @@ void on_information(GtkWidget *, main_window *widgets){
} else {
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetTypeCombo),0);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetCombo),yon_gtk_combo_box_text_find(widgets->TargetCombo,name));
gtk_combo_box_set_active_id(GTK_COMBO_BOX(widgets->TargetCombo),name);
g_signal_handlers_unblock_by_func(G_OBJECT(widgets->TargetCombo),on_information_chosen_changed,widgets);
char *command = get_information_command((char*)name);
main_config.last_info = yon_char_new((char*)name);
@ -967,6 +1007,12 @@ quota_window *yon_quota_window_new(){
g_signal_connect(G_OBJECT(window->ManualInputEntry),"changed",G_CALLBACK(on_manual_edit),window);
g_signal_connect(G_OBJECT(window->ManualInputEntry),"focus-out-event",G_CALLBACK(yon_manual_string_finish),window);
struct sysinfo inf;
sysinfo(&inf);
main_config.avaliable_ram=inf.totalram;
main_config.avaliable_swap=inf.totalswap;
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
yon_get_devices(window);
window->devices=window->devices->first;
@ -988,14 +1034,9 @@ quota_window *yon_quota_window_new(){
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_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i],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;
@ -1042,9 +1083,9 @@ void yon_quota_update(quota_window *window){
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++)
if (size_mult < 0) size_mult = -1;
long hard_current_max = main_config.avaliable_ram;
for (int i=0;i<size_mult+1;i++) hard_current_max /= 1024;
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) {
@ -1164,6 +1205,7 @@ void on_edit_open(GtkWidget *, main_window *widgets){
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();
yon_gtk_window_setup(GTK_WINDOW(window->Window),GTK_WINDOW(widgets->Window),NULL,icon_path,"quota_window");
gtk_widget_set_sensitive(window->BlockUiBox,1);
char *target, *type;
gtk_tree_model_get(model,&iter,0,&type,1,&target,-1);
@ -1206,9 +1248,9 @@ gboolean on_dispatcher_update(GtkWidget *,main_window *widgets){
void on_processes_update(GtkWidget *,main_window *widgets){
int show_all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ShowAllCheck));
int show_core = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ShowCoreCheck));
char *command = get_processes_tree_command;
if (show_all) yon_char_append(command, " -k");
if (show_core) yon_char_append(command, " -l");
char *command = yon_char_new(get_processes_tree_command);
if (show_all) command = yon_char_append(command, " -k");
if (show_core) command = yon_char_append(command, " -l");
yon_terminal_integrated_start_shell(widgets->ProcessesTerminal, command,NULL,NULL);
}
@ -1236,7 +1278,7 @@ void on_info_target_type_switched(GtkWidget *self, main_window *widgets){
break;
}
for (int i=0; i<size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->TargetCombo),str[i]);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(widgets->TargetCombo),str[i],str[i]);
}
}
@ -1363,8 +1405,8 @@ int main(int argc, char *argv[]){
main_config.launch_size=argc;
yon_window_check_root_message(widgets);
yon_main_window_complete((main_window*)widgets);
char *path = yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL);
yon_window_config_load(path);
yon_window_config_load(config_path);
gtk_main();
return 0;
}

@ -17,15 +17,15 @@
#include <webkit2/webkit2.h>
#endif
#include "ubl-strings.h"
#define config_path yon_char_unite("/home/",yon_ubl_root_user_get(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define _(String) gettext(String)
#define glade_path "/com/ublinux/ui/ubl-settings-resourcequota.glade"
#define glade_filters_path "/com/ublinux/ui/ubl-settings-resourcequota-filters.glade"
#define glade_quota_path "/com/ublinux/ui/ubl-settings-resourcequota-quota.glade"
#define banner_path "/com/ublinux/images/ubl-settings-resourcequota-banner.png"
#define CssPath "/com/ublinux/css/ubl-settings-resourcequota.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define icon_path "com.ublinux.ubl-settings-resourcequota"
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-resourcequota"
@ -38,7 +38,7 @@
// #define remove_command "ubconfig remove security "
// #define remove_global_command "ubconfig --target global --noexecute remove security "
// #define remove_local_command "ubconfig --target system remove security "
#define get_devices_command "clear;findmnt -lo source,target,fstype,label,size -t ext4 |grep -vE \"zram|\\]|\\[|SOURCE\""
#define get_devices_command "findmnt -lo source,target,fstype,label,size -t ext4| tail -n +2| grep -v \"\\[\""
#define get_processes_tree_command "clear; systemd-cgls --no-page"
#define get_dispatcher_command "clear; systemd-cgtop -c"
#define get_information_command(target) yon_char_unite("systemctl status ",target,".slice --no-pager",NULL)
@ -52,7 +52,7 @@
#define config_get_local_only_parameters ""
#define CGROUP_QUOTA(name) yon_char_unite("CGROUP_QUOTA[",name,"]",NULL)
#define CGROUP_QUOTA_comd(name) yon_char_unite("ubconfig -- source global get security CGROUP_QUOTA[",target,"]",NULL)
#define CGROUP_QUOTA_comd(name) yon_char_unite("ubconfig -- source global get security CGROUP_QUOTA[",name,"]",NULL)
#define CGROUP_QUOTA_parameter "CGROUP_QUOTA"
#define CGROUP_QUOTA_command "ubconfig -- source global get security CGROUP_QUOTA"

Loading…
Cancel
Save