[haiku-commits] haiku: hrev52806 - src/system/boot/loader

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 27 Jan 2019 11:51:35 -0500 (EST)

hrev52806 adds 1 changeset to branch 'master'
old head: f551180bf99755f34a62a84e684f3a51fcbdb4ba
new head: 90913491392c026ec62e20fcd1360c8d5e192e72
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=90913491392c+%5Ef551180bf997

----------------------------------------------------------------------------

90913491392c: Add syslog output support to bootloader
  
  Broadcast console output as syslog debug messages, stripped of trailing 
newlines.
  Disabled by default.
  
  Patch from #6168.
  
  Change-Id: I1754381477dcde00bdcfa4482017daf5eb682cd3
  Reviewed-on: https://review.haiku-os.org/c/912
  Reviewed-by: Stephan Aßmus <superstippi@xxxxxx>

                                [ Andreas Faerber <andreas.faerber@xxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52806
Commit:      90913491392c026ec62e20fcd1360c8d5e192e72
URL:         https://git.haiku-os.org/haiku/commit/?id=90913491392c
Author:      Andreas Faerber <andreas.faerber@xxxxxx>
Date:        Sun Jan 27 08:23:46 2019 UTC
Committer:   Stephan Aßmus <superstippi@xxxxxx>
Commit-Date: Sun Jan 27 16:51:32 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/6168

----------------------------------------------------------------------------

1 file changed, 63 insertions(+), 1 deletion(-)
src/system/boot/loader/stdio.cpp | 64 +++++++++++++++++++++++++++++++++++-

----------------------------------------------------------------------------

diff --git a/src/system/boot/loader/stdio.cpp b/src/system/boot/loader/stdio.cpp
index 267ddbd46f..07ae5ee4dc 100644
--- a/src/system/boot/loader/stdio.cpp
+++ b/src/system/boot/loader/stdio.cpp
@@ -6,6 +6,8 @@
 
 #include <boot/vfs.h>
 #include <boot/stdio.h>
+#include <boot/net/NetStack.h>
+#include <boot/net/UDP.h>
 
 #include <errno.h>
 #include <stdarg.h>
@@ -20,6 +22,9 @@
 //extern FILE *stdin;
 
 
+//#define ENABLE_SYSLOG
+
+
 #undef errno
 int errno;
 
@@ -31,6 +36,51 @@ _errnop(void)
 }
 
 
+#ifdef ENABLE_SYSLOG
+
+static UDPSocket *sSyslogSocket = NULL;
+
+static void
+sendToSyslog(const char *message, int length)
+{
+       // Lazy-initialize the socket
+       if (sSyslogSocket == NULL) {
+               // Check if the network stack has been initialized yet
+               if (NetStack::Default() != NULL) {
+                       sSyslogSocket = new(std::nothrow) UDPSocket;
+                       sSyslogSocket->Bind(INADDR_ANY, 60514);
+               }
+       }
+
+       if (sSyslogSocket == NULL)
+               return;
+
+       // Strip trailing newlines
+       while (length > 0) {
+               if (message[length - 1] != '\n'
+                       && message[length - 1] != '\r') {
+                       break;
+               }
+               length--;
+       }
+       if (length <= 0)
+               return;
+
+       char buffer[1500];
+               // same comment as in vfprintf applies...
+       const int facility = 0; // kernel
+       int severity = 7; // debug
+       int offset = snprintf(buffer, sizeof(buffer),
+               "<%d>1 - - Haiku - - - \xEF\xBB\xBF",
+               facility * 8 + severity);
+       length = std::min(length, (int)sizeof(buffer) - offset);
+       memcpy(buffer + offset, message, length);
+       sSyslogSocket->Send(INADDR_BROADCAST, 514, buffer, offset + length);
+}
+
+#endif
+
+
 int
 vfprintf(FILE *file, const char *format, va_list list)
 {
@@ -40,8 +90,12 @@ vfprintf(FILE *file, const char *format, va_list list)
 
        int length = vsnprintf(buffer, sizeof(buffer), format, list);
        length = std::min(length, (int)sizeof(buffer) - 1);
-       if (length > 0)
+       if (length > 0) {
                node->Write(buffer, length);
+#ifdef ENABLE_SYSLOG
+               sendToSyslog(buffer, length);
+#endif
+       }
 
        return length;
 }
@@ -92,6 +146,10 @@ fputc(int c, FILE *file)
        // we only support direct console output right now...
        status = ((ConsoleNode *)file)->Write(&character, 1);
 
+#ifdef ENABLE_SYSLOG
+       sendToSyslog(&character, 1);
+#endif
+
        if (status > 0)
                return character;
 
@@ -108,6 +166,10 @@ fputs(const char *string, FILE *file)
        status_t status = ((ConsoleNode *)file)->Write(string, strlen(string));
        fputc('\n', file);
 
+#ifdef ENABLE_SYSLOG
+       sendToSyslog(string, strlen(string));
+#endif
+
        return status;
 }
 


Other related posts:

  • » [haiku-commits] haiku: hrev52806 - src/system/boot/loader - Stephan Aßmus