diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive.c | 7 | ||||
-rw-r--r-- | src/blogc-make/exec.c | 5 | ||||
-rw-r--r-- | src/blogc-runserver/main.c | 2 | ||||
-rw-r--r-- | src/common/compat.c | 39 | ||||
-rw-r--r-- | src/common/compat.h | 14 |
6 files changed, 63 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index f6a5ce3..29c65d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,6 +61,7 @@ noinst_HEADERS = \ src/blogc-runserver/httpd.h \ src/blogc-runserver/httpd-utils.h \ src/blogc-runserver/mime.h \ + src/common/compat.h \ src/common/config-parser.h \ src/common/error.h \ src/common/file.h \ @@ -139,6 +140,7 @@ libblogc_la_LIBADD = \ libblogc_common_la_SOURCES = \ + src/common/compat.c \ src/common/config-parser.c \ src/common/error.c \ src/common/file.c \ diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c index e8ac1d3..b059753 100644 --- a/src/blogc-git-receiver/pre-receive.c +++ b/src/blogc-git-receiver/pre-receive.c @@ -15,6 +15,7 @@ #include <dirent.h> #include <time.h> #include <libgen.h> +#include "../common/compat.h" #include "../common/utils.h" #include "../common/stdin.h" #include "pre-receive-parser.h" @@ -197,7 +198,7 @@ bgr_pre_receive_hook(int argc, char *argv[]) char *build_cmd = NULL; if (0 == access("blogcfile", F_OK)) { int status_bmake = system("blogc-make -v 2> /dev/null > /dev/null"); - if (127 == WEXITSTATUS(status_bmake)) { + if (127 == bc_compat_status_code(status_bmake)) { fprintf(stderr, "error: failed to find blogc-make binary\n"); rv = 3; goto cleanup; @@ -209,12 +210,12 @@ bgr_pre_receive_hook(int argc, char *argv[]) const char *make_impl = NULL; int status_gmake = system("gmake -f /dev/null 2> /dev/null > /dev/null"); - if (127 != WEXITSTATUS(status_gmake)) { + if (127 != bc_compat_status_code(status_gmake)) { make_impl = "gmake"; } else { int status_make = system("make -f /dev/null 2> /dev/null > /dev/null"); - if (127 != WEXITSTATUS(status_make)) { + if (127 != bc_compat_status_code(status_make)) { make_impl = "make"; } } diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c index aaae523..49c46a2 100644 --- a/src/blogc-make/exec.c +++ b/src/blogc-make/exec.c @@ -18,6 +18,7 @@ #include <sys/wait.h> #include <errno.h> #include <libgen.h> +#include "../common/compat.h" #include "../common/error.h" #include "../common/file.h" #include "../common/utils.h" @@ -202,7 +203,7 @@ bm_exec_command(const char *cmd, const char *input, char **output, int status; waitpid(pid, &status, 0); - return WEXITSTATUS(status); + return bc_compat_status_code(status); } @@ -402,7 +403,7 @@ 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); + int rv = bc_compat_status_code(status); bc_string_free(cmd, true); if (rv != 0 && rv != 130) { diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c index b9b831a..1b2df26 100644 --- a/src/blogc-runserver/main.c +++ b/src/blogc-runserver/main.c @@ -55,7 +55,7 @@ int main(int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - signal(SIGINT, sigint_handler); + //signal(SIGINT, sigint_handler); int rv = 0; char *host = NULL; diff --git a/src/common/compat.c b/src/common/compat.c new file mode 100644 index 0000000..f7394c8 --- /dev/null +++ b/src/common/compat.c @@ -0,0 +1,39 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif /* HAVE_SYS_WAIT_H */ + +#include <signal.h> +#include "compat.h" + + +int +bc_compat_status_code(int waitstatus) +{ + int rv = waitstatus; +#if defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && defined(WTERMSIG) + if (WIFEXITED(waitstatus)) { + rv = WEXITSTATUS(waitstatus); + } + else if (WIFSIGNALED(waitstatus)) { + rv = WTERMSIG(waitstatus); + rv += 128; + } +#elif defined(WIN32) || defined(_WIN32) + if (waitstatus == 3) { + rv = SIGTERM + 128; // can't get signal on windows. + } +#endif + return rv; +} diff --git a/src/common/compat.h b/src/common/compat.h new file mode 100644 index 0000000..021dc6e --- /dev/null +++ b/src/common/compat.h @@ -0,0 +1,14 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifndef _COMPAT_H +#define _COMPAT_H + +int bc_compat_status_code(int waitstatus); + +#endif /* _COMPAT_H */ |