aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-runserver/httpd.c
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-runserver/httpd.c
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-runserver/httpd.c')
-rw-r--r--src/blogc-runserver/httpd.c18
1 files changed, 9 insertions, 9 deletions
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;
}