master #90

Merged
asmeron merged 7 commits from YanTheKaller/ubl-settings-services:master into master 8 months ago

@ -7,6 +7,9 @@
<gresource prefix="/com/ublinux/css">
<file>ubl-settings-services.css</file>
</gresource>
<gresource prefix="/com/ublinux/csv">
<file>systemd_conf.csv</file>
</gresource>
<gresource prefix="/com/ublinux/images">
<file>ubl-settings-services-banner.png</file>
</gresource>

@ -36,6 +36,7 @@ add_custom_target(GLADE ubl-settings-services.glade)
set(DEPENDFILES
../ubl-settings-services.glade
../systemd_conf.csv
../ubl-settings-services-terminal.glade
../gresource.xml
../ubl-settings-services-banner.png
@ -69,12 +70,18 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wmissing-declarations
-Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection")
string(FIND "${CMAKE_CXX_FLAGS}" "-D_FORTIFY_SOURCE" FORTIFY_FOUND)
string(FIND "${CMAKE_CXX_FLAGS}" "-D_FORTIFY_SOURCE" FORTIFY_FOUND)
if(FORTIFY_FOUND EQUAL -1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
endif()
set(SOURCE_FILES
ubl-settings-services.c
ubl-settings-services.h
ubl-settings-services-systemd.c
ubl-settings-services-systemd.h
ubl-strings.h
)
@ -87,7 +94,8 @@ set(LIBRARIES
pthread
ublsettings
ublsettings-gtk3
ublsettingsui-gtk3)
ublsettingsui-gtk3
systemd)
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C})

@ -0,0 +1,123 @@
#include "ubl-settings-services-systemd.h"
void at_exit_cleanup();
sd_bus *global_bus=NULL;
void at_exit_cleanup(){
if (global_bus) {
sd_bus_unref(global_bus);
}
}
dictionary *yon_systemd_get_list() {
sd_bus *bus = NULL;
sd_bus_message *reply = NULL;
int r;
r = sd_bus_open_system(&bus);
if (r < 0) return NULL;
dictionary *dict = NULL;
r = sd_bus_call_method(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ListUnits",
NULL,
&reply,
"");
if (r < 0) {if (bus) sd_bus_unref(bus);return NULL;}
sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssssouso)");
while (sd_bus_message_enter_container(reply, SD_BUS_TYPE_STRUCT, "ssssssouso") > 0) {
const char *name, *description;
const char *load_state, *active_state, *sub_state;
const char *following, *unit_path;
unsigned int job_id;
const char *job_type, *job_path;
sd_bus_message_read(reply, "ssssssouso",
&name, &description,
&load_state, &active_state,
&sub_state, &following,
&unit_path, &job_id,
&job_type, &job_path);
systemd_struct *u = calloc(1, sizeof(systemd_struct));
u->name = yon_char_new(name);
u->description = yon_char_new(description);
u->load = !strcmp(load_state,"loaded");
u->active = !strcmp(active_state, "active");
u->state = yon_char_new(sub_state);
u->enable = 0;
yon_dictionary_add_or_create_if_exists_with_data(dict, (char*)name, u);
sd_bus_message_exit_container(reply);
}
sd_bus_message_unref(reply);
reply = NULL;
r = sd_bus_call_method(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ListUnitFiles",
NULL,
&reply,
"");
if (r < 0) {if (bus) sd_bus_unref(bus); return NULL;}
sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ss)");
while (sd_bus_message_enter_container(reply, SD_BUS_TYPE_STRUCT, "ss") > 0) {
const char *name, *file_state;
sd_bus_message_read(reply, "ss", &name, &file_state);
dictionary *found = NULL;
for (dictionary *it = dict; it; it = it->next) {
if (strcmp(it->key, name) == 0) {
found = it;
break;
}
}
if (!found) {
systemd_struct *u = calloc(1, sizeof(systemd_struct));
u->name = yon_char_new(name);
u->description = yon_char_new("");
u->load = 0;
u->active = 0;
u->state = yon_char_new("");
u->enable = 0;
yon_dictionary_add_or_create_if_exists_with_data(dict, (char*)name, u);
}
sd_bus_message_exit_container(reply);
}
sd_bus_message_unref(reply);
reply = NULL;
dictionary *it;
for_dictionaries(it, dict) {
systemd_struct *u = (systemd_struct*)it->data;
r = sd_bus_call_method(bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"GetUnitFileState",
NULL,
&reply,
"s", u->name);
if (r >= 0) {
const char *status;
sd_bus_message_read(reply, "s", &status);
u->enable = (strcmp(status, "enabled") == 0);
}
sd_bus_message_unref(reply);
reply = NULL;
}
if (reply) sd_bus_message_unref(reply);
if (bus) sd_bus_unref(bus);
return dict;
}

@ -0,0 +1,8 @@
#ifndef UBL_SETTINGS_SERVICES_SYSTEMD_H
#define UBL_SETTINGS_SERVICES_SYSTEMD_H
#include "ubl-settings-services.h"
#include <systemd/sd-bus.h>
dictionary *yon_systemd_get_list();
#endif

File diff suppressed because it is too large Load Diff

@ -1,3 +1,5 @@
#ifndef UBL_SETTINGS_SERVICES_H
#define UBL_SETTINGS_SERVICES_H
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gtk/gtkx.h>
@ -12,6 +14,7 @@
#include <libublsettings.h>
#include <libublsettings-gtk3.h>
#include <libublsettingsui-gtk3.h>
#include "ubl-settings-services-systemd.h"
#include <time.h>
#include <json-c/json.h>
#ifdef WEBKIT_FOUND
@ -31,7 +34,9 @@
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-services"
#define LocaleName "ubl-settings-services"
#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_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)
@ -44,6 +49,9 @@
#define service_disable_command(target) yon_char_append("systemctl disable ",target)
#define service_kill_command(target) yon_char_append("systemctl kill ",target)
#define service_check_active_command(target) yon_char_append("systemctl is-active ",target)
#define check_enabled_command(target) yon_char_append("systemctl is-enabled ",target)
#define user_check_active_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ is-active ",target,NULL)
#define user_check_enabled_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ is-enabled ",target,NULL)
#define service_info_command(target) yon_char_append("systemctl status -l --no-pager ",target)
#define get_log_command(target) yon_char_append("journalctl --all --no-pager --unit ",target)
@ -75,7 +83,7 @@
#define list_of_sockets_command "systemctl list-sockets --all --no-pager| sed -e 's/ */;/g'"
#define list_of_timers_command "systemctl list-timers --all --no-pager| sed -e 's/ */;/g'"
#define list_of_session_command "while IFS=\" \" read -r GET_SESSION GET_UID GET_USER GET_SEAT GET_TTY; do echo -e \"${GET_SESSION} $(loginctl session-status ${GET_SESSION} --no-page | sed -Enr \"s/^\\s*State: (.*)$/\1/p\") ${GET_UID} ${GET_USER} ${GET_SEAT} ${GET_TTY}\"; done < <(loginctl list-sessions --no-legend)"
#define get_activate_deactivate_times(target) yon_char_append("systemctl show -p ActiveEnterTimestampMonotonic -p InactiveEnterTimestampMonotonic -p Names ",target)
#define get_activate_deactivate_times(target) yon_char_append("systemctl show --timestamp=utc -p Names -p ActiveEnterTimestamp -p InactiveEnterTimestampMonotonic ",target)
#define config_get_command(target) yon_char_append("cat ",target)
@ -122,9 +130,33 @@
#define SERVICES_MASK_PARAMETER "SERVICES_MASK"
typedef char* string;
__attribute__((unused)) static \
string version_application;
char *local;
enum YON_UNIT_TYPE {
YON_UNIT_SERVICE=0,
YON_UNIT_SWAP,
YON_UNIT_SOCKET,
YON_UNIT_DEVICE,
YON_UNIT_TARGET,
YON_UNIT_MOUNT,
YON_UNIT_TIMER,
YON_UNIT_PATH,
YON_UNIT_SLICE,
YON_UNIT_SCOPE,
YON_UNIT_UNRECOGNISED
};
typedef struct systemd_struct{
char *name;
char *description;
int enable;
int active;
char *state;
int load;
}systemd_struct;
typedef struct {
template_config_fields
@ -316,7 +348,7 @@ void on_sockets_list_status(GtkWidget *self, main_window *widgets);
void on_timers_list_status(GtkWidget *self, main_window *widgets);
gboolean yon_interface_update(main_window *widgets);
void* yon_interface_update(main_window *widgets);
void on_interface_update(GtkWidget *self, main_window *widgets);
@ -375,7 +407,7 @@ void on_system_info_clicked(GtkWidget *self, main_window *widgets);
void on_system_log_clicked(GtkWidget *self, main_window *widgets);
void *on_terminal_relaunch(log_window *window);
gboolean on_terminal_relaunch(log_window *window);
void on_save_clicked(GtkWidget *self, log_window *window);
void on_update_clicked(GtkWidget *self, log_window *window);
void on_system_edit_clicked(GtkWidget *self, main_window *widgets);
@ -444,4 +476,59 @@ gboolean on_source_system_filter(GtkTreeModel *model, GtkTreeIter *iter,void *da
void on_root_get_root(char *argline);
void on_root_access(GtkWidget *self, main_window *widgets);
void on_save_done(main_window *widgets, config_str output, int size);
void on_save_done(main_window *widgets, config_str output, int size);
struct system_services_data{
main_window *widgets;
int SystemAutostart;
int SystemLaunched;
char *Name;
char *Descr;
enum YON_UNIT_TYPE Type;
int Loaded;
int Active;
char *State;
};
struct system_user_data{
main_window *widgets;
int SystemAutostart;
int SystemLaunched;
char *Name;
char *Descr;
enum YON_UNIT_TYPE Type;
int Loaded;
int Active;
char *State;
};
struct system_config_data{
main_window *widgets;
char *Name;
char *Descr;
char *Date;
};
struct system_timers_data{
main_window *widgets;
const char *unit;
const char *next;
const char *left;
const char *last;
const char *passed;
const char *activates;
};
gboolean yon_interface_update_finish(main_window *widgets);
gboolean yon_timers_set(struct system_timers_data *data);
gboolean yon_system_config_set(struct system_config_data *data);
gboolean yon_user_set(struct system_user_data *data);
gboolean yon_system_set(struct system_services_data *data);
gboolean yon_interface_list_models_connect(main_window *widgets);
gboolean yon_interface_list_models_disconnect(main_window *widgets);
#endif

@ -15,15 +15,19 @@
</object>
<object class="GtkListStore" id="SessionsList">
<columns>
<!-- column-name gint2 -->
<!-- column-name Id -->
<column type="gint"/>
<!-- column-name gchararray2 -->
<!-- column-name Status -->
<column type="gchararray"/>
<!-- column-name gint1 -->
<!-- column-name User Id -->
<column type="gint"/>
<!-- column-name gchararray3 -->
<!-- column-name Username -->
<column type="gchararray"/>
<!-- column-name gchararray4 -->
<!-- column-name RenderId -->
<column type="gchararray"/>
<!-- column-name SeatId -->
<column type="gchararray"/>
<!-- column-name TTY -->
<column type="gchararray"/>
</columns>
</object>
@ -407,11 +411,6 @@
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.ubl-settings-services.properties-symbolic</property>
</object>
<object class="GtkImage" id="image19">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.ubl-settings-services.sync-symbolic</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -427,6 +426,11 @@
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.ubl-settings-services.arrow-round-symbolic</property>
</object>
<object class="GtkImage" id="image22">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.ubl-settings-services.sync-symbolic</property>
</object>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -1916,7 +1920,7 @@
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="tooltip-text" translatable="yes">Update</property>
<property name="image">image19</property>
<property name="image">image22</property>
<style>
<class name="thin"/>
</style>
@ -2081,7 +2085,7 @@
<child>
<object class="GtkTreeViewColumn">
<property name="min-width">20</property>
<property name="title" translatable="yes">Seat ID</property>
<property name="title" translatable="yes">Seat ID | TTY</property>
<property name="expand">True</property>
<property name="sort-column-id">4</property>
<child>

@ -517,3 +517,67 @@ msgstr ""
#: source/ubl-strings.h:159
msgid "Status:"
msgstr ""
#: source/ubl-strings.h:159
msgid "UBLinux OS configuration files"
msgstr ""
#: source/ubl-strings.h:159
msgid "System Debug Dump Configuration"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuring various systemd log service options"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuring various systemd-journal-upload.service parameters"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuring Global Network Settings"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuration file for systemd-pstore, a tool for archiving the contents of the pstore persistent storage file system"
msgstr ""
#: source/ubl-strings.h:159
msgid "Workstation hibernation options"
msgstr ""
#: source/ubl-strings.h:159
msgid "Systemd configuration"
msgstr ""
#: source/ubl-strings.h:159
msgid "User Configuration"
msgstr ""
#: source/ubl-strings.h:159
msgid "Settings management configuration for user account home directories created and managed by systemd-homed.service"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuration files for various systemd-journal-remote.service parameters"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuration files for various systemd login manager options"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuration files for various out-of-memory (OOM) killer parameters in systemd user space"
msgstr ""
#: source/ubl-strings.h:159
msgid "Local DNS and LLMNR name resolution management configuration files"
msgstr ""
#: source/ubl-strings.h:159
msgid "System swap file management configuration files"
msgstr ""
#: source/ubl-strings.h:159
msgid "Configuration file controlling NTP network time synchronization"
msgstr ""

@ -520,3 +520,74 @@ msgstr "Деактивирован:"
#: source/ubl-strings.h:159
msgid "Status:"
msgstr "Статус:"
#: source/ubl-strings.h:159
msgid "UBLinux OS configuration files"
msgstr "Файлы конфигурации ОС UBLinux"
#: source/ubl-strings.h:159
msgid "System Debug Dump Configuration"
msgstr "Конфигурация системного отладочного дампа"
#: source/ubl-strings.h:159
msgid "Configuring various systemd log service options"
msgstr "Настройка различных параметров службы журнала systemd"
#: source/ubl-strings.h:159
msgid "Configuring various systemd-journal-upload.service parameters"
msgstr "Настройка различных параметров systemd-journal-upload.service"
#: source/ubl-strings.h:159
msgid "Configuring Global Network Settings"
msgstr "Настройка глобальных сетевых параметров"
#: source/ubl-strings.h:159
msgid ""
"Configuration file for systemd-pstore, a tool for archiving the contents of "
"the pstore persistent storage file system"
msgstr "Файл конфигурации для systemd-pstore, инструмента для архивирования содержимого постоянной файловой системы хранения pstore"
#: source/ubl-strings.h:159
msgid "Workstation hibernation options"
msgstr "Параметры спящего режима рабочей станции"
#: source/ubl-strings.h:159
msgid "Systemd configuration"
msgstr "Системная конфигурация"
#: source/ubl-strings.h:159
msgid "User Configuration"
msgstr "Конфигурация пользователя"
#: source/ubl-strings.h:159
msgid ""
"Settings management configuration for user account home directories created "
"and managed by systemd-homed.service"
msgstr "Конфигурация управления настройками для домашних каталогов учетных записей пользователей, созданная и управляемая systemd-homed.service"
#: source/ubl-strings.h:159
msgid ""
"Configuration files for various systemd-journal-remote.service parameters"
msgstr "Файлы конфигурации для различных параметров systemd-journal-remote.service"
#: source/ubl-strings.h:159
msgid "Configuration files for various systemd login manager options"
msgstr "Файлы конфигурации для различных опций менеджера входа в систему systemd"
#: source/ubl-strings.h:159
msgid ""
"Configuration files for various out-of-memory (OOM) killer parameters in "
"systemd user space"
msgstr "Файлы конфигурации для различных параметров исключения нехватки памяти (OOM) в пользовательском пространстве systemd"
#: source/ubl-strings.h:159
msgid "Local DNS and LLMNR name resolution management configuration files"
msgstr "Файлы конфигурации управления разрешением имен локального DNS и LLMNR"
#: source/ubl-strings.h:159
msgid "System swap file management configuration files"
msgstr "Файлы конфигурации управления файлами подкачки системы"
#: source/ubl-strings.h:159
msgid "Configuration file controlling NTP network time synchronization"
msgstr "Файл конфигурации, управляющий синхронизацией времени сети NTP"

Loading…
Cancel
Save