diff --git a/inc/common/macro.h b/inc/common/macro.h index 1ba00aa134172feef27e329bad2c29a9d6d0e674..da56e358042a2cbb3ce8579e1ac7fffdf0ef58d9 100644 --- a/inc/common/macro.h +++ b/inc/common/macro.h @@ -75,6 +75,9 @@ #define SELF_EXECUTABLE_FREEBSD "/proc/curproc/file" #define SELF_EXECUTABLE_SOLARIS "/proc/self/path/a.out" +#define LKT_ENV_RESTART "__LKT_RESTART" +#define LKT_ENV_CURRENT "__LKT_CURRENT" + #define LKT_MAX_SQLITE_STATEMENT 1024 #define PROTECTED_DATABASE "disk" diff --git a/inc/lektor/config.h b/inc/lektor/config.h index 22c200b1ef6d88e7d6794ce6c179b2c5eb722746..e8c89482a50c989160967634937b73d8c3f132f1 100644 --- a/inc/lektor/config.h +++ b/inc/lektor/config.h @@ -35,3 +35,7 @@ int config_new(volatile sqlite3 *db, const char *conf); /* Prints the default config file. */ void config_default(FILE *output); + +/* Manipulate Environment Variables */ +#define env_set(var, val) setenv(var, val, 1) +#define env_get getenv diff --git a/src/commands.c b/src/commands.c index 9ad34084ef1317c2dadf1b3ef0b0e2488e2a49b6..f4f0c7cfca956bc828b9ebc2ab59a5685551a85c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -23,12 +23,27 @@ inline bool command_restart(struct lkt_state *srv, size_t c) { const char *const argv[] = { executable_name, NULL }; + struct lkt_queue_state sta = {0}; RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); if (!executable_name) { LOG_ERROR_SCT("GENERAL", "%s", "Can't restart if the executable path was not found at start-up"); return false; } close(srv->fds[0].fd); + database_queue_state(srv->db, &sta); + env_set(LKT_ENV_RESTART, "1"); + int len = long_length(sta.current); + if (len > 0) { + char *pos = calloc(len, sizeof(char)); + if (pos) { + safe_snprintf(pos, len, "%d", sta.current); + env_set(LKT_ENV_CURRENT, pos); + free(pos); + } else + LOG_WARN_SCT("GENERAL", "Failed to malloc, don't set %s to %d", + LKT_ENV_CURRENT, sta.current); + } else + env_set(LKT_ENV_CURRENT, "NULL"); database_close_all(); execv(executable_name, (char *const *) argv); LOG_ERROR_SCT("GENERAL", "%s", "Failed to exec lektor or OS not supported");