-
Notifications
You must be signed in to change notification settings - Fork 334
Offer a means to send the tty to the Apple log system #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5083e30
f107b67
dd7716c
9a66ade
3fdabd9
8f07383
336fbb8
27aa572
e2af04b
bf1404f
5b93edd
679700d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| /* Initialize ASL logger and local buffer. */ | ||
| void log_init(void); | ||
|
|
||
| /* Send one character to the logger: wait for full lines before actually sending. */ | ||
| void log_put(uint8_t _c); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #include <asl.h> | ||
| #include <pwd.h> | ||
| #include <fcntl.h> | ||
| #include <stdio.h> | ||
| #include <time.h> | ||
|
|
||
| #include <SystemConfiguration/SystemConfiguration.h> | ||
|
|
||
| #include <xhyve/log.h> | ||
|
|
||
| static aslclient log_client = NULL; | ||
| static aslmsg log_msg = NULL; | ||
|
|
||
| static unsigned char buf[4096]; | ||
| /* Index of the _next_ character to insert in the buffer. */ | ||
| static size_t buf_idx = 0; | ||
|
|
||
| /* asl is deprecated in favor of os_log starting with macOS 10.12. */ | ||
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
|
|
||
| /* Initialize ASL logger and local buffer. */ | ||
| void log_init(void) | ||
| { | ||
| log_client = asl_open(NULL, NULL, 0); | ||
| log_msg = asl_new(ASL_TYPE_MSG); | ||
| } | ||
|
|
||
|
|
||
| /* Send the content of the buffer to the logger. */ | ||
| static void log_flush(void) | ||
| { | ||
| buf[buf_idx] = 0; | ||
| asl_log(log_client, log_msg, ASL_LEVEL_NOTICE, "%s", buf); | ||
| buf_idx = 0; | ||
| } | ||
|
|
||
|
|
||
| /* Send one character to the logger: wait for full lines before actually sending. */ | ||
| void log_put(uint8_t c) | ||
| { | ||
| if ((c == '\n') || (c == 0)) { | ||
| log_flush(); | ||
| } else { | ||
| if (buf_idx + 2 >= sizeof(buf)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this now seems to waste one byte. But more in general maybe have something like: This would keep everything in one function, but it's a matter of taste, i guess
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I guess. I dislike assignments such as |
||
| log_flush(); | ||
| } | ||
| buf[buf_idx] = c; | ||
| ++buf_idx; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,13 +41,14 @@ | |
| #include <assert.h> | ||
| #include <errno.h> | ||
| #include <sys/mman.h> | ||
| #include <xhyve/log.h> | ||
| #include <xhyve/support/ns16550.h> | ||
| #include <xhyve/mevent.h> | ||
| #include <xhyve/uart_emul.h> | ||
|
|
||
| #define COM1_BASE 0x3F8 | ||
| #define COM1_BASE 0x3F8 | ||
| #define COM1_IRQ 4 | ||
| #define COM2_BASE 0x2F8 | ||
| #define COM2_BASE 0x2F8 | ||
| #define COM2_IRQ 3 | ||
|
|
||
| #define DEFAULT_RCLK 1843200 | ||
|
|
@@ -91,7 +92,7 @@ struct fifo { | |
| struct ttyfd { | ||
| bool opened; | ||
| int fd; /* tty device file descriptor */ | ||
| int sfd; | ||
| int sfd; | ||
| char *name; /* slave pty name when using autopty*/ | ||
| struct termios tio_orig, tio_new; /* I/O Terminals */ | ||
| }; | ||
|
|
@@ -121,6 +122,7 @@ struct uart_softc { | |
|
|
||
| struct ttyfd tty; | ||
| struct log log; | ||
| bool asl; /* Output to Apple logger. */ | ||
| bool thre_int_pending; /* THRE interrupt pending */ | ||
|
|
||
| void *arg; | ||
|
|
@@ -427,7 +429,7 @@ uart_write(struct uart_softc *sc, int offset, uint8_t value) | |
| } | ||
| } | ||
|
|
||
| switch (offset) { | ||
| switch (offset) { | ||
| case REG_DATA: | ||
| if (sc->mcr & MCR_LOOPBACK) { | ||
| if (rxfifo_putchar(sc, value) != 0) | ||
|
|
@@ -436,6 +438,8 @@ uart_write(struct uart_softc *sc, int offset, uint8_t value) | |
| ttywrite(&sc->tty, value); | ||
| if (sc->log.ring) | ||
| ringwrite(&sc->log, value); | ||
| if (sc->asl) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. below it looks like the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see that they are exclusive. What do you mean?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I misread the snippet of code from below. This is fine. |
||
| log_put(value); | ||
| } /* else drop on floor */ | ||
| sc->thre_int_pending = true; | ||
| break; | ||
|
|
@@ -681,15 +685,15 @@ uart_tty_backend(struct uart_softc *sc, const char *backend) | |
| static char * | ||
| copy_up_to_comma(const char *from) | ||
| { | ||
| char *comma = strchr(from, ','); | ||
| char *tmp = NULL; | ||
| if (comma == NULL) { | ||
| tmp = strdup(from); /* rest of string */ | ||
| } else { | ||
| ptrdiff_t length = comma - from; | ||
| tmp = strndup(from, (size_t)length); | ||
| } | ||
| return tmp; | ||
| char *comma = strchr(from, ','); | ||
| char *tmp = NULL; | ||
| if (comma == NULL) { | ||
| tmp = strdup(from); /* rest of string */ | ||
| } else { | ||
| ptrdiff_t length = comma - from; | ||
| tmp = strndup(from, (size_t)length); | ||
| } | ||
| return tmp; | ||
| } | ||
|
|
||
| int | ||
|
|
@@ -773,6 +777,10 @@ uart_set_backend(struct uart_softc *sc, const char *backend, const char *devname | |
| if (uart_mapring(sc, logname) == -1) { | ||
| goto err; | ||
| } | ||
| } else if (strcmp("asl", backend) == 0) { | ||
| sc->asl = true; | ||
| log_init(); | ||
| retval = 0; | ||
| } else if (uart_tty_backend(sc, backend) == 0) { | ||
| retval = 0; | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read the code which calls this function correctly in neither case where this function is called do you null terminate
buf. So, how doesasl_log()know how longbufis?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rn. Again, I'm sorry, but I don't know what you mean. It seems to me that you missed line 32, or I misunderstand your sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my bad. shouldn't review code without having coffee before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄