diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-04 01:14:00 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-04 01:29:43 +0100 |
commit | 8c320bfe295ac1cbd1833d7fba5c54a325875add (patch) | |
tree | 88589ebb027a1cb7ba1e700d5ac3aa01304fd5ec /src/blogc-make/exec.c | |
parent | 4c00812c31dfa42183c8b6586ccf102a6d65f61c (diff) | |
download | blogc-8c320bfe295ac1cbd1833d7fba5c54a325875add.tar.gz blogc-8c320bfe295ac1cbd1833d7fba5c54a325875add.tar.bz2 blogc-8c320bfe295ac1cbd1833d7fba5c54a325875add.zip |
make: implemented lighttpd support to runserver rulefeature/runserver-lighttpd
Diffstat (limited to 'src/blogc-make/exec.c')
-rw-r--r-- | src/blogc-make/exec.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c index 5f508e6..28bab58 100644 --- a/src/blogc-make/exec.c +++ b/src/blogc-make/exec.c @@ -19,6 +19,7 @@ #include "../common/utils.h" #include "ctx.h" #include "exec.h" +#include "lighttpd.h" #include "settings.h" @@ -343,6 +344,38 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port, if (ctx == NULL) return 3; + int rv = 0; + + // check if lighttpd exists + + // we need to mangle path, because lighttpd is usually installed to + // /usr/sbin + char *old_path = getenv("PATH"); + char *path = NULL; + if (old_path != NULL) { + path = bc_strdup_printf("/usr/sbin:%s", path); + setenv("PATH", path, 1); + } + + char *cmd_lighttpd = bc_strdup_printf("%s -v 2> /dev/null > /dev/null", + ctx->lighttpd); + int status_lighttpd = system(cmd_lighttpd); + free(cmd_lighttpd); + + // if it exists, use it! :D + if (127 != WEXITSTATUS(status_lighttpd)) { + char *conf = bm_lighttpd_deploy(ctx->output_dir, host, port); + if (conf == NULL) + return 3; + + cmd_lighttpd = bc_strdup_printf("%s -D -f %s", ctx->lighttpd, conf); + int status = system(cmd_lighttpd); + free(cmd_lighttpd); + bm_lighttpd_destroy(conf); + rv = WEXITSTATUS(status); + goto eval_rv; + } + bc_string_t *cmd = bc_string_new(); bc_string_append(cmd, ctx->blogc_runserver); @@ -377,9 +410,17 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port, // we don't need pipes to run blogc-runserver, because it is "interactive" int status = system(cmd->str); - int rv = WEXITSTATUS(status); + rv = WEXITSTATUS(status); bc_string_free(cmd, true); +eval_rv: + + // cleanup path changes + if (old_path != NULL) { + setenv("PATH", old_path, 1); + free(path); + } + if (rv != 0) { if (rv == 127) { fprintf(stderr, |