added details to error messages - fiche - A pastebin adjusted for gopher use | |
git clone git://vernunftzentrum.de/fiche.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit c1e37117428266b13b33ea2ce5cb7fb9a076c9b4 | |
parent 173883c0a5a1fb36b1af11d800f1aaa26186c69a | |
Author: solusipse <[email protected]> | |
Date: Mon, 16 Sep 2013 10:53:32 +0200 | |
added details to error messages | |
Diffstat: | |
fiche.c | 20 +++++++++++--------- | |
fiche.h | 3 ++- | |
2 files changed, 13 insertions(+), 10 deletions(-) | |
--- | |
diff --git a/fiche.c b/fiche.c | |
@@ -117,16 +117,16 @@ void perform_connection(int listen_socket) | |
timeout.tv_usec = 0; | |
if (setsockopt (connection_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeo… | |
- error(); | |
+ error("ERROR while setting setsockopt timeout"); | |
if (setsockopt (connection_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeo… | |
- error(); | |
+ error("ERROR while setting setsockopt timeout"); | |
struct thread_arguments arguments; | |
arguments.connection_socket = connection_socket; | |
arguments.client_address = client_address; | |
if (pthread_create(&thread_id, NULL, &thread_connection, &arguments) != 0) | |
- error(); | |
+ error("ERROR on thread creation"); | |
else | |
pthread_detach(thread_id); | |
} | |
@@ -154,10 +154,12 @@ struct client_data get_client_address(struct sockaddr_in … | |
char *hostaddrp; | |
hostp = gethostbyaddr((const char *)&client_address.sin_addr.s_addr, sizeo… | |
- if (hostp == NULL) error(); | |
+ if (hostp == NULL) | |
+ nerror("ERROR: Couldn't obtain client's address"); | |
hostaddrp = inet_ntoa(client_address.sin_addr); | |
- if (hostaddrp == NULL) error(); | |
+ if (hostaddrp == NULL) | |
+ nerror("ERROR: Couldn't obtain client's address"); | |
display_date(); | |
printf("Client: %s (%s)\n", hostaddrp, hostp->h_name); | |
@@ -223,7 +225,7 @@ int create_socket() | |
{ | |
int lsocket = socket(AF_INET, SOCK_STREAM, 0); | |
if (lsocket < 0) | |
- error(); | |
+ error("ERROR: Couldn't open socket"); | |
else return lsocket; | |
} | |
@@ -239,9 +241,9 @@ struct sockaddr_in set_address(struct sockaddr_in server_ad… | |
void bind_to_port(int listen_socket, struct sockaddr_in server_address) | |
{ | |
if (bind(listen_socket, (struct sockaddr *) &server_address, sizeof(server… | |
- error(); | |
+ error("ERROR while binding to port"); | |
if (listen(listen_socket, QUEUE_SIZE) < 0) | |
- error(); | |
+ error("ERROR while starting listening"); | |
} | |
void generate_url(char *buffer, char *slug) | |
@@ -310,7 +312,7 @@ void set_uid_gid(char *username) | |
{ | |
struct passwd *userdata = getpwnam(username); | |
if (userdata == NULL) | |
- error(); | |
+ error("Provided user doesn't exist"); | |
UID = userdata->pw_uid; | |
GID = userdata->pw_gid; | |
diff --git a/fiche.h b/fiche.h | |
@@ -63,7 +63,8 @@ int create_directory(char *slug); | |
void bind_to_port(int listen_socket, struct sockaddr_in serveraddr); | |
void display_line(){printf("====================================\n");} | |
-void error(){perror("ERROR"); exit(1);} | |
+void error(char *error_code){perror(error_code); exit(1);} | |
+void nerror(char *error_code){perror(error_code);} | |
void display_date(); | |
void perform_connection(int listen_socket); | |
void generate_url(char *buffer, char *slug); |