From 1d059a1e0df972020ff5e7a75b9fba17c9456491 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 15 May 2025 16:39:22 +0600 Subject: [PATCH] WIP service loading changes --- source/ubl-settings-services.c | 52 ++++++++++++++++++---------------- source/ubl-settings-services.h | 25 ++++++++++++++-- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/source/ubl-settings-services.c b/source/ubl-settings-services.c index 62ac971..3b6c00c 100644 --- a/source/ubl-settings-services.c +++ b/source/ubl-settings-services.c @@ -1349,12 +1349,12 @@ void* yon_interface_update(main_window *widgets){ g_idle_add((GSourceFunc)yon_interface_list_models_disconnect,widgets); int 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 system_units_size; + // config_str system_units = yon_config_load(load_system_units_command,&system_units_size); int 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); + config_str user_services = yon_config_load(load_user_units_command,&user_size); + // int user_units_size; + // config_str user_units = yon_config_load(load_user_units_command,&user_units_size); int config_size; config_str config_files = yon_config_load(get_config_files_command,&config_size); int timers_size; @@ -1394,24 +1394,25 @@ void* yon_interface_update(main_window *widgets){ parsed[0]=yon_char_replace(name_temp,"\18","\\\\"); if (name_temp!=parsed[0]) free(name_temp); if (parsed){ + int enabled = !strcmp(parsed[5],"enabled"); 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,loaded,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,1,11,_(parsed[3]),13,parsed[3],-1); + gtk_list_store_set(widgets->SystemList,&iter,3,enabled,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],-1); } } - for (int i=0;iSystemList,&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"),13,"disabled",-1); + // for (int i=0;iSystemList,&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"),13,"disabled",-1); - } - } + // } + // } // for (int i=0; iUserList,&iter); - gtk_list_store_set(widgets->UserList,&iter,3,loaded,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,1,11,_(parsed[3]),13,parsed[3],-1); + gtk_list_store_set(widgets->UserList,&iter,3,enabled,4,active,5,parsed[0],6,parsed[4],7,type,8,active,9,loaded,11,_(parsed[3]),13,parsed[3],-1); } } - for (int i=0;iUserList,&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"),13,"disabled",-1); + // for (int i=0;iUserList,&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"),13,"disabled",-1); - } - } + // } + // } int descr_size; config_str config_descr = yon_resource_open_file(systemd_config_path,&descr_size); diff --git a/source/ubl-settings-services.h b/source/ubl-settings-services.h index 2eecd13..2e6c752 100644 --- a/source/ubl-settings-services.h +++ b/source/ubl-settings-services.h @@ -38,9 +38,30 @@ #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 --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic " \ +"--no-pager --all --no-legend show -- $( { " \ +"systemctl list-units --no-pager --all --plain --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \ +"systemctl list-unit-files --no-pager --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \ +"} | sed '/@\\./d' | sort -u ) | " \ +"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \ +"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \ +"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \ +"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \ +"val[\"InactiveEnterTimestampMonotonic\"]; delete val }'" + #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_units_command yon_char_unite(\ +"systemctl --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic " \ +"--no-pager --all --no-legend show -- $( { " \ +"systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --no-pager --all --plain --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \ +"systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-unit-files --no-pager --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \ +"} | sed '/@\\./d' | sort -u ) | " \ +"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \ +"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \ +"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \ +"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \ +"val[\"InactiveEnterTimestampMonotonic\"]; delete val }'",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_enabled_command "systemctl list-unit-files --no-pager --state=enabled --all |sed -e 's/ */:/g' -e 's/ *: */:/g'|cut -f1 -d:"