You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2026/09/27 21:03:18 UTC
(celix) 01/01: Improve remote shell loop error handling
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/improve-remote-shell-loop-handling
in repository https://gitbox.apache.org/repos/asf/celix.git
commit bfe6ffb450eccb749f5b5cf2dfda913fdc6e55c3
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Sun Sep 27 23:02:39 2026 +0200
Improve remote shell loop error handling
---
.../shell/remote_shell/src/connection_listener.c | 8 +++--
bundles/shell/remote_shell/src/remote_shell.c | 40 +++++++++++++---------
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/bundles/shell/remote_shell/src/connection_listener.c b/bundles/shell/remote_shell/src/connection_listener.c
index a1af23e9a..5b53816c1 100644
--- a/bundles/shell/remote_shell/src/connection_listener.c
+++ b/bundles/shell/remote_shell/src/connection_listener.c
@@ -83,7 +83,7 @@ celix_status_t connectionListener_create(remote_shell_pt remoteShell, int port,
celix_status_t connectionListener_start(connection_listener_pt instance) {
celix_status_t status = CELIX_SUCCESS;
celixThreadMutex_lock(&instance->mutex);
- celixThread_create(&instance->thread, NULL, connection_listener_thread, instance);
+ status = celixThread_create(&instance->thread, NULL, connection_listener_thread, instance);
celixThreadMutex_unlock(&instance->mutex);
return status;
}
@@ -138,7 +138,11 @@ static void* connection_listener_thread(void *data) {
char portStr[10];
snprintf(&portStr[0], 10, "%d", instance->port);
- getaddrinfo(NULL, portStr, &hints, &result);
+ int gaiResult = getaddrinfo(NULL, portStr, &hints, &result);
+ if (gaiResult != 0) {
+ celix_logHelper_log(*instance->loghelper, CELIX_LOG_LEVEL_ERROR, "getaddrinfo failed: %s", gai_strerror(gaiResult));
+ return NULL;
+ }
for (rp = result; rp != NULL && status == CELIX_BUNDLE_EXCEPTION; rp = rp->ai_next) {
diff --git a/bundles/shell/remote_shell/src/remote_shell.c b/bundles/shell/remote_shell/src/remote_shell.c
index e16ef2148..d7261774b 100644
--- a/bundles/shell/remote_shell/src/remote_shell.c
+++ b/bundles/shell/remote_shell/src/remote_shell.c
@@ -175,24 +175,32 @@ void *remoteShell_connection_run(void *data) {
char buff[COMMAND_BUFF_SIZE];
len = recv(fd, buff, COMMAND_BUFF_SIZE - 1, 0);
- if (len < COMMAND_BUFF_SIZE) {
- celix_status_t commandStatus = CELIX_SUCCESS;
- buff[len] = '\0';
-
- commandStatus = remoteShell_connection_execute(connection, buff);
-
- if (commandStatus == CELIX_SUCCESS) {
- remoteShell_connection_print(connection, RS_PROMPT);
- } else if (commandStatus == CELIX_FILE_IO_EXCEPTION) {
- //exit command
- break;
- } else { //error
- remoteShell_connection_print(connection, RS_ERROR);
- remoteShell_connection_print(connection, RS_PROMPT);
+ if (len > 0) {
+ if (len < COMMAND_BUFF_SIZE) {
+ celix_status_t commandStatus = CELIX_SUCCESS;
+ buff[len] = '\0';
+
+ commandStatus = remoteShell_connection_execute(connection, buff);
+
+ if (commandStatus == CELIX_SUCCESS) {
+ remoteShell_connection_print(connection, RS_PROMPT);
+ } else if (commandStatus == CELIX_FILE_IO_EXCEPTION) {
+ //exit command
+ break;
+ } else { //error
+ remoteShell_connection_print(connection, RS_ERROR);
+ remoteShell_connection_print(connection, RS_PROMPT);
+ }
+
+ } else {
+ celix_logHelper_log(*connection->parent->loghelper, CELIX_LOG_LEVEL_ERROR, "REMOTE_SHELL: Error while retrieving data");
}
-
+ } else if (len == 0) {
+ celix_logHelper_log(*connection->parent->loghelper, CELIX_LOG_LEVEL_INFO, "REMOTE_SHELL: Connection closed by peer");
+ break;
} else {
- celix_logHelper_log(*connection->parent->loghelper, CELIX_LOG_LEVEL_ERROR, "REMOTE_SHELL: Error while retrieving data");
+ celix_logHelper_log(*connection->parent->loghelper, CELIX_LOG_LEVEL_ERROR, "REMOTE_SHELL: recv() failed: %s", strerror(errno));
+ break;
}
}
}