aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/blogc-make/exec.c52
-rw-r--r--tests/blogc-make/check_exec.c12
2 files changed, 47 insertions, 17 deletions
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index bb0a323..ee86f15 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -184,7 +184,9 @@ bm_exec_build_blogc_cmd(bm_settings_t *settings, bc_trie_t *variables,
// use blogc binary from environment, if provided
const char *blogc_bin = getenv("BLOGC");
if (blogc_bin != NULL) {
- bc_string_append(rv, blogc_bin);
+ char *tmp = bc_shell_quote(blogc_bin);
+ bc_string_append(rv, tmp);
+ free(tmp);
}
else {
bc_string_append(rv, "blogc");
@@ -305,25 +307,53 @@ bm_exec_blogc(bm_settings_t *settings, bc_trie_t *variables, bool listing,
int
bm_exec_blogc_runserver(bm_settings_t *settings, bool verbose)
{
- // use blogc binary from environment, if provided
+ bc_string_t *cmd = bc_string_new();
+
+ // use blogc-runserver binary from environment, if provided
const char *blogc_runserver = getenv("BLOGC_RUNSERVER");
+ if (blogc_runserver != NULL) {
+ char *tmp = bc_shell_quote(blogc_runserver);
+ bc_string_append(cmd, tmp);
+ free(tmp);
+ }
+ else {
+ bc_string_append(cmd, "blogc-runserver");
+ }
- char *cmd = bc_strdup_printf("%s -t %s -p %s -m %s %s",
- blogc_runserver != NULL ? blogc_runserver : "blogc-runserver",
- bc_trie_lookup(settings->settings, "runserver_host"),
- bc_trie_lookup(settings->settings, "runserver_port"),
- bc_trie_lookup(settings->settings, "runserver_threads"),
- bc_trie_lookup(settings->settings, "output_dir"));
+ const char *runserver_host_tmp = getenv("RUNSERVER_HOST");
+ if (runserver_host_tmp != NULL) {
+ char *tmp = bc_shell_quote(runserver_host_tmp);
+ bc_string_append_printf(cmd, " -t %s", tmp);
+ free(tmp);
+ }
+
+ const char *runserver_port_tmp = getenv("RUNSERVER_PORT");
+ if (runserver_port_tmp != NULL) {
+ char *tmp = bc_shell_quote(runserver_port_tmp);
+ bc_string_append_printf(cmd, " -p %s", tmp);
+ free(tmp);
+ }
+
+ const char *runserver_threads_tmp = getenv("RUNSERVER_THREADS");
+ if (runserver_threads_tmp != NULL) {
+ char *tmp = bc_shell_quote(runserver_threads_tmp);
+ bc_string_append_printf(cmd, " -m %s", tmp);
+ free(tmp);
+ }
+
+ char *tmp = bc_shell_quote(bc_trie_lookup(settings->settings, "output_dir"));
+ bc_string_append_printf(cmd, " %s", tmp);
+ free(tmp);
if (verbose)
- printf("%s\n", cmd);
+ printf("%s\n", cmd->str);
else
printf("\n");
fflush(stdout);
// we don't need pipes to run blogc-runserver, because it is "interactive"
- int rv = WEXITSTATUS(system(cmd));
- free(cmd);
+ int rv = WEXITSTATUS(system(cmd->str));
+ bc_string_free(cmd, true);
if (rv != 0) {
if (rv == 127) {
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index ce87f09..6b5ca9e 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -55,19 +55,19 @@ test_build_blogc_cmd_with_settings(void **state)
rv = bm_exec_build_blogc_cmd(settings, variables, true, "main.tmpl",
"foo.html", true);
assert_string_equal(rv,
- "LC_ALL='en_US.utf8' /path/to/blogc -D FOO='BAR' -D BAR='BAZ' "
+ "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ' "
"-D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
rv = bm_exec_build_blogc_cmd(settings, variables, false, NULL, NULL, false);
assert_string_equal(rv,
- "LC_ALL='en_US.utf8' /path/to/blogc -D FOO='BAR' -D BAR='BAZ' "
+ "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ' "
"-D LOL='HEHE'");
free(rv);
rv = bm_exec_build_blogc_cmd(settings, NULL, false, NULL, NULL, false);
assert_string_equal(rv,
- "LC_ALL='en_US.utf8' /path/to/blogc -D FOO='BAR' -D BAR='BAZ'");
+ "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ'");
free(rv);
unsetenv("BLOGC");
@@ -108,17 +108,17 @@ test_build_blogc_cmd_without_settings(void **state)
rv = bm_exec_build_blogc_cmd(NULL, variables, true, "main.tmpl", "foo.html",
true);
assert_string_equal(rv,
- "/path/to/blogc -D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i");
+ "'/path/to/blogc' -D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i");
free(rv);
rv = bm_exec_build_blogc_cmd(NULL, variables, false, NULL, NULL, false);
assert_string_equal(rv,
- "/path/to/blogc -D LOL='HEHE'");
+ "'/path/to/blogc' -D LOL='HEHE'");
free(rv);
rv = bm_exec_build_blogc_cmd(NULL, NULL, false, NULL, NULL, false);
assert_string_equal(rv,
- "/path/to/blogc");
+ "'/path/to/blogc'");
free(rv);
unsetenv("BLOGC");