Skip to content

Commit 4bbb568

Browse files
committed
Symlink for UART tap was never created during uart_pty_connect()
1 parent b3a8e8f commit 4bbb568

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

examples/parts/uart_pty.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,16 @@ uart_pty_init(
240240
p->irq = avr_alloc_irq(&avr->irq_pool, 0, IRQ_UART_PTY_COUNT, irq_names);
241241
avr_irq_register_notify(p->irq + IRQ_UART_PTY_BYTE_IN, uart_pty_in_hook, p);
242242

243-
int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) ||
244-
(getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM"))) ;
243+
const int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) ||
244+
(getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM")));
245+
p->hastap = hastap;
245246

246247
for (int ti = 0; ti < 1 + hastap; ti++) {
247248
int m, s;
248249

249250
if (openpty(&m, &s, p->port[ti].slavename, NULL, NULL) < 0) {
250251
fprintf(stderr, "%s: Can't create pty: %s", __FUNCTION__, strerror(errno));
251-
return ;
252+
return;
252253
}
253254
struct termios tio;
254255
tcgetattr(m, &tio);
@@ -302,9 +303,9 @@ uart_pty_connect(
302303
if (xoff)
303304
avr_irq_register_notify(xoff, uart_pty_xoff_hook, p);
304305

305-
for (int ti = 0; ti < 1; ti++) if (p->port[ti].s) {
306+
for (int ti = 0; ti < 1+(p->hastap?1:0); ti++) if (p->port[ti].s) {
306307
char link[128];
307-
sprintf(link, "/tmp/simavr-uart%s%c", ti == 1 ? "tap" : "", uart);
308+
snprintf(link, sizeof(link), "/tmp/simavr-uart%c%s", uart, ti == 1 ? "-tap" : "");
308309
unlink(link);
309310
if (symlink(p->port[ti].slavename, link) != 0) {
310311
fprintf(stderr, "WARN %s: Can't create %s: %s", __func__, link, strerror(errno));
@@ -320,4 +321,3 @@ uart_pty_connect(
320321
} else
321322
printf("note: export SIMAVR_UART_XTERM=1 and install picocom to get a terminal\n");
322323
}
323-

examples/parts/uart_pty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct uart_pty_t {
5151

5252
pthread_t thread;
5353
int xon;
54+
int hastap;
5455

5556
union {
5657
struct {

0 commit comments

Comments
 (0)