aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-git-receiver
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-26 20:52:13 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-26 20:52:13 +0100
commit7bf68b0b617fb3ffa86f38fe06a49786883037f4 (patch)
tree797c86c0f24195555d4cd520a2a9c92c852be55b /src/blogc-git-receiver
parent509af4c66c0b6287ba281a2d1f01d69450f6109c (diff)
downloadblogc-7bf68b0b617fb3ffa86f38fe06a49786883037f4.tar.gz
blogc-7bf68b0b617fb3ffa86f38fe06a49786883037f4.tar.bz2
blogc-7bf68b0b617fb3ffa86f38fe06a49786883037f4.zip
*: binaries should always return 3 on errors, for consistency.
We used to return 1 or 2 in case of errors, with no special meaning, other than "something is wrong", but these codes are reserved. Now we always return 3.
Diffstat (limited to 'src/blogc-git-receiver')
-rw-r--r--src/blogc-git-receiver/main.c2
-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, 32 insertions, 32 deletions
diff --git a/src/blogc-git-receiver/main.c b/src/blogc-git-receiver/main.c
index fb6e724..43f5df2 100644
--- a/src/blogc-git-receiver/main.c
+++ b/src/blogc-git-receiver/main.c
@@ -28,5 +28,5 @@ main(int argc, char *argv[])
return bgr_shell(argc, argv);
fprintf(stderr, "error: this is a special shell, go away!\n");
- return 1;
+ return 3;
}
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index 415cb0c..8ed133a 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -54,14 +54,14 @@ bgr_post_receive_hook(int argc, char *argv[])
char *real_hooks_dir = realpath(hooks_dir, NULL);
if (real_hooks_dir == NULL) {
fprintf(stderr, "error: failed to guess repository root.\n");
- return 1;
+ return 3;
}
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 = 1;
+ rv = 3;
goto cleanup;
}
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index c27dc77..9772a2f 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -101,14 +101,14 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *real_hooks_dir = realpath(hooks_dir, NULL);
if (real_hooks_dir == NULL) {
fprintf(stderr, "error: failed to guess repository root.\n");
- return 1;
+ return 3;
}
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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -118,7 +118,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: no previous build found. nothing to "
"rebuild.\n");
free(htdocs_sym);
- rv = 1;
+ rv = 3;
goto cleanup;
}
char *build_dir = realpath(htdocs_sym, NULL);
@@ -126,7 +126,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
if (build_dir == NULL) {
fprintf(stderr, "error: failed to get the hash of last built "
"commit.\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
char **pieces = bc_str_split(basename(build_dir), '-', 2);
@@ -135,7 +135,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: failed to parse the hash of last built "
"commit.\n");
bc_strv_free(pieces);
- rv = 1;
+ rv = 3;
goto cleanup;
}
master = bc_strdup(pieces[0]);
@@ -155,7 +155,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
char dir[] = "/tmp/blogc_XXXXXX";
if (NULL == mkdtemp(dir)) {
- rv = 1;
+ rv = 3;
goto cleanup;
}
tmpdir = dir;
@@ -165,7 +165,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
if (0 != system(git_archive_cmd)) {
fprintf(stderr, "error: failed to extract git content to temporary "
"directory: %s\n", tmpdir);
- rv = 1;
+ rv = 3;
free(git_archive_cmd);
goto cleanup;
}
@@ -174,7 +174,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
if (0 != chdir(tmpdir)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", tmpdir,
strerror(errno));
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -186,7 +186,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *home = getenv("HOME");
if (home == NULL) {
fprintf(stderr, "error: failed to find user home path\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -201,7 +201,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
if (make_impl == NULL) {
fprintf(stderr, "error: no 'make' implementation found\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -223,7 +223,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: failed to build website ...\n");
rmdir_recursive(output_dir);
free(gmake_cmd);
- rv = 1;
+ rv = 3;
goto cleanup;
}
free(gmake_cmd);
@@ -232,7 +232,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: failed to chdir (%s): %s\n", repo_dir,
strerror(errno));
rmdir_recursive(output_dir);
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -241,7 +241,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
repo_dir, strerror(errno));
rmdir_recursive(output_dir);
- rv = 1;
+ rv = 3;
goto cleanup2;
}
@@ -249,7 +249,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
fprintf(stderr, "error: failed to create symlink (%s/htdocs): %s\n",
repo_dir, strerror(errno));
rmdir_recursive(output_dir);
- rv = 1;
+ rv = 3;
goto cleanup2;
}
diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c
index a21c5bd..d0799e4 100644
--- a/src/blogc-git-receiver/shell.c
+++ b/src/blogc-git-receiver/shell.c
@@ -30,7 +30,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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -38,7 +38,7 @@ bgr_shell(int argc, char *argv[])
char *home = getenv("HOME");
if (home == NULL) {
fprintf(stderr, "error: failed to find user home path\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -46,7 +46,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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -63,7 +63,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 = 1;
+ rv = 3;
free(git_init_cmd);
goto cleanup;
}
@@ -73,7 +73,7 @@ bgr_shell(int argc, char *argv[])
if (0 != chdir(repo)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", repo,
strerror(errno));
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -83,7 +83,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 = 1;
+ rv = 3;
goto cleanup;
}
}
@@ -91,7 +91,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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -99,7 +99,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 = 1;
+ rv = 3;
goto cleanup;
}
}
@@ -107,7 +107,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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -115,7 +115,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 = 1;
+ rv = 3;
goto cleanup;
}
}
@@ -123,7 +123,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 = 1;
+ rv = 3;
goto cleanup;
}
@@ -132,7 +132,7 @@ git_exec:
if (0 != chdir(home)) {
fprintf(stderr, "error: failed to chdir (%s): %s\n", home,
strerror(errno));
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -146,13 +146,13 @@ git_exec:
if (sizeof(buffer) < (strlen(command) + strlen(quoted_repo) + 2)) {
fprintf(stderr, "error: git-shell command is too big\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
if (0 > snprintf(buffer, sizeof(buffer), "%s %s", command, quoted_repo)) {
fprintf(stderr, "error: failed to generate git-shell command\n");
- rv = 1;
+ rv = 3;
goto cleanup;
}
@@ -166,7 +166,7 @@ git_exec:
// execlp only returns on error, then something bad happened
fprintf(stderr, "error: failed to execute git-shell\n");
- return 1;
+ return 3;
}
printf("git-shell -c \"%s\"\n", buffer); // used by tests, ignore