error() - no need to use ERROR multiple times
This commit is contained in:
22
fiche.c
22
fiche.c
@@ -40,11 +40,11 @@ int main(int argc, char **argv)
|
|||||||
if (getuid() == 0)
|
if (getuid() == 0)
|
||||||
{
|
{
|
||||||
if (UID == -1)
|
if (UID == -1)
|
||||||
error("ERROR: user not set");
|
error("user not set");
|
||||||
if (setgid(GID) != 0)
|
if (setgid(GID) != 0)
|
||||||
error("ERROR: Unable to drop group privileges");
|
error("Unable to drop group privileges");
|
||||||
if (setuid(UID) != 0)
|
if (setuid(UID) != 0)
|
||||||
error("ERROR: Unable to drop user privileges");
|
error("Unable to drop user privileges");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BASEDIR == NULL)
|
if (BASEDIR == NULL)
|
||||||
@@ -67,7 +67,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
error("ERROR: Failed to fork");
|
error("Failed to fork");
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
while (1) perform_connection(listen_socket);
|
while (1) perform_connection(listen_socket);
|
||||||
}
|
}
|
||||||
@@ -142,16 +142,16 @@ void perform_connection(int listen_socket)
|
|||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
if (setsockopt (connection_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
if (setsockopt (connection_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
||||||
error("ERROR while setting setsockopt timeout");
|
error("while setting setsockopt timeout");
|
||||||
if (setsockopt (connection_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
if (setsockopt (connection_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
||||||
error("ERROR while setting setsockopt timeout");
|
error("while setting setsockopt timeout");
|
||||||
|
|
||||||
struct thread_arguments arguments;
|
struct thread_arguments arguments;
|
||||||
arguments.connection_socket = connection_socket;
|
arguments.connection_socket = connection_socket;
|
||||||
arguments.client_address = client_address;
|
arguments.client_address = client_address;
|
||||||
|
|
||||||
if (pthread_create(&thread_id, NULL, &thread_connection, &arguments) != 0)
|
if (pthread_create(&thread_id, NULL, &thread_connection, &arguments) != 0)
|
||||||
error("ERROR on thread creation");
|
error("on thread creation");
|
||||||
else
|
else
|
||||||
pthread_detach(thread_id);
|
pthread_detach(thread_id);
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ int create_socket()
|
|||||||
int lsocket = socket(AF_INET, SOCK_STREAM, 0);
|
int lsocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
if (lsocket < 0)
|
if (lsocket < 0)
|
||||||
error("ERROR: Couldn't open socket");
|
error("Couldn't open socket");
|
||||||
|
|
||||||
return lsocket;
|
return lsocket;
|
||||||
}
|
}
|
||||||
@@ -285,9 +285,9 @@ struct sockaddr_in set_address(struct sockaddr_in server_address)
|
|||||||
void bind_to_port(int listen_socket, struct sockaddr_in server_address)
|
void bind_to_port(int listen_socket, struct sockaddr_in server_address)
|
||||||
{
|
{
|
||||||
if (bind(listen_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0)
|
if (bind(listen_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0)
|
||||||
error("ERROR while binding to port");
|
error("while binding to port");
|
||||||
if (listen(listen_socket, QUEUE_SIZE) < 0)
|
if (listen(listen_socket, QUEUE_SIZE) < 0)
|
||||||
error("ERROR while starting listening");
|
error("while starting listening");
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_url(char *buffer, char *slug, size_t slug_length, struct client_data data)
|
void generate_url(char *buffer, char *slug, size_t slug_length, struct client_data data)
|
||||||
@@ -391,7 +391,7 @@ void startup_message()
|
|||||||
|
|
||||||
void error(char *buffer)
|
void error(char *buffer)
|
||||||
{
|
{
|
||||||
printf("%s\n", buffer);
|
printf("Error: %s\n", buffer);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user