You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/09/26 12:44:37 UTC

[16/19] guacamole-server git commit: GUACAMOLE-623: Clean up logging (libwebsockets adds newline characters).

GUACAMOLE-623: Clean up logging (libwebsockets adds newline characters).


Project: http://git-wip-us.apache.org/repos/asf/guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-server/commit/61df2956
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-server/tree/61df2956
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-server/diff/61df2956

Branch: refs/heads/master
Commit: 61df2956b322a01a777c8169cbbd2b2a2877d696
Parents: 83a531b
Author: Michael Jumper <mj...@apache.org>
Authored: Tue Sep 11 03:17:00 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Tue Sep 25 21:30:52 2018 -0700

----------------------------------------------------------------------
 src/protocols/kubernetes/client.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/61df2956/src/protocols/kubernetes/client.c
----------------------------------------------------------------------
diff --git a/src/protocols/kubernetes/client.c b/src/protocols/kubernetes/client.c
index 331e03d..1a1eb3a 100644
--- a/src/protocols/kubernetes/client.c
+++ b/src/protocols/kubernetes/client.c
@@ -48,9 +48,32 @@ guac_client* guac_kubernetes_lws_current_client = NULL;
  *     The line of logging output to log.
  */
 static void guac_kubernetes_log(int level, const char* line) {
-    if (guac_kubernetes_lws_current_client != NULL)
-        guac_client_log(guac_kubernetes_lws_current_client, GUAC_LOG_DEBUG,
-                "libwebsockets: %s", line);
+
+    char buffer[1024];
+
+    /* Drop log message if there's nowhere to log yet */
+    if (guac_kubernetes_lws_current_client == NULL)
+        return;
+
+    /* Trim length of line to fit buffer (plus null terminator) */
+    int length = strlen(line);
+    if (length > sizeof(buffer) - 1)
+        length = sizeof(buffer) - 1;
+
+    /* Copy as much of the received line as will fit in the buffer */
+    memcpy(buffer, line, length);
+
+    /* If the line ends with a newline character, trim the character */
+    if (length > 0 && buffer[length - 1] == '\n')
+        length--;
+
+    /* Null-terminate the trimmed string */
+    buffer[length] = '\0';
+
+    /* Log using guacd's own log facilities */
+    guac_client_log(guac_kubernetes_lws_current_client, GUAC_LOG_DEBUG,
+            "libwebsockets: %s", buffer);
+
 }
 
 int guac_client_init(guac_client* client) {