[Replicant] [libsamsung-ril] [PATCH 15/23] RIL_Init: Make sure there are prints for each error paths

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Thu Mar 4 12:42:42 UTC 2021


If libsamsung-ril didn't start (for instance due to issues
or because we are porting it to a newer Android version) it is
useful to know why.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 client.c      | 36 ++++++++++++++++++++++++++++++++----
 samsung-ril.c | 30 +++++++++++++++++++++++++-----
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/client.c b/client.c
index 2449ee0..3fa313e 100644
--- a/client.c
+++ b/client.c
@@ -92,11 +92,26 @@ int ril_client_open(struct ril_client *client)
 {
 	int rc = 0;
 
-	if (client == NULL)
+	if (client == NULL) {
+		RIL_LOGD("%s: Skipping open due to Invalid client "
+			 "(client is NULL)",
+			 __func__);
+		return -1;
+	}
+
+	if (client->handlers == NULL) {
+		RIL_LOGD("%s: Skipping open due to Invalid client "
+			 "(client->handlers is NULL)",
+			 __func__);
 		return -1;
+	}
 
-	if (client->handlers == NULL || client->handlers->open == NULL)
+	if (client->handlers->open == NULL) {
+		RIL_LOGD("%s: Skipping open due to Invalid client "
+			 "(client->handlers->open is NULL)",
+			 __func__);
 		return -1;
+	}
 
 	rc = client->handlers->open(client);
 	if (rc < 0) {
@@ -193,11 +208,24 @@ int ril_client_loop(struct ril_client *client)
 	pthread_attr_t attr;
 	int rc;
 
-	if (client == NULL)
+	if (client == NULL) {
+		RIL_LOGD("%s: Skipping loop due to Invalid client "
+			 "(client is NULL)", __func__);
+		return -1;
+	}
+
+	if (client->handlers == NULL) {
+		RIL_LOGD("%s: Skipping loop due to Invalid client "
+			 "(client->handlers is NULL)", __func__);
 		return -1;
+	}
 
-	if (client->handlers == NULL || client->handlers->loop == NULL)
+	if (client->handlers->loop == NULL) {
+		RIL_LOGD("%s: Skipping loop due to Invalid client "
+			 "(client->handlers->loop is NULL)",
+			 __func__);
 		return -1;
+	}
 
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
diff --git a/samsung-ril.c b/samsung-ril.c
index faec338..fe7a703 100644
--- a/samsung-ril.c
+++ b/samsung-ril.c
@@ -1545,12 +1545,15 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env,
 	unsigned int i;
 	int rc;
 
-	if (env == NULL)
+	if (env == NULL) {
+		RIL_LOGE("%s: Aborting: Invalid RIL_Env (RIL_Env is NULL)",
+			 __func__);
 		return NULL;
+	}
 
 	rc = ril_data_create();
 	if (rc < 0) {
-		RIL_LOGE("Creating RIL data failed");
+		RIL_LOGE("%s: Creating RIL data failed", __func__);
 		return NULL;
 	}
 
@@ -1559,17 +1562,26 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env,
 	ril_data->env = env;
 
 	for (i = 0; i < ril_clients_count; i++) {
-		if (ril_clients[i] == NULL)
+		if (ril_clients[i] == NULL) {
+			RIL_LOGD("%s: Skipping ril_client_create "
+				 "due to Invalid client (client is NULL)",
+				 __func__);
 			continue;
+		}
 
 		rc = ril_client_create(ril_clients[i]);
 		if (rc < 0)
+			/* ril_client_create already prints an error if it fails */
 			goto error;
 	}
 
 	for (i = 0; i < ril_clients_count; i++) {
-		if (ril_clients[i] == NULL)
+		if (ril_clients[i] == NULL) {
+			RIL_LOGD("%s: Skipping ril_client_open "
+				 "due to Invalid client (client is NULL)",
+				 __func__);
 			continue;
+		}
 
 		failures = 0;
 
@@ -1581,11 +1593,19 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env,
 			}
 		} while (rc < 0 && failures < RIL_CLIENT_RETRY_COUNT);
 
-		if (rc < 0)
+		if (rc < 0) {
+			RIL_LOGD("%s: "
+				 "gave up trying to open the %s client "
+				 "after %d retries",
+				 __func__,
+				 (ril_clients[i])->name,
+				 RIL_CLIENT_RETRY_COUNT);
 			goto error;
+		}
 
 		rc = ril_client_loop(ril_clients[i]);
 		if (rc < 0)
+			/* ril_client_loop already prints an error if it fails */
 			goto error;
 	}
 
-- 
2.30.1



More information about the Replicant mailing list