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

KLKT: Don't mix klkt and lektord logs

parent 62a3486e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!140Auto klkt
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <lektor/commands.h> #include <lektor/commands.h>
#include <lektor/segv.h> #include <lektor/segv.h>
#include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
#include <wait.h> #include <wait.h>
#include <spawn.h> #include <spawn.h>
...@@ -92,7 +93,7 @@ __mkdir(const char *dir) ...@@ -92,7 +93,7 @@ __mkdir(const char *dir)
/* Exec an other program wthout any argument */ /* Exec an other program wthout any argument */
static pid_t ___klkt_pid = 0; static pid_t ___klkt_pid = 0;
__attribute__((constructor)) static inline void __attribute__((destructor)) static inline void
___kill_klkt(void) ___kill_klkt(void)
{ {
RETURN_UNLESS(___kill_klkt, "No klkt child process to wait for", NOTHING) RETURN_UNLESS(___kill_klkt, "No klkt child process to wait for", NOTHING)
...@@ -133,6 +134,11 @@ __launch_klkt(void) ...@@ -133,6 +134,11 @@ __launch_klkt(void)
static const char *basename_appimage_arch = "klkt.AppImage"; static const char *basename_appimage_arch = "klkt.AppImage";
static const char *basename_appimage_no_arch = "klkt-" LKT_ARCH ".AppImage"; static const char *basename_appimage_no_arch = "klkt-" LKT_ARCH ".AppImage";
posix_spawn_file_actions_t action;
posix_spawn_file_actions_init(&action);
posix_spawn_file_actions_addopen(&action, STDOUT_FILENO, "/dev/null", O_RDONLY, 0);
posix_spawn_file_actions_addopen(&action, STDERR_FILENO, "/dev/null", O_RDONLY, 0);
if (appimage == NULL) { if (appimage == NULL) {
/* No AppImage */ /* No AppImage */
if (read_self_exe(exe_path, LKT_LINE_MAX)) { if (read_self_exe(exe_path, LKT_LINE_MAX)) {
...@@ -150,31 +156,29 @@ __launch_klkt(void) ...@@ -150,31 +156,29 @@ __launch_klkt(void)
/* Normal try */ /* Normal try */
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);
if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end);
return;
}
/* 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;
if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end);
return;
}
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;
if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { LOG_DEBUG("GENERAL", "Try to launch klkt with file %s", try_name);
LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); GOTO_UNLESS(posix_spawn(&___klkt_pid, try_name, &action, NULL, args, environ), "Klkt launched!", end);
return;
}
/* Oupsi */ /* Oupsi */
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 */
end:
LOG_INFO("GENERAL", "Klkt launched with pid %ld", ___klkt_pid, try_name);
posix_spawn_file_actions_destroy(&action);
} }
int int
......
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