diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-12-26 20:52:13 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-12-26 20:52:13 +0100 |
commit | 7bf68b0b617fb3ffa86f38fe06a49786883037f4 (patch) | |
tree | 797c86c0f24195555d4cd520a2a9c92c852be55b | |
parent | 509af4c66c0b6287ba281a2d1f01d69450f6109c (diff) | |
download | blogc-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.
-rw-r--r-- | src/blogc-git-receiver/main.c | 2 | ||||
-rw-r--r-- | src/blogc-git-receiver/post-receive.c | 4 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive.c | 28 | ||||
-rw-r--r-- | src/blogc-git-receiver/shell.c | 30 | ||||
-rw-r--r-- | src/blogc-runserver/httpd.c | 18 | ||||
-rw-r--r-- | src/blogc-runserver/main.c | 8 | ||||
-rw-r--r-- | src/blogc/main.c | 20 |
7 files changed, 55 insertions, 55 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 diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c index 66a7466..7d96c9b 100644 --- a/src/blogc-runserver/httpd.c +++ b/src/blogc-runserver/httpd.c @@ -212,7 +212,7 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, { if (port == 0) { fprintf(stderr, "Invalid port: 0\n"); - return 1; + return 3; } thread_data_t threads[max_threads]; @@ -222,7 +222,7 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, int server_socket = socket(AF_INET, SOCK_STREAM, 0); if (server_socket == -1) { fprintf(stderr, "Failed to open server socket: %s\n", strerror(errno)); - return 1; + return 3; } int rv = 0; @@ -230,7 +230,7 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, int value = 1; if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(int)) < 0) { fprintf(stderr, "Failed to set socket option: %s\n", strerror(errno)); - rv = 1; + rv = 3; goto cleanup; } @@ -240,7 +240,7 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, server_addr.sin_port = htons(port); if ((server_addr.sin_addr.s_addr = inet_addr(host)) == -1) { fprintf(stderr, "Invalid server listen address: %s\n", host); - rv = 1; + rv = 3; goto cleanup; } @@ -249,13 +249,13 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, { fprintf(stderr, "Failed to bind to server socket (%s:%d): %s\n", host, port, strerror(errno)); - rv = 1; + rv = 3; goto cleanup; } if (listen(server_socket, LISTEN_BACKLOG) == -1) { fprintf(stderr, "Failed to listen to server socket: %s\n", strerror(errno)); - rv = 1; + rv = 3; goto cleanup; } @@ -275,7 +275,7 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, (struct sockaddr *) &client_addr, &len); if (client_socket == -1) { fprintf(stderr, "Failed to accept connection: %s\n", strerror(errno)); - rv = 1; + rv = 3; goto cleanup; } @@ -288,14 +288,14 @@ br_httpd_run(const char *host, unsigned short port, const char *docroot, if (threads[current_thread].initialized) { if (pthread_join(threads[current_thread].thread, NULL) != 0) { fprintf(stderr, "Failed to join thread\n"); - rv = 1; + rv = 3; goto cleanup; } } if (pthread_create(&(threads[current_thread].thread), NULL, handle_request, arg) != 0) { fprintf(stderr, "Failed to create thread\n"); - rv = 1; + rv = 3; goto cleanup; } diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c index 0b8d0fe..7f83f42 100644 --- a/src/blogc-runserver/main.c +++ b/src/blogc-runserver/main.c @@ -98,7 +98,7 @@ main(int argc, char **argv) print_usage(); fprintf(stderr, "blogc-runserver: error: invalid " "argument: -%c\n", argv[i][1]); - rv = 2; + rv = 3; goto cleanup; } } @@ -107,7 +107,7 @@ main(int argc, char **argv) print_usage(); fprintf(stderr, "blogc-runserver: error: only one positional " "argument allowed\n"); - rv = 2; + rv = 3; goto cleanup; } args++; @@ -119,7 +119,7 @@ main(int argc, char **argv) print_usage(); fprintf(stderr, "blogc-runserver: error: document root directory " "required\n"); - rv = 2; + rv = 3; goto cleanup; } @@ -127,7 +127,7 @@ main(int argc, char **argv) print_usage(); fprintf(stderr, "blogc-runserver: error: invalid value for -m. " "Must be integer > 0 and <= 1000\n"); - rv = 2; + rv = 3; goto cleanup; } diff --git a/src/blogc/main.c b/src/blogc/main.c index 787de0f..8a22ae2 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -199,7 +199,7 @@ main(int argc, char **argv) fprintf(stderr, "blogc: error: invalid value for " "-D (must have an '='): %s\n", tmp); bc_strv_free(pieces); - rv = 2; + rv = 3; goto cleanup; } for (unsigned int j = 0; pieces[0][j] != '\0'; j++) { @@ -210,7 +210,7 @@ main(int argc, char **argv) "for -D (configuration key must be uppercase " "with '_'): %s\n", pieces[0]); bc_strv_free(pieces); - rv = 2; + rv = 3; goto cleanup; } } @@ -223,7 +223,7 @@ main(int argc, char **argv) blogc_print_usage(); fprintf(stderr, "blogc: error: invalid argument: -%c\n", argv[i][1]); - rv = 2; + rv = 3; goto cleanup; } } @@ -237,7 +237,7 @@ main(int argc, char **argv) if (!listing && bc_slist_length(sources) == 0) { blogc_print_usage(); fprintf(stderr, "blogc: error: one source file is required\n"); - rv = 2; + rv = 3; goto cleanup; } @@ -245,7 +245,7 @@ main(int argc, char **argv) blogc_print_usage(); fprintf(stderr, "blogc: error: only one source file should be provided, " "if running without '-l'\n"); - rv = 2; + rv = 3; goto cleanup; } @@ -254,7 +254,7 @@ main(int argc, char **argv) bc_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { bc_error_print(err, "blogc"); - rv = 2; + rv = 3; goto cleanup2; } @@ -263,7 +263,7 @@ main(int argc, char **argv) if (val == NULL) { fprintf(stderr, "blogc: error: configuration variable not found: %s\n", print); - rv = 2; + rv = 3; } else { printf("%s\n", val); @@ -274,14 +274,14 @@ main(int argc, char **argv) if (template == NULL) { blogc_print_usage(); fprintf(stderr, "blogc: error: argument -t is required when rendering content\n"); - rv = 2; + rv = 3; goto cleanup2; } bc_slist_t* l = blogc_template_parse_from_file(template, &err); if (err != NULL) { bc_error_print(err, "blogc"); - rv = 2; + rv = 3; goto cleanup3; } @@ -299,7 +299,7 @@ main(int argc, char **argv) if (fp == NULL) { fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", output, strerror(errno)); - rv = 2; + rv = 3; goto cleanup4; } } |