From: Uffe Jakobsen Date: Tue, 29 Jan 2019 08:06:31 +0000 (+0100) Subject: Symlink for UART tap was never created during uart_pty_connect() X-Git-Tag: v1.7~22^2 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=4bbb568f58ea70018c7d613f00af0f61fcca36f0;p=sx%2Fsimavr.git Symlink for UART tap was never created during uart_pty_connect() --- diff --git a/examples/parts/uart_pty.c b/examples/parts/uart_pty.c index 3282ac9..dfe3fe7 100644 --- a/examples/parts/uart_pty.c +++ b/examples/parts/uart_pty.c @@ -240,15 +240,16 @@ uart_pty_init( p->irq = avr_alloc_irq(&avr->irq_pool, 0, IRQ_UART_PTY_COUNT, irq_names); avr_irq_register_notify(p->irq + IRQ_UART_PTY_BYTE_IN, uart_pty_in_hook, p); - int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) || - (getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM"))) ; + const int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) || + (getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM"))); + p->hastap = hastap; for (int ti = 0; ti < 1 + hastap; ti++) { int m, s; if (openpty(&m, &s, p->port[ti].slavename, NULL, NULL) < 0) { fprintf(stderr, "%s: Can't create pty: %s", __FUNCTION__, strerror(errno)); - return ; + return; } struct termios tio; tcgetattr(m, &tio); @@ -302,9 +303,9 @@ uart_pty_connect( if (xoff) avr_irq_register_notify(xoff, uart_pty_xoff_hook, p); - for (int ti = 0; ti < 1; ti++) if (p->port[ti].s) { + for (int ti = 0; ti < 1+(p->hastap?1:0); ti++) if (p->port[ti].s) { char link[128]; - sprintf(link, "/tmp/simavr-uart%s%c", ti == 1 ? "tap" : "", uart); + snprintf(link, sizeof(link), "/tmp/simavr-uart%c%s", uart, ti == 1 ? "-tap" : ""); unlink(link); if (symlink(p->port[ti].slavename, link) != 0) { fprintf(stderr, "WARN %s: Can't create %s: %s", __func__, link, strerror(errno)); @@ -320,4 +321,3 @@ uart_pty_connect( } else printf("note: export SIMAVR_UART_XTERM=1 and install picocom to get a terminal\n"); } - diff --git a/examples/parts/uart_pty.h b/examples/parts/uart_pty.h index a75f9f5..c851ab1 100644 --- a/examples/parts/uart_pty.h +++ b/examples/parts/uart_pty.h @@ -51,6 +51,7 @@ typedef struct uart_pty_t { pthread_t thread; int xon; + int hastap; union { struct {