From 633f43164d8245e388a71ab499aff4b3b2b79ceb Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 13 May 2018 18:24:57 +0200 Subject: make: git-receiver: fixed conversion from wait status to status code --- Makefile.am | 2 ++ src/blogc-git-receiver/pre-receive.c | 7 ++++--- src/blogc-make/exec.c | 5 +++-- src/blogc-runserver/main.c | 2 +- src/common/compat.c | 39 ++++++++++++++++++++++++++++++++++++ src/common/compat.h | 14 +++++++++++++ 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/common/compat.c create mode 100644 src/common/compat.h 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 #include #include +#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 #include #include +#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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_SYS_WAIT_H +#include +#endif /* HAVE_SYS_WAIT_H */ + +#include +#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 + * + * 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 */ -- cgit v1.2.3-18-g5258