From 191171802b15d14ee2bbcb0947000ba210a23271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Mon, 19 Apr 2021 21:26:58 +0200 Subject: [PATCH] Make Lakka change handlers use the setting pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These change handler functions had incorrect parameter (void *) instead of (rarch_setting_t *) and were also spawning new local pointer to the settings and other local variables, which was not necessary, as one can use the value from the call (setting->target.value.boolean in these cases). I have also modified the systemd_sevice_toggle function. Before it looked like it was creating / deleting the file in both child and parent processes and started / stopped the systemd service in the child process. Now both actions (creation / deletion of file and start / stop of service) are done in the child process. Below are the compiler warnings about incompatible pointer types: ``` menu/menu_setting.c: In function ‘setting_append_list’: menu/menu_setting.c:18520:58: warning: assignment to ‘change_handler_t’ {aka ‘void (*)(struct rarch_setting *)’} from incompatible pointer type ‘void (*)(void *)’ [-Wincompatible-pointer-types] 18520 | (*list)[list_info->index - 1].change_handler = ssh_enable_toggle_change_handler; | ^ menu/menu_setting.c:18536:58: warning: assignment to ‘change_handler_t’ {aka ‘void (*)(struct rarch_setting *)’} from incompatible pointer type ‘void (*)(void *)’ [-Wincompatible-pointer-types] 18536 | (*list)[list_info->index - 1].change_handler = samba_enable_toggle_change_handler; | ^ menu/menu_setting.c:18552:58: warning: assignment to ‘change_handler_t’ {aka ‘void (*)(struct rarch_setting *)’} from incompatible pointer type ‘void (*)(void *)’ [-Wincompatible-pointer-types] 18552 | (*list)[list_info->index - 1].change_handler = bluetooth_enable_toggle_change_handler; | ^ menu/menu_setting.c:18568:58: warning: assignment to ‘change_handler_t’ {aka ‘void (*)(struct rarch_setting *)’} from incompatible pointer type ‘void (*)(void *)’ [-Wincompatible-pointer-types] 18568 | (*list)[list_info->index - 1].change_handler = localap_enable_toggle_change_handler; | ^ ``` --- menu/menu_setting.c | 74 ++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index ec4492661b..18bf8eff50 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -7949,75 +7949,47 @@ static void update_streaming_url_write_handler(rarch_setting_t *setting) #ifdef HAVE_LAKKA static void systemd_service_toggle(const char *path, char *unit, bool enable) { - int pid = fork(); - char* args[] = {(char*)"systemctl", NULL, NULL, NULL}; - - if (enable) - args[1] = (char*)"start"; - else - args[1] = (char*)"stop"; - args[2] = unit; - - if (enable) - filestream_close(filestream_open(path, - RETRO_VFS_FILE_ACCESS_WRITE, - RETRO_VFS_FILE_ACCESS_HINT_NONE)); - else - filestream_delete(path); + pid_t pid = fork(); + char* args[] = {(char*)"systemctl", + enable ? (char*)"start" : (char*)"stop", + unit, + NULL}; if (pid == 0) + { + if (enable) + filestream_close(filestream_open(path, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE)); + else + filestream_delete(path); + execvp(args[0], args); - - return; + } } -static void ssh_enable_toggle_change_handler(void *data) +static void ssh_enable_toggle_change_handler(rarch_setting_t *setting) { - bool enable = false; - settings_t *settings = config_get_ptr(); - bool ssh_enable = settings ? settings->bools.ssh_enable : false; - - if (ssh_enable) - enable = true; - systemd_service_toggle(LAKKA_SSH_PATH, (char*)"sshd.service", - enable); + *setting->value.target.boolean); } -static void samba_enable_toggle_change_handler(void *data) +static void samba_enable_toggle_change_handler(rarch_setting_t *setting) { - bool enable = false; - settings_t *settings = config_get_ptr(); - bool samba_enable = settings ? settings->bools.samba_enable : false; - - if (samba_enable) - enable = true; - systemd_service_toggle(LAKKA_SAMBA_PATH, (char*)"smbd.service", - enable); + *setting->value.target.boolean); } -static void bluetooth_enable_toggle_change_handler(void *data) +static void bluetooth_enable_toggle_change_handler(rarch_setting_t *setting) { - bool enable = false; - settings_t *settings = config_get_ptr(); - - if (settings && settings->bools.bluetooth_enable) - enable = true; - systemd_service_toggle(LAKKA_BLUETOOTH_PATH, (char*)"bluetooth.service", - enable); + *setting->value.target.boolean); } -static void localap_enable_toggle_change_handler(void *data) +static void localap_enable_toggle_change_handler(rarch_setting_t *setting) { - bool enable = false; - settings_t *settings = config_get_ptr(); - - if (settings && settings->bools.localap_enable) - enable = true; - - driver_wifi_tether_start_stop(enable, LAKKA_LOCALAP_PATH); + driver_wifi_tether_start_stop(*setting->value.target.boolean, + LAKKA_LOCALAP_PATH); } #endif