aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-03-28 19:57:12 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-03-28 19:57:12 +0100
commit81acc30ee998ce7eb05df0e4216b3d994a5b30f2 (patch)
tree3ed29e9c821256e8654819e9ae611f5b683425df
parenta7d888e158104ee7993921687457dc3b4ddd6c4b (diff)
downloadblogc-81acc30ee998ce7eb05df0e4216b3d994a5b30f2.tar.gz
blogc-81acc30ee998ce7eb05df0e4216b3d994a5b30f2.tar.bz2
blogc-81acc30ee998ce7eb05df0e4216b3d994a5b30f2.zip
git-receiver: exit 1 on error
-rw-r--r--src/blogc-git-receiver/main.c4
-rw-r--r--src/blogc-git-receiver/post-receive.c4
-rw-r--r--src/blogc-git-receiver/pre-receive.c28
-rw-r--r--src/blogc-git-receiver/shell.c30
4 files changed, 33 insertions, 33 deletions
diff --git a/src/blogc-git-receiver/main.c b/src/blogc-git-receiver/main.c
index 43a9993..13218dd 100644
--- a/src/blogc-git-receiver/main.c
+++ b/src/blogc-git-receiver/main.c
@@ -35,10 +35,10 @@ main(int argc, char *argv[])
char *ssh_orig = getenv("SSH_ORIGINAL_COMMAND");
if (argc == 1 && ssh_orig != NULL && argv[0][0] == '/') {
setenv("SHELL", argv[0], 1);
- char* _argv[3] = {argv[0], "-c", ssh_orig};
+ char* _argv[] = {argv[0], "-c", ssh_orig};
return bgr_shell(3, _argv);
}
fprintf(stderr, "error: this is a special shell, go away!\n");
- return 3;
+ return 1;
}
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index b5e1f81..17a8aa7 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -29,14 +29,14 @@ bgr_post_receive_hook(int argc, char *argv[])
if (real_hooks_dir == NULL) {
fprintf(stderr, "error: failed to guess repository root: %s\n",
strerror(errno));
- return 3;
+ return 1;
}
char *repo_path = bc_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_path)) {
fprintf(stderr, "error: failed to change to repository root\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 9274857..03b5b21 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -103,14 +103,14 @@ bgr_pre_receive_hook(int argc, char *argv[])
if (real_hooks_dir == NULL) {
fprintf(stderr, "error: failed to guess repository root: %s\n",
strerror(errno));
- return 3;
+ return 1;
}
char *repo_dir = bc_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_dir)) {
fprintf(stderr, "error: failed to change to repository root\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -147,14 +147,14 @@ default_sym:
if (0 != access(sym, R_OK)) {
fprintf(stderr, "error: no previous build found. nothing to "
"rebuild.\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
char *build_dir = realpath(sym, NULL);
if (build_dir == NULL) {
fprintf(stderr, "error: failed to get the hash of last built "
"commit: %s\n", strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
char **pieces = bc_str_split(basename(build_dir), '-', 2);
@@ -163,7 +163,7 @@ default_sym:
fprintf(stderr, "error: failed to parse the hash of last built "
"commit.\n");
bc_strv_free(pieces);
- rv = 3;
+ rv = 1;
goto cleanup;
}
master = bc_strdup(pieces[0]);
@@ -183,7 +183,7 @@ default_sym:
char dir[] = "/tmp/blogc_XXXXXX";
if (NULL == mkdtemp(dir)) {
- rv = 3;
+ rv = 1;
goto cleanup;
}
tmpdir = dir;
@@ -193,7 +193,7 @@ default_sym:
if (0 != system(git_archive_cmd)) {
fprintf(stderr, "error: failed to extract git content to temporary "
"directory: %s\n", tmpdir);
- rv = 3;
+ rv = 1;
free(git_archive_cmd);
goto cleanup;
}
@@ -202,14 +202,14 @@ default_sym:
if (0 != chdir(tmpdir)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", tmpdir,
strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
char *buildsd = bgr_settings_get_builds_dir();
if (buildsd == NULL) {
fprintf(stderr, "error: failed to find builds directory path\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -230,7 +230,7 @@ default_sym:
int status_bmake = system("blogc-make -v 2> /dev/null > /dev/null");
if (127 == bc_compat_status_code(status_bmake)) {
fprintf(stderr, "error: failed to find blogc-make binary\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
@@ -252,7 +252,7 @@ default_sym:
if (make_impl == NULL) {
fprintf(stderr, "error: no 'make' implementation found\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
build_cmd = bc_strdup_printf(
@@ -270,7 +270,7 @@ default_sym:
fprintf(stderr, "error: failed to build website ...\n");
rmdir_recursive(output_dir);
free(build_cmd);
- rv = 3;
+ rv = 1;
goto cleanup;
}
free(build_cmd);
@@ -280,7 +280,7 @@ default_sym:
fprintf(stderr, "error: failed to remove symlink (%s): %s\n", sym,
strerror(errno));
rmdir_recursive(output_dir);
- rv = 3;
+ rv = 1;
goto cleanup2;
}
@@ -288,7 +288,7 @@ default_sym:
fprintf(stderr, "error: failed to create symlink (%s): %s\n", sym,
strerror(errno));
rmdir_recursive(output_dir);
- rv = 3;
+ rv = 1;
goto cleanup2;
}
diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c
index 3f6a078..a460ac2 100644
--- a/src/blogc-git-receiver/shell.c
+++ b/src/blogc-git-receiver/shell.c
@@ -42,7 +42,7 @@ bgr_shell(int argc, char *argv[])
char *self = getenv("SHELL");
if (self == NULL) {
fprintf(stderr, "error: failed to find blogc-git-receiver path\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -50,7 +50,7 @@ bgr_shell(int argc, char *argv[])
const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
fprintf(stderr, "error: failed to find base directory path\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -58,7 +58,7 @@ bgr_shell(int argc, char *argv[])
char *tmp_repo = bgr_shell_command_parse(argv[2]);
if (tmp_repo == NULL) {
fprintf(stderr, "error: invalid git-shell command: %s\n", argv[2]);
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -75,7 +75,7 @@ bgr_shell(int argc, char *argv[])
if (0 != system(git_init_cmd)) {
fprintf(stderr, "error: failed to create git repository: %s\n",
repo);
- rv = 3;
+ rv = 1;
free(git_init_cmd);
goto cleanup;
}
@@ -85,7 +85,7 @@ bgr_shell(int argc, char *argv[])
if (0 != chdir(repo)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", repo,
strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -95,7 +95,7 @@ bgr_shell(int argc, char *argv[])
if (0 != mkdir("hooks", 0777)) { // mkdir honors umask for us.
fprintf(stderr, "error: failed to create directory (%s/hooks): "
"%s\n", repo, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
}
@@ -103,7 +103,7 @@ bgr_shell(int argc, char *argv[])
if (0 != chdir("hooks")) {
fprintf(stderr, "error: failed to chdir (%s/hooks): %s\n", repo,
strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -111,7 +111,7 @@ bgr_shell(int argc, char *argv[])
if (0 != unlink("pre-receive")) {
fprintf(stderr, "error: failed to remove old symlink "
"(%s/hooks/pre-receive): %s\n", repo, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
}
@@ -119,7 +119,7 @@ bgr_shell(int argc, char *argv[])
if (0 != symlink(self, "pre-receive")) {
fprintf(stderr, "error: failed to create symlink "
"(%s/hooks/pre-receive): %s\n", repo, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -127,7 +127,7 @@ bgr_shell(int argc, char *argv[])
if (0 != unlink("post-receive")) {
fprintf(stderr, "error: failed to remove old symlink "
"(%s/hooks/post-receive): %s\n", repo, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
}
@@ -135,7 +135,7 @@ bgr_shell(int argc, char *argv[])
if (0 != symlink(self, "post-receive")) {
fprintf(stderr, "error: failed to create symlink "
"(%s/hooks/post-receive): %s\n", repo, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -143,7 +143,7 @@ git_exec:
if (0 != chdir(bd)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", bd, strerror(errno));
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -157,13 +157,13 @@ git_exec:
if (sizeof(buffer) < (strlen(command) + strlen(quoted_repo) + 2)) {
fprintf(stderr, "error: git-shell command is too big\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
if (0 > snprintf(buffer, sizeof(buffer), "%s %s", command, quoted_repo)) {
fprintf(stderr, "error: failed to generate git-shell command\n");
- rv = 3;
+ rv = 1;
goto cleanup;
}
@@ -177,7 +177,7 @@ git_exec:
// execlp only returns on error, then something bad happened
fprintf(stderr, "error: failed to execute git-shell\n");
- return 3;
+ return 1;
}
printf("git-shell -c \"%s\"\n", buffer); // used by tests, ignore