#ifdef CONFIG_LIBDEVFS_DEV_STDOUT
#define DEV_STDOUT_NAME "stdout"
+/* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. This kind of behavior should be in
+ * a single place in posix-tty. We keep this workaround until we have feature
+ * in posix-tty that handles newline characters correctly.
+ */
+static inline __ssz _console_out(const char *buf, __sz len)
+{
+ const char *next_nl = NULL;
+ __sz l = len;
+ __sz off = 0;
+ __ssz rc = 0;
+
+ if (unlikely(!len))
+ return 0;
+ if (unlikely(!buf))
+ return -EINVAL;
+
+ while (l > 0) {
+ next_nl = memchr(buf, '\n', l);
+ if (next_nl) {
+ off = next_nl - buf;
+ if ((rc = uk_console_out(buf, off)) < 0)
+ return rc;
+ if ((rc = uk_console_out("\r\n", 2)) < 0)
+ return rc;
+ buf = next_nl + 1;
+ l -= off + 1;
+ } else {
+ if ((rc = uk_console_out(buf, l)) < 0)
+ return rc;
+ break;
+ }
+ }
+
+ return len;
+}
+
static int __write_fn(void *dst __unused, void *src, size_t *cnt)
{
- int ret = uk_console_out(src, *cnt);
+ int ret = _console_out(src, *cnt);
if (ret < 0)
/* TODO: remove -1 when vfscore switches to negative
#if CONFIG_LIBUKCONSOLE
#include <uk/console.h>
+#include <string.h>
+
+/* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. This kind of behavior should be in
+ * a single place in posix-tty. We keep this workaround until we have feature
+ * in posix-tty that handles newline characters correctly.
+ */
+static inline __ssz _console_out(const char *buf, __sz len)
+{
+ const char *next_nl = NULL;
+ __sz l = len;
+ __sz off = 0;
+ __ssz rc = 0;
+
+ if (unlikely(!len))
+ return 0;
+ if (unlikely(!buf))
+ return -EINVAL;
+
+ while (l > 0) {
+ next_nl = memchr(buf, '\n', l);
+ if (next_nl) {
+ off = next_nl - buf;
+ if ((rc = uk_console_out(buf, off)) < 0)
+ return rc;
+ if ((rc = uk_console_out("\r\n", 2)) < 0)
+ return rc;
+ buf = next_nl + 1;
+ l -= off + 1;
+ } else {
+ if ((rc = uk_console_out(buf, l)) < 0)
+ return rc;
+ break;
+ }
+ }
+
+ return len;
+}
#endif /* CONFIG_LIBUKCONSOLE */
static int
/* DELETE control character */
if (buf - 1 != buffer) {
/* If this is not the first byte */
- uk_console_out("\b \b", 3);
+ _console_out("\b \b", 3);
buf -= 1;
if (bytes_total > 0)
bytes_total--;
}
buf -= 1;
} else {
- uk_console_out(buf - bytes_read, bytes_read);
+ _console_out(buf - bytes_read, bytes_read);
bytes_total += bytes_read;
}
#include <uk/essentials.h>
#include <uk/arch/lcpu.h>
+
#if CONFIG_LIBUKCONSOLE
#include <uk/console.h>
+
+/* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. This kind of behavior should be in
+ * a single place in posix-tty. We keep this workaround until we have feature
+ * in posix-tty that handles newline characters correctly.
+ */
+static inline __ssz _console_out(const char *buf, __sz len)
+{
+ const char *next_nl = NULL;
+ __sz l = len;
+ __sz off = 0;
+ __ssz rc = 0;
+
+ if (unlikely(!len))
+ return 0;
+ if (unlikely(!buf))
+ return -EINVAL;
+
+ while (l > 0) {
+ next_nl = memchr(buf, '\n', l);
+ if (next_nl) {
+ off = next_nl - buf;
+ if ((rc = uk_console_out(buf, off)) < 0)
+ return rc;
+ if ((rc = uk_console_out("\r\n", 2)) < 0)
+ return rc;
+ buf = next_nl + 1;
+ l -= off + 1;
+ } else {
+ if ((rc = uk_console_out(buf, l)) < 0)
+ return rc;
+ break;
+ }
+ }
+
+ return len;
+}
#endif /* CONFIG_LIBUKCONSOLE */
/* 64 bits + 0-Byte at end */
*/
if (fp == stdout || fp == stderr)
#if CONFIG_LIBUKCONSOLE
- ret = uk_console_out(buf, ret);
+ ret = _console_out(buf, ret);
#else /* !CONFIG_LIBUKCONSOLE */
ret = strlen(buf);
#endif /* !CONFIG_LIBUKCONSOLE */
unsigned char c = _c;
if (fp == stdout || fp == stderr)
- ret = uk_console_out((char *)&c, 1);
+ ret = _console_out((char *)&c, 1);
if (ret == 1)
return _c;
len = strlen(s);
if (stream == stdout || stream == stderr)
- ret = uk_console_out(s, len);
+ ret = _console_out(s, len);
else
return EOF;
- /* If uk_console_out wasn't able to write all characters, assume
+ /* If _console_out wasn't able to write all characters, assume
* that an error happened and there is no point in retrying.
*/
if ((size_t)ret != len)
[VWERASE] = 027,
};
+/* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. This kind of behavior should be in
+ * a single place in posix-tty. We keep this workaround until we have feature
+ * in posix-tty that handles newline characters correctly.
+ */
+static inline __ssz _console_out(const char *buf, __sz len)
+{
+ const char *next_nl = NULL;
+ __sz l = len;
+ __sz off = 0;
+ __ssz rc = 0;
+
+ if (unlikely(!len))
+ return 0;
+ if (unlikely(!buf))
+ return -EINVAL;
+
+ while (l > 0) {
+ next_nl = memchr(buf, '\n', l);
+ if (next_nl) {
+ off = next_nl - buf;
+ if ((rc = uk_console_out(buf, off)) < 0)
+ return rc;
+ if ((rc = uk_console_out("\r\n", 2)) < 0)
+ return rc;
+ buf = next_nl + 1;
+ l -= off + 1;
+ } else {
+ if ((rc = uk_console_out(buf, l)) < 0)
+ return rc;
+ break;
+ }
+ }
+
+ return len;
+}
static ssize_t serial_read(const struct uk_file *f,
const struct iovec *iov, int iovcnt,
*last = '\n';
/* Echo the input to the console (NOT stdout!) */
- uk_console_out(buf, bytes_read);
+ _console_out(buf, bytes_read);
if (*last == '\n')
break;
if (unlikely(!buf && len))
return -EFAULT;
- bytes_written = uk_console_out(buf, len);
+ bytes_written = _console_out(buf, len);
if (unlikely(bytes_written < 0))
return bytes_written;
break;
}
+ /* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. There should be a dedicated TTY
+ * layer to take care of this. Once that layer exists, stop printing
+ * a CRLF sequence if `UK_PRSYSCALL_FMTF_NEWLINE` is set and print a
+ * single newline character instead.
+ */
+
/* Try to fix the line ending if content got truncated */
if (uk_streambuf_istruncated(sb)) {
/* reserve an extra byte for the newline ending if configured */
__sz needed_len = 3
- + ((fmtf & UK_PRSYSCALL_FMTF_NEWLINE) ? 1 : 0);
+ + ((fmtf & UK_PRSYSCALL_FMTF_NEWLINE) ? 2 : 0);
if (uk_streambuf_buflen(sb) > needed_len + 1) {
sb->seek = uk_streambuf_seek(sb) - needed_len;
uk_streambuf_strcpy(sb, "...");
}
if (fmtf & UK_PRSYSCALL_FMTF_NEWLINE)
- uk_streambuf_strcpy(sb, "\n");
+ uk_streambuf_strcpy(sb, "\r\n");
}
int uk_snprsyscall(char *buf, __sz maxlen, int fmtf, long syscall_num,
#if CONFIG_LIBUKCONSOLE
#include <uk/console.h>
+#include <errno.h>
#endif /* CONFIG_LIBUKCONSOLE */
#if CONFIG_LIBUKDEBUG_ANSI_COLOR
int prevlvl;
};
+#if CONFIG_LIBUKCONSOLE
+/* TODO: Some consoles require both a newline and a carriage return to
+ * go to the start of the next line. This kind of behavior should be in
+ * a single place in posix-tty. We keep this workaround until we have feature
+ * in posix-tty that handles newline characters correctly.
+ */
+static inline __ssz _console_out(const char *buf, __sz len)
+{
+ const char *next_nl = NULL;
+ __sz l = len;
+ __sz off = 0;
+ __ssz rc = 0;
+
+ if (unlikely(!len))
+ return 0;
+ if (unlikely(!buf))
+ return -EINVAL;
+
+ while (l > 0) {
+ next_nl = memchr(buf, '\n', l);
+ if (next_nl) {
+ off = next_nl - buf;
+ if ((rc = uk_console_out(buf, off)) < 0)
+ return rc;
+ if ((rc = uk_console_out("\r\n", 2)) < 0)
+ return rc;
+ buf = next_nl + 1;
+ l -= off + 1;
+ } else {
+ if ((rc = uk_console_out(buf, l)) < 0)
+ return rc;
+ break;
+ }
+ }
+
+ return len;
+}
+#endif /* CONFIG_LIBUKCONSOLE */
+
/* Console state for kernel output */
#if CONFIG_LIBUKDEBUG_REDIR_PRINTD || CONFIG_LIBUKDEBUG_PRINTK
static struct _vprint_console kern = {
#if CONFIG_LIBUKCONSOLE
- .cout = uk_console_out,
+ .cout = _console_out,
#else
.cout = NULL,
#endif /* CONFIG_LIBUKCONSOLE */
#if !CONFIG_LIBUKDEBUG_REDIR_PRINTD
static struct _vprint_console debug = {
#if CONFIG_LIBUKCONSOLE
- .cout = uk_console_out,
+ .cout = _console_out,
#else
.cout = NULL,
#endif /* CONFIG_LIBUKCONSOLE */