Skip to content
Extraits de code Groupes Projets
Vérifiée Valider d2dc6a52 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

KLKT: Add a launched hook and add the function 'launch_klkt' in the server's register

parent 12973176
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!140Auto klkt
value_opt("log", "INFO") /* Can be DEBUG, INFO, WARN, ERROR */ /* The comment, you can overlod it, or not, as you wish.
* Only 'section' and 'value' are mendatory, but you might
* want to define 'value_opt'... */
#if ! defined (comment)
#define comment(...)
#endif
#if ! defined (value_opt)
#define value_opt(...)
#endif
/* comment("Can be DEBUG, INFO, WARN, ERROR.")
* EXTERNALS value_opt("log", "INFO")
*
* Used to find external programs. */ /* EXTERNALS */
comment("All specified programs in this section must exists!")
section("externals") section("externals")
value("mkvpropedit", "/usr/bin/mkvpropedit") value("mkvpropedit", "/usr/bin/mkvpropedit")
/* /* SERVER */
* SERVER
*
* Configure the server. */
section("server") section("server")
value("max_clients", "16") value("max_clients", "16")
value("host", "0.0.0.0") value("host", "0.0.0.0")
value("port", "6600") /* Must be 'unix' for Unix sockets. In that
* case, the 'host' will be treated as a file.
* If it already exists there will be an error */
/* Only used when 'port == "unix"', this is an octal. */ comment("If the 'port' is set to 'unix', 'host' will be treated as a file and lektord will listen on that socket.")
comment("If it already exists there will be an error.")
value("port", "6600")
comment("The 'permission' is only used when 'port' is set to 'unix'")
value_opt("permission", "0600") value_opt("permission", "0600")
/* /* DATABASE */
* DATABASE
*
* The database, the local thing where all karas will be stored. */
section("database") section("database")
value("kara_dir", "/home/kara") /* All the folder and sub folder comment("All the folders and subfolders in 'kara_dir' must be on the same filesystem.")
* must be on the same partition */ value("kara_dir", "/home/kara")
value("db_path", "/home/kara/kara.db") value("db_path", "/home/kara/kara.db")
/* /* MODULE: REPO */
* MODULE: REPO comment("The repo module, here to be able to sync the bakabase with kurisu or any other server, if configured correctly.")
*
* The repo module, here to be able to sync the bakabase with kurisu or
* any other server, if configured correctly */
section("repo") section("repo")
value("obfuscate", "1") value("obfuscate", "1")
value("module", "repo") value("module", "repo")
...@@ -47,12 +48,9 @@ value("id_kara", "https://kurisu.iiens.net/api/download/%ld") ...@@ -47,12 +48,9 @@ value("id_kara", "https://kurisu.iiens.net/api/download/%ld")
value("fav_json", "https://kurisu.iiens.net/api/fav/") value("fav_json", "https://kurisu.iiens.net/api/fav/")
value("plt_json", "https://kurisu.iiens.net/api/plt/") value("plt_json", "https://kurisu.iiens.net/api/plt/")
/* /* MODULE: PLAYER */
* MODULE: PLAYER comment("The player module, so that people can 'sing' when using lektor.")
* comment("By default it's sdl, but one can create any module, for audio support only for example.")
* The player module, so that people can 'sing' when using lektor. By
* default it's sdl, but one can create any module, for audio support
* only for example. */
section("player") section("player")
value("module", "sdl2") value("module", "sdl2")
value("autoclear", "true") value("autoclear", "true")
...@@ -63,25 +61,31 @@ value("def_repeat", "false") ...@@ -63,25 +61,31 @@ value("def_repeat", "false")
value("font_size", "20") value("font_size", "20")
value("font_name", "Hack Nerd Font") value("font_name", "Hack Nerd Font")
value("msg_duration", "4") value("msg_duration", "4")
value_opt("force_x11", "1") /* Force libmpv to use x11, may segfault on some PCs... */ comment("'force_x11' will be used to force libmpv to use the x11 context, may segfault on some PCs...")
/* HOOK */
comment("To place hooks, when some things are done in lektor.")
comment("The default value 'none' is here so that nothing happens.")
comment("Like any module, the value can point to a module or a function in the internal register.")
comment("To specify multiple modules, use a comma separated list, line this:")
comment("`kara_load = print_stdout,print_stderr`.")
comment("For the moment, only functions in the server register are supported.")
comment("NOTE: All the functions will recieve a va_list as a unique argument.")
/*
* HOOK
*
* To place hooks, when some things are done in lektor. The default value
* 'none' is here so that nothing happens. Like any module, the value can point
* to a module or a function in the internal register. To specify multiple
* modules, use a comma separated list, line this: `kara_load = print_stdout,
* print_stderr`. For the moment, only functions in the server register are
* supported.
* NOTE: All the functions will recieve a va_list as a unique argument. */
section("hook") section("hook")
value("kara_load", "none") /* Before a kara is loaded to be played,
* the 'player' module needs to support it */
value("queue_begin", "none") /* On play, when the player is not already playing
* or paused */
/* 0 for False, anything else for True. Launch klkt when starting lektord. */ comment("kara_load: Before a kara is loaded to be played, the 'player' module needs to support it")
value_opt("launch_klkt", "0") value("kara_load", "none")
comment("queue_begin: On play, when the player is not already playing or paused")
value("queue_begin", "none")
comment("launched: Configuration has been loaded, lektord is not currently listening for clients.")
comment("All the modules needed (player, repo) has been created")
value("launched", "none")
comment("The available hooks are the followings:")
comment(" - none: nothing, the hook is ignored")
comment(" - launch_klkt: launch klkt, note that it will be automatically killed when lektord exits")
// vi:syntax=c // vi:syntax=c
...@@ -106,9 +106,8 @@ ___kill_klkt(void) ...@@ -106,9 +106,8 @@ ___kill_klkt(void)
int status; int status;
do { do {
if (waitpid(___klkt_pid, &status, WUNTRACED | WCONTINUED) == -1) { if (waitpid(___klkt_pid, &status, WUNTRACED | WCONTINUED) == -1)
LOG_ERROR("GENERAL", "Failed to wait for child klkt with pid %ld", ___klkt_pid); LOG_ERROR("GENERAL", "Failed to wait for child klkt with pid %ld", ___klkt_pid);
}
LOG_INFO("GENERAL", "Child klkt status is %s%d", LOG_INFO("GENERAL", "Child klkt status is %s%d",
/* String desc */ /* String desc */
...@@ -123,8 +122,8 @@ ___kill_klkt(void) ...@@ -123,8 +122,8 @@ ___kill_klkt(void)
} while (!WIFEXITED(status) && !WIFSIGNALED(status)); } while (!WIFEXITED(status) && !WIFSIGNALED(status));
} }
static inline void static inline int
__launch_klkt(void) launch_klkt(va_list UNUSED *___args)
{ {
/* Patch PATH to first search the basedir */ /* Patch PATH to first search the basedir */
char exe_path[LKT_LINE_MAX]; char exe_path[LKT_LINE_MAX];
...@@ -143,7 +142,7 @@ __launch_klkt(void) ...@@ -143,7 +142,7 @@ __launch_klkt(void)
/* No AppImage */ /* No AppImage */
if (read_self_exe(exe_path, LKT_LINE_MAX)) { if (read_self_exe(exe_path, LKT_LINE_MAX)) {
LOG_ERROR("GENERAL", "Failed to get the current executable path, not patching the PATH"); LOG_ERROR("GENERAL", "Failed to get the current executable path, not patching the PATH");
return; goto error;
} }
} else { } else {
/* AppImage */ /* AppImage */
...@@ -157,28 +156,34 @@ __launch_klkt(void) ...@@ -157,28 +156,34 @@ __launch_klkt(void)
errno = 0; errno = 0;
safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt", current_dir); safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt", current_dir);
LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name); LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ),
"Klkt launched!", end);
/* AppImage try */ /* AppImage try */
safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt-" LKT_ARCH ".AppImage", current_dir); safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt-" LKT_ARCH ".AppImage", current_dir);
errno = 0; errno = 0;
args[0] = (char *) basename_appimage_arch; args[0] = (char *) basename_appimage_arch;
LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name); LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ),
"Klkt launched!", end);
safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt.AppImage", current_dir); safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt.AppImage", current_dir);
errno = 0; errno = 0;
args[0] = (char *) basename_appimage_no_arch; args[0] = (char *) basename_appimage_no_arch;
LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name); LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ),
"Klkt launched!", end);
/* Oupsi */ /* Oupsi */
error:
LOG_ERROR("GENERAL", "Failed to spawn klkt (%s): %s", try_name, strerror(errno)); LOG_ERROR("GENERAL", "Failed to spawn klkt (%s): %s", try_name, strerror(errno));
___klkt_pid = 0; /* posix_spawnp may have modified it even in case of failure */ ___klkt_pid = 0; /* posix_spawnp may have modified it even in case of failure */
return 1;
end: end:
LOG_INFO("GENERAL", "Klkt launched with pid %ld", ___klkt_pid, try_name); LOG_INFO("GENERAL", "Klkt launched with pid %ld", ___klkt_pid, try_name);
posix_spawn_file_actions_destroy(&action); posix_spawn_file_actions_destroy(&action);
return 0;
} }
int int
...@@ -187,6 +192,7 @@ main(int argc, char *argv[]) ...@@ -187,6 +192,7 @@ main(int argc, char *argv[])
install_segv_handler(); install_segv_handler();
REG_BEGIN(server_reg) REG_BEGIN(server_reg)
REG_ADD(launch_klkt)
#if defined (LKT_STATIC_MODULE) #if defined (LKT_STATIC_MODULE)
REG_REGISTER("repo", repo_reg) REG_REGISTER("repo", repo_reg)
REG_REGISTER("sdl2", sdl2_reg) REG_REGISTER("sdl2", sdl2_reg)
...@@ -286,12 +292,6 @@ retry_config: ...@@ -286,12 +292,6 @@ retry_config:
/* No longer need the config file */ /* No longer need the config file */
free(conf_file); free(conf_file);
/* Launch Klkt if specified by the configuration */
int launch_klkt = 0;
database_config_get(srv.db, "hook", "launch_klkt", &launch_klkt);
if (launch_klkt)
__launch_klkt();
/* Read the configuration. We already know that the config is valid */ /* Read the configuration. We already know that the config is valid */
database_config_get(srv.db, "player", "autoclear", &autoclear); database_config_get(srv.db, "player", "autoclear", &autoclear);
database_config_get(srv.db, "database", "kara_dir", kara_dir, PATH_MAX); database_config_get(srv.db, "database", "kara_dir", kara_dir, PATH_MAX);
...@@ -350,6 +350,7 @@ retry_config: ...@@ -350,6 +350,7 @@ retry_config:
LOG_INFO("GENERAL", "Lektor was %s", LOG_INFO("GENERAL", "Lektor was %s",
env_get(LKT_ENV_RESTART) ? "restarted" : "started"); env_get(LKT_ENV_RESTART) ? "restarted" : "started");
config_handle_hook(srv.db, "launched");
lkt_listen(&srv); lkt_listen(&srv);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter