Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision c7137738c048f4d114777abf95ab228e771e4627)
@@ -54,5 +54,4 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <err.h>
 
 #include <net/socket_codes.h>
@@ -161,5 +160,5 @@
     int dont_fragment)
 {
-	ERROR_DECLARE;
+	int rc;
 
 	// do not send an error if disabled
@@ -172,8 +171,9 @@
 	header->checksum = ICMP_CHECKSUM(header,
 	    packet_get_data_length(packet));
-	if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl,
-	    tos, dont_fragment, 0))) {
-		return icmp_release_and_return(packet, ERROR_CODE);
-	}
+	
+	rc = ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, tos,
+	    dont_fragment, 0);
+	if (rc != EOK)
+		return icmp_release_and_return(packet, rc);
 
 	return ip_send_msg(icmp_globals.ip_phone, -1, packet, SERVICE_ICMP,
@@ -249,6 +249,4 @@
     const struct sockaddr * addr, socklen_t addrlen)
 {
-	ERROR_DECLARE;
-
 	icmp_header_ref header;
 	packet_t packet;
@@ -257,6 +255,6 @@
 	icmp_reply_ref reply;
 	int reply_key;
-	int result;
 	int index;
+	int rc;
 
 	if (addrlen <= 0)
@@ -265,6 +263,8 @@
 	length = (size_t) addrlen;
 	// TODO do not ask all the time
-	ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
-	    &icmp_globals.packet_dimension));
+	rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
+	    &icmp_globals.packet_dimension);
+	if (rc != EOK)
+		return rc;
 
 	packet = packet_get_4_remote(icmp_globals.net_phone, size,
@@ -277,8 +277,7 @@
 	// prepare the requesting packet
 	// set the destination address
-	if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr,
-	    length))) {
-		return icmp_release_and_return(packet, ERROR_CODE);
-	}
+	rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
+	if (rc != EOK)
+		return icmp_release_and_return(packet, rc);
 
 	// allocate space in the packet
@@ -329,11 +328,8 @@
 	// wait for the reply
 	// timeout in microseconds
-	if (ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar,
-	    &reply->mutex, timeout * 1000))) {
-		result = ERROR_CODE;
-	} else {
-		// read the result
-		result = reply->result;
-	}
+	rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
+	    timeout * 1000);
+	if (rc == EOK)
+		rc = reply->result;
 
 	// drop the reply mutex before locking the globals again
@@ -344,5 +340,5 @@
 	icmp_replies_exclude_index(&icmp_globals.replies, index);
 
-	return result;
+	return rc;
 }
 
@@ -413,6 +409,4 @@
 int icmp_initialize(async_client_conn_t client_connection)
 {
-	ERROR_DECLARE;
-
 	measured_string_t names[] = {
 		{
@@ -428,4 +422,5 @@
 	size_t count = sizeof(names) / sizeof(measured_string_t);
 	char *data;
+	int rc;
 
 	fibril_rwlock_initialize(&icmp_globals.lock);
@@ -433,11 +428,19 @@
 	icmp_replies_initialize(&icmp_globals.replies);
 	icmp_echo_data_initialize(&icmp_globals.echo_data);
+	
 	icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
 	    SERVICE_ICMP, client_connection);
-	if (icmp_globals.ip_phone < 0)
+	if (icmp_globals.ip_phone < 0) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
 		return icmp_globals.ip_phone;
-
-	ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
-	    &icmp_globals.packet_dimension));
+	}
+	
+	rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
+	    &icmp_globals.packet_dimension);
+	if (rc != EOK) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
+		return rc;
+	}
+
 	icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
 	icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
@@ -448,6 +451,11 @@
 	// get configuration
 	configuration = &names[0];
-	ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration,
-	    count, &data));
+	rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
+	    &data);
+	if (rc != EOK) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
+		return rc;
+	}
+	
 	if (configuration) {
 		if (configuration[0].value) {
@@ -519,6 +527,4 @@
 static int icmp_process_packet(packet_t packet, services_t error)
 {
-	ERROR_DECLARE;
-
 	size_t length;
 	uint8_t *src;
@@ -529,4 +535,5 @@
 	icmp_type_t type;
 	icmp_code_t code;
+	int rc;
 
 	switch (error) {
@@ -541,5 +548,7 @@
 		length = (size_t) result;
 		// remove the error header
-		ERROR_PROPAGATE(packet_trim(packet, length, 0));
+		rc = packet_trim(packet, length, 0);
+		if (rc != EOK)
+			return rc;
 		break;
 	default:
@@ -549,5 +558,7 @@
 	// get rid of the ip header
 	length = ip_client_header_length(packet);
-	ERROR_PROPAGATE(packet_trim(packet, length, 0));
+	rc = packet_trim(packet, length, 0);
+	if (rc != EOK)
+		return rc;
 
 	length = packet_get_data_length(packet);
@@ -582,5 +593,5 @@
 	switch (header->type) {
 	case ICMP_ECHOREPLY:
-		if (error) 
+		if (error)
 			icmp_process_echo_reply(packet, header, type, code);
 		else
@@ -654,8 +665,9 @@
     services_t receiver, services_t error)
 {
-	ERROR_DECLARE;
-
-	if (ERROR_OCCURRED(icmp_process_packet(packet, error)))
-		return icmp_release_and_return(packet, ERROR_CODE);
+	int rc;
+
+	rc = icmp_process_packet(packet, error);
+	if (rc != EOK)
+		return icmp_release_and_return(packet, rc);
 
 	return EOK;
@@ -682,37 +694,35 @@
 static int icmp_process_message(ipc_call_t *call)
 {
-	ERROR_DECLARE;
-
 	packet_t packet;
+	int rc;
 
 	switch (IPC_GET_METHOD(*call)) {
 	case NET_ICMP_DEST_UNREACH:
-		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE = icmp_destination_unreachable_msg_local(0,
-			    ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
-		}
-		return ERROR_CODE;
+		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
+		return icmp_destination_unreachable_msg_local(0,
+		    ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
 	case NET_ICMP_SOURCE_QUENCH:
-		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE = icmp_source_quench_msg_local(0, packet);
-		}
-		return ERROR_CODE;
+		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
+		return icmp_source_quench_msg_local(0, packet);
 	case NET_ICMP_TIME_EXCEEDED:
-		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE = icmp_time_exceeded_msg_local(0,
-			    ICMP_GET_CODE(call), packet);
-		}
-		return ERROR_CODE;
+		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
+		return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call),
+		    packet);
 	case NET_ICMP_PARAMETERPROB:
-		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE = icmp_parameter_problem_msg_local(0,
-			    ICMP_GET_CODE(call), ICMP_GET_POINTER(call),
-			    packet);
-		}
-		return ERROR_CODE;
+		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
+		return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call),
+		    ICMP_GET_POINTER(call), packet);
 	default:
 		return ENOTSUP;
@@ -757,5 +767,5 @@
 			break;
 		}
-	} while(icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
+	} while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
 
 	echo_data->identifier = index;
@@ -779,6 +789,4 @@
 static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
 {
-	ERROR_DECLARE;
-
 	bool keep_on_going = true;
 	ipc_call_t answer;
@@ -788,5 +796,5 @@
 	ipc_callid_t data_callid;
 	icmp_echo_ref echo_data;
-	int res;
+	int rc = EOK;
 
 	/*
@@ -794,5 +802,4 @@
 	 *  - Answer the first NET_ICMP_INIT call.
 	 */
-	res = EOK;
 	answer_count = 0;
 
@@ -803,14 +810,14 @@
 	// assign a new identifier
 	fibril_rwlock_write_lock(&icmp_globals.lock);
-	res = icmp_bind_free_id(echo_data);
+	rc = icmp_bind_free_id(echo_data);
 	fibril_rwlock_write_unlock(&icmp_globals.lock);
-	if (res < 0) {
+	if (rc < 0) {
 		free(echo_data);
-		return res;
+		return rc;
 	}
 
 	while (keep_on_going) {
 		// answer the call
-		answer_call(callid, res, &answer, answer_count);
+		answer_call(callid, rc, &answer, answer_count);
 
 		// refresh data
@@ -824,10 +831,10 @@
 		case IPC_M_PHONE_HUNGUP:
 			keep_on_going = false;
-			res = EHANGUP;
+			rc = EHANGUP;
 			break;
 		
 		case NET_ICMP_ECHO:
 			if (!async_data_write_receive(&data_callid, &length)) {
-				res = EINVAL;
+				rc = EINVAL;
 				break;
 			}
@@ -835,17 +842,17 @@
 			addr = malloc(length);
 			if (!addr) {
-				res = ENOMEM;
+				rc = ENOMEM;
 				break;
 			}
 			
-			if (ERROR_OCCURRED(async_data_write_finalize(
-			    data_callid, addr, length))) {
+			rc = async_data_write_finalize(data_callid, addr,
+			    length);
+			if (rc != EOK) {
 				free(addr);
-				res = ERROR_CODE;
 				break;
 			}
 
 			fibril_rwlock_write_lock(&icmp_globals.lock);
-			res = icmp_echo(echo_data->identifier,
+			rc = icmp_echo(echo_data->identifier,
 			    echo_data->sequence_number, ICMP_GET_SIZE(call),
 			    ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call),
@@ -864,5 +871,5 @@
 
 		default:
-			res = icmp_process_message(&call);
+			rc = icmp_process_message(&call);
 		}
 
@@ -874,5 +881,5 @@
 	fibril_rwlock_write_unlock(&icmp_globals.lock);
 
-	return res;
+	return rc;
 }
 
@@ -894,18 +901,16 @@
     ipc_call_t *answer, int *answer_count)
 {
-	ERROR_DECLARE;
-
 	packet_t packet;
+	int rc;
 
 	*answer_count = 0;
 	switch (IPC_GET_METHOD(*call)) {
 	case NET_TL_RECEIVED:
-		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE =
-			    icmp_received_msg_local(IPC_GET_DEVICE(call),
-			    packet, SERVICE_ICMP, IPC_GET_ERROR(call));
-		}
-		return ERROR_CODE;
+		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
+		return icmp_received_msg_local(IPC_GET_DEVICE(call), packet,
+		    SERVICE_ICMP, IPC_GET_ERROR(call));
 	
 	case NET_ICMP_INIT:
@@ -970,9 +975,9 @@
 int main(int argc, char *argv[])
 {
-	ERROR_DECLARE;
+	int rc;
 	
 	/* Start the module */
-	ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));
-	return EOK;
+	rc = tl_module_start_standalone(tl_client_connection);
+	return rc;
 }
 
