(Lakka) Control systemd services. Touching the files was not enough.

This commit is contained in:
Jean-André Santoni 2016-04-25 15:49:25 +07:00
parent 78d48c53d2
commit a6acc7b31b

View File

@ -57,6 +57,11 @@
#include "../tasks/tasks_internal.h" #include "../tasks/tasks_internal.h"
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
struct rarch_setting_info struct rarch_setting_info
{ {
@ -3068,34 +3073,44 @@ static void overlay_enable_toggle_change_handler(void *data)
#endif #endif
#ifdef HAVE_LAKKA #ifdef HAVE_LAKKA
void lakka_service_toggle(const char *path, char *unit, bool enable)
void lakka_service_toggle(const char *path, bool enable)
{ {
int pid = fork();
char* args[] = {"systemctl", NULL, NULL, NULL};
args[1] = enable ? "start" : "stop";
args[2] = unit;
if (enable) if (enable)
fclose(fopen(path, "w")); fclose(fopen(path, "w"));
else else
remove(path); remove(path);
if (pid == 0) {
execvp(args[0], args);
}
return; return;
} }
static void ssh_enable_toggle_change_handler(void *data) static void ssh_enable_toggle_change_handler(void *data)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
lakka_service_toggle(LAKKA_SSH_PATH, lakka_service_toggle(LAKKA_SSH_PATH, "sshd.service",
settings && settings->ssh_enable); settings && settings->ssh_enable);
return; return;
} }
static void samba_enable_toggle_change_handler(void *data) static void samba_enable_toggle_change_handler(void *data)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
lakka_service_toggle(LAKKA_SAMBA_PATH, lakka_service_toggle(LAKKA_SAMBA_PATH, "smbd.service",
settings && settings->samba_enable); settings && settings->samba_enable);
return; return;
} }
static void bluetooth_enable_toggle_change_handler(void *data) static void bluetooth_enable_toggle_change_handler(void *data)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
lakka_service_toggle(LAKKA_BLUETOOTH_PATH, lakka_service_toggle(LAKKA_BLUETOOTH_PATH, "bluetooth.service",
settings && settings->bluetooth_enable); settings && settings->bluetooth_enable);
return; return;
} }