diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe0cdc108a0540eec0905a4b9b7d1f345acfa02..599604ab6a82c8efdc76bc32e629c37c249f0494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Add the Klkt client (notification for desktops) to the lektor project - Add AppImage builds for lektord, lkt and klkt - Add basic controls to klkt (play, pause, next, previous, shuffle) +- Add SDL2-Image lib to the dependencies (--with-depends) - Remove archlinux package support (replaced by AppImage) - Fix: the moveid was in fact a move command, no range supported - Bug fix: reduce libs to link to lkt (dear autoconf...) diff --git a/Makefile.in b/Makefile.in index 85fb6f5b649269756bb4da3c6371d4a94823e810..22a5c1c8b33809bccd9779bbb2dcb1be328fd9c6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -290,6 +290,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LKT_APPIMAGETOOL = @LKT_APPIMAGETOOL@ +LKT_ARCH = @LKT_ARCH@ LKT_BUILD_STRING = @LKT_BUILD_STRING@ LKT_COMPILER = @LKT_COMPILER@ LKT_DEBUG_ENABLED = @LKT_DEBUG_ENABLED@ diff --git a/configure b/configure index 120382cb8c91e0aee9b6c85abb33543a9b57117f..d3c9d4021c3c16ea75e5b3f49a5b93185736cef1 100755 --- a/configure +++ b/configure @@ -642,6 +642,7 @@ LKT_DEPENDS_ENABLE_TRUE LKT_ENDIANES_BIG LKT_ENDIANES_LITTLE LKT_BUILD_STRING +LKT_ARCH LKT_COMPILER LKT_MAN_BINARY LKT_PREFIX_PATH @@ -18495,6 +18496,13 @@ _ACEOF + +cat >>confdefs.h <<_ACEOF +#define LKT_ARCH "$(arch)" +_ACEOF + + + LKT_BUILD_STRING="$(basename $CC)/$(basename $CXX) $(uname -s) $(uname -p) $(uname -r) $(uname -m)" cat >>confdefs.h <<_ACEOF diff --git a/configure.ac b/configure.ac index 62969ad26720b0aaa341ade5011eecc5fd36e657..d7133fc1c3894faf082be1e403ea3cfc622f3e06 100644 --- a/configure.ac +++ b/configure.ac @@ -224,6 +224,9 @@ AC_SUBST([LKT_MAN_BINARY]) AC_DEFINE_UNQUOTED([LKT_COMPILER], ["$CC"], [Lektor compiled with]) AC_SUBST([LKT_COMPILER]) +AC_DEFINE_UNQUOTED([LKT_ARCH], ["$(arch)"], [Host architecture]) +AC_SUBST([LKT_ARCH]) + LKT_BUILD_STRING="$(basename $CC)/$(basename $CXX) $(uname -s) $(uname -p) $(uname -r) $(uname -m)" AC_DEFINE_UNQUOTED([LKT_BUILD_STRING], ["$LKT_BUILD_STRING"], [Build string]) AC_SUBST([LKT_BUILD_STRING]) diff --git a/inc/Makefile.in b/inc/Makefile.in index f8b473da92cb78ccdb95c586d79ff91a80807f85..7e75d8ff3f04977c095f548452b5cfa6c4b60180 100644 --- a/inc/Makefile.in +++ b/inc/Makefile.in @@ -220,6 +220,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LKT_APPIMAGETOOL = @LKT_APPIMAGETOOL@ +LKT_ARCH = @LKT_ARCH@ LKT_BUILD_STRING = @LKT_BUILD_STRING@ LKT_COMPILER = @LKT_COMPILER@ LKT_DEBUG_ENABLED = @LKT_DEBUG_ENABLED@ diff --git a/inc/lektor/config.def b/inc/lektor/config.def index e16bbe2c3e319e4a9a0a6467d48942333b03e021..b0c3938f632a0e8f9142c88a3da5d1c6072245b3 100644 --- a/inc/lektor/config.def +++ b/inc/lektor/config.def @@ -1,4 +1,4 @@ -value_opt("log", "INFO") /* Can be DEBUG, INFO, WARN, ERROR */ +value_opt("log", "INFO") /* Can be DEBUG, INFO, WARN, ERROR */ /* * EXTERNALS @@ -81,4 +81,7 @@ value("kara_load", "none") /* Before a kara is loaded to be played, 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. */ +value_opt("launch_klkt", "0") + // vi:syntax=c diff --git a/inc/lektor/lktconfig.h.in b/inc/lektor/lktconfig.h.in index 46e6ea53e33b59afc8509f98136cf8c207f99129..5659c2dfd8183a38441f3bc8bdfc80b52184c6b6 100644 --- a/inc/lektor/lktconfig.h.in +++ b/inc/lektor/lktconfig.h.in @@ -57,6 +57,9 @@ /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H +/* Host architecture */ +#undef LKT_ARCH + /* Build string */ #undef LKT_BUILD_STRING diff --git a/inc/lektor/queue.h b/inc/lektor/queue.h index 5a518ba1cb23234a28fa53a8afd088521238fde3..d5bfe332997c214d8edb9b511f518f92bcfd79ba 100644 --- a/inc/lektor/queue.h +++ b/inc/lektor/queue.h @@ -1,6 +1,9 @@ #if ! defined(__LKT_QUEUE_H__) #define __LKT_QUEUE_H__ + +#if ! defined(_POSIX_C_SOURCE) #define _POSIX_C_SOURCE 200809L +#endif /* Everything in this file is implemented in the header, so that modules don't have to compile the lib with another .c file. */ diff --git a/man/Makefile.in b/man/Makefile.in index 97a4f75754ce66dde9fffad0f517ee868632b1e0..d592c364a75e911ea817f5be63b8c693581de856 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -202,6 +202,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LKT_APPIMAGETOOL = @LKT_APPIMAGETOOL@ +LKT_ARCH = @LKT_ARCH@ LKT_BUILD_STRING = @LKT_BUILD_STRING@ LKT_COMPILER = @LKT_COMPILER@ LKT_DEBUG_ENABLED = @LKT_DEBUG_ENABLED@ diff --git a/src/Makefile.in b/src/Makefile.in index 97663fc4b9f8269c285296e43a50a9bffa058fce..56f1fbc8cb85751d38d5a28028d3ab908674c011 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -434,6 +434,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LKT_APPIMAGETOOL = @LKT_APPIMAGETOOL@ +LKT_ARCH = @LKT_ARCH@ LKT_BUILD_STRING = @LKT_BUILD_STRING@ LKT_COMPILER = @LKT_COMPILER@ LKT_DEBUG_ENABLED = @LKT_DEBUG_ENABLED@ diff --git a/src/base/common.c b/src/base/common.c index ef1a4afee6929f8186417f6e7c1be87e9fbe697c..104ae17427af90c35e0e90511aad903140fb299a 100644 --- a/src/base/common.c +++ b/src/base/common.c @@ -271,9 +271,9 @@ safe_zero_malloc(size_t size) int read_self_exe(char *path, size_t len) { - return ! (readlink(SELF_EXECUTABLE_LINUX, path, len - 1) > 0) || - (readlink(SELF_EXECUTABLE_FREEBSD, path, len - 1) > 0) || - (readlink(SELF_EXECUTABLE_SOLARIS, path, len - 1) > 0); + return ! ((readlink(SELF_EXECUTABLE_LINUX, path, len - 1) > 0) + || (readlink(SELF_EXECUTABLE_FREEBSD, path, len - 1) > 0) + || (readlink(SELF_EXECUTABLE_SOLARIS, path, len - 1) > 0)); } int diff --git a/src/main/server.c b/src/main/server.c index 8e36dffa75cafb34649b6d7bea11bbe2c75f9afc..f1c4215a683feed7a666d8676edece90b223959b 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -1,4 +1,4 @@ -#define _POSIX_C_SOURCE 200809L +#define _POSIX_C_SOURCE 200808L #include <lektor/lktconfig.h> #include <lektor/common.h> @@ -10,6 +10,9 @@ #include <lektor/commands.h> #include <lektor/segv.h> +#include <spawn.h> +#include <libgen.h> +#include <limits.h> #include <locale.h> #include <signal.h> #include <stdio.h> @@ -26,6 +29,9 @@ REG_DECLARE(repo_reg) #endif +/* The environment */ +extern char **environ; + /* Disable echo in the console, only for the program */ struct termios ___tty_cur, ___tty_save; @@ -81,6 +87,63 @@ __mkdir(const char *dir) * mkdir(tmp, S_IRWXU); */ } +/* Exec an other program wthout any argument */ +static pid_t ___klkt_pid = 0; +static inline void +__launch_klkt(void) +{ + /* Patch PATH to first search the basedir */ + char exe_path[LKT_LINE_MAX]; + char try_name[LKT_LINE_MAX]; + const char *const appimage = getenv("APPIMAGE"); + char *args[] = { "klkt", NULL }; + static const char *basename_appimage_arch = "klkt.AppImage"; + static const char *basename_appimage_no_arch = "klkt-" LKT_ARCH ".AppImage"; + + if (appimage == NULL) { + /* No AppImage */ + if (read_self_exe(exe_path, LKT_LINE_MAX)) { + LOG_ERROR("GENERAL", "Failed to get the current executable path, not patching the PATH"); + return; + } + } else { + /* AppImage */ + safe_strncpy(exe_path, appimage, LKT_LINE_MAX); + LOG_DEBUG("GENERAL", "Running an AppImage, file is %s", appimage); + } + + char *current_dir = dirname(exe_path); + + /* Normal try */ + errno = 0; + safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt", current_dir); + if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { + LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); + return; + } + + /* AppImage try */ + safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt-" LKT_ARCH ".AppImage", current_dir); + errno = 0; + args[0] = (char *) basename_appimage_arch; + if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { + LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); + return; + } + + safe_snprintf(try_name, LKT_LINE_MAX, "%s/klkt.AppImage", current_dir); + errno = 0; + args[0] = (char *) basename_appimage_no_arch; + if (posix_spawn(&___klkt_pid, try_name, NULL, NULL, args, environ) == 0) { + LOG_INFO("GENERAL", "Klkt launched with pid %ld with from %s", ___klkt_pid, try_name); + return; + } + + /* Oupsi */ + 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 */ +} + int main(int argc, char *argv[]) { @@ -186,6 +249,12 @@ retry_config: /* No longer need the config 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 */ database_config_get(srv.db, "player", "autoclear", &autoclear); database_config_get(srv.db, "database", "kara_dir", kara_dir, PATH_MAX);