Fixed services parsing

pull/91/head
parent 5fe77a06a6
commit d21be8d136

@ -1265,18 +1265,25 @@ gboolean yon_interface_update_finish(main_window *widgets){
} }
} }
main_config.update_thread_active=0; main_config.update_thread_active=0;
char *final = yon_char_unite(yon_char_get_localised_from_lib(SUCCESS_LABEL),". ",main_config.load_mode==0?yon_char_get_localised_from_lib(GLOBAL_LOAD_SUCCESS_LABEL):yon_char_get_localised_from_lib(LOCAL_LOAD_SUCCESS_LABEL),NULL);
yon_ubl_status_box_render(final,BACKGROUND_IMAGE_SUCCESS_TYPE);
free(final);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void* yon_interface_update(main_window *widgets){ void* yon_interface_update(main_window *widgets){
dictionary *dict = yon_systemd_get_list(); // dictionary *dict = yon_systemd_get_list();
if (dict){} // if (dict){}
if (widgets){ if (widgets){
g_idle_add((GSourceFunc)yon_interface_list_models_disconnect,widgets); g_idle_add((GSourceFunc)yon_interface_list_models_disconnect,widgets);
// int system_size; int system_size;
// config_str system_services = yon_config_load(load_services_command,&system_size); config_str system_services = yon_config_load(load_services_command,&system_size);
int system_units_size;
config_str system_units = yon_config_load(load_system_units_command,&system_units_size);
int user_size; int user_size;
config_str user_services = yon_config_load(load_user_services_command,&user_size); config_str user_services = yon_config_load(load_user_services_command,&user_size);
int user_units_size;
config_str user_units = yon_config_load(load_user_units_command,&user_units_size);
int config_size; int config_size;
config_str config_files = yon_config_load(get_config_files_command,&config_size); config_str config_files = yon_config_load(get_config_files_command,&config_size);
int timers_size; int timers_size;
@ -1288,47 +1295,101 @@ void* yon_interface_update(main_window *widgets){
yon_char_remove_last_symbol(launched[i],'\n'); yon_char_remove_last_symbol(launched[i],'\n');
} }
dictionary *dact = NULL; // dictionary *dact = NULL;
for_dictionaries(dact,dict){ // for_dictionaries(dact,dict){
enum YON_UNIT_TYPE type = yon_get_unit_type(((systemd_struct*)dact->data)->name); // enum YON_UNIT_TYPE type = yon_get_unit_type(((systemd_struct*)dact->data)->name);
struct system_services_data *data = malloc(sizeof(struct system_services_data)); // struct system_services_data *data = malloc(sizeof(struct system_services_data));
{ // {
data->widgets=widgets; // data->widgets=widgets;
data->SystemAutostart=((systemd_struct*)dact->data)->enable; // data->SystemAutostart=((systemd_struct*)dact->data)->enable;
data->SystemLaunched=((systemd_struct*)dact->data)->active; // data->SystemLaunched=((systemd_struct*)dact->data)->active;
data->Name=((systemd_struct*)dact->data)->name; // data->Name=((systemd_struct*)dact->data)->name;
data->Descr=((systemd_struct*)dact->data)->description; // data->Descr=((systemd_struct*)dact->data)->description;
data->Type = type; // data->Type = type;
data->Loaded=((systemd_struct*)dact->data)->load; // data->Loaded=((systemd_struct*)dact->data)->load;
data->Active=((systemd_struct*)dact->data)->active; // data->Active=((systemd_struct*)dact->data)->active;
data->State=((systemd_struct*)dact->data)->state; // data->State=((systemd_struct*)dact->data)->state;
// }
// g_idle_add((GSourceFunc)yon_system_set,data);
// }
for (int i=0; i<system_size;i++){
GtkTreeIter iter;
if (system_services[i][strlen(system_services[i])-1]=='\n') system_services[i][strlen(system_services[i])-1] = '\0';
int size;
config_str parsed = yon_char_parse(system_services[i],&size,";");
char *name_temp = yon_char_replace(parsed[0],"\\","\18");
if (name_temp!=parsed[0]) free(parsed[0]);
parsed[0]=yon_char_replace(name_temp,"\18","\\\\");
if (name_temp!=parsed[0]) free(name_temp);
if (parsed){
int loaded = !strcmp(parsed[1],"loaded");
int active = !strcmp(parsed[2],"active");
enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]);
gtk_list_store_append(widgets->SystemList,&iter);
gtk_list_store_set(widgets->SystemList,&iter,3,1,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),-1);
} }
g_idle_add((GSourceFunc)yon_system_set,data);
} }
for (int i=0;i<system_units_size;i++){
yon_char_remove_last_symbol(system_units[i],'\n');
if (!yon_char_parsed_check_exist_begins_with(system_services,system_size,system_units[i])){
GtkTreeIter iter;
gtk_list_store_append(widgets->SystemList,&iter);
enum YON_UNIT_TYPE type = yon_get_unit_type(system_units[i]);
gtk_list_store_set(widgets->SystemList,&iter,0,0,1,0,2,0,3,0,4,0,5,system_units[i],6,"",7,type,8,0,9,0,10,0,11,_("disabled"),-1);
}
}
// for (int i=0; i<user_size;i++){
// if (user_services[i][strlen(user_services[i])-1]=='\n') user_services[i][strlen(user_services[i])-1] = '\0';
// int size;
// config_str parsed = yon_char_parse(user_services[i],&size,";");
// if (parsed){
// // int loaded = !system(user_check_enabled_command(parsed[0]));
// // int active = !system(user_check_active_command(parsed[0]));
// enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]);
// struct system_user_data *data = malloc(sizeof(struct system_user_data));
// {
// data->widgets=widgets;
// data->SystemAutostart=0;//loaded;
// data->SystemLaunched=0;//active;
// data->Name=yon_char_new(parsed[0]);
// data->Descr=yon_char_new(parsed[4]);
// data->Type = type;
// data->Loaded=strcmp(parsed[1],"loaded")?0:1;
// data->Active=strcmp(parsed[2],"active")?0:1;
// data->State=yon_char_new(_(parsed[3]));
// }
// g_idle_add((GSourceFunc)yon_user_set,data);
// }
// yon_char_parsed_free(parsed,size);
// }
for (int i=0; i<user_size;i++){ for (int i=0; i<user_size;i++){
GtkTreeIter iter;
if (user_services[i][strlen(user_services[i])-1]=='\n') user_services[i][strlen(user_services[i])-1] = '\0'; if (user_services[i][strlen(user_services[i])-1]=='\n') user_services[i][strlen(user_services[i])-1] = '\0';
int size; int size;
config_str parsed = yon_char_parse(user_services[i],&size,";"); config_str parsed = yon_char_parse(user_services[i],&size,";");
if (parsed){ if (parsed){
// int loaded = !system(user_check_enabled_command(parsed[0])); int loaded = !strcmp(parsed[1],"loaded");
// int active = !system(user_check_active_command(parsed[0])); int active = !strcmp(parsed[2],"active");
enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]); enum YON_UNIT_TYPE type = yon_get_unit_type(parsed[0]);
struct system_user_data *data = malloc(sizeof(struct system_user_data)); gtk_list_store_append(widgets->UserList,&iter);
{ gtk_list_store_set(widgets->UserList,&iter,3,1,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),-1);
data->widgets=widgets; }
data->SystemAutostart=0;//loaded;
data->SystemLaunched=0;//active;
data->Name=yon_char_new(parsed[0]);
data->Descr=yon_char_new(parsed[4]);
data->Type = type;
data->Loaded=strcmp(parsed[1],"loaded")?0:1;
data->Active=strcmp(parsed[2],"active")?0:1;
data->State=yon_char_new(_(parsed[3]));
} }
g_idle_add((GSourceFunc)yon_user_set,data); for (int i=0;i<user_units_size;i++){
yon_char_remove_last_symbol(user_units[i],'\n');
if (!yon_char_parsed_check_exist_begins_with(user_services,user_size,user_units[i])){
GtkTreeIter iter;
gtk_list_store_append(widgets->UserList,&iter);
enum YON_UNIT_TYPE type = yon_get_unit_type(user_units[i]);
gtk_list_store_set(widgets->UserList,&iter,0,0,1,0,2,0,3,0,4,0,5,user_units[i],6,"",7,type,8,0,9,0,10,0,11,_("disabled"),-1);
} }
yon_char_parsed_free(parsed,size);
} }
int descr_size; int descr_size;

@ -39,6 +39,8 @@
#define systemd_config_path "resource:///com/ublinux/csv/systemd_conf.csv" #define systemd_config_path "resource:///com/ublinux/csv/systemd_conf.csv"
#define load_services_command "systemctl list-units --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)/\\1;\\2;\\3;\\4;\\5/'" #define load_services_command "systemctl list-units --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)/\\1;\\2;\\3;\\4;\\5/'"
#define load_system_units_command "systemctl list-unit-files --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)(.*)/\\1/'"
#define load_user_units_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-unit-files --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)(.*)/\\1;\\2;\\3;/'",NULL)
#define load_user_services_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)/\\1;\\2;\\3;\\4;\\5/'",NULL) #define load_user_services_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)/\\1;\\2;\\3;\\4;\\5/'",NULL)
#define load_system_services_command "systemctl --system list-units --no-pager --all |grep -E \"^ \" |grep -v \"UNIT\" |sed -e 's/ */;/g' -e 's/^;//g' |cut -f1 -d';'" #define load_system_services_command "systemctl --system list-units --no-pager --all |grep -E \"^ \" |grep -v \"UNIT\" |sed -e 's/ */;/g' -e 's/^;//g' |cut -f1 -d';'"
#define load_enabled_command "systemctl list-unit-files --no-pager --state=enabled --all |sed -e 's/ */:/g' -e 's/ *: */:/g'|cut -f1 -d:" #define load_enabled_command "systemctl list-unit-files --no-pager --state=enabled --all |sed -e 's/ */:/g' -e 's/ *: */:/g'|cut -f1 -d:"

Loading…
Cancel
Save