Skip to content

Commit 7c254e2

Browse files
authored
Merge pull request #319 from uffejakobsen/uart_tap_symlink
Symlink for UART tap was never created during uart_pty_connect()
2 parents ff689b6 + 4bbb568 commit 7c254e2

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
@@ -245,15 +245,16 @@ uart_pty_init(
245245
p->irq = avr_alloc_irq(&avr->irq_pool, 0, IRQ_UART_PTY_COUNT, irq_names);
246246
avr_irq_register_notify(p->irq + IRQ_UART_PTY_BYTE_IN, uart_pty_in_hook, p);
247247

248-
int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) ||
249-
(getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM"))) ;
248+
const int hastap = (getenv("SIMAVR_UART_TAP") && atoi(getenv("SIMAVR_UART_TAP"))) ||
249+
(getenv("SIMAVR_UART_XTERM") && atoi(getenv("SIMAVR_UART_XTERM")));
250+
p->hastap = hastap;
250251

251252
for (int ti = 0; ti < 1 + hastap; ti++) {
252253
int m, s;
253254

254255
if (openpty(&m, &s, p->port[ti].slavename, NULL, NULL) < 0) {
255256
fprintf(stderr, "%s: Can't create pty: %s", __FUNCTION__, strerror(errno));
256-
return ;
257+
return;
257258
}
258259
struct termios tio;
259260
tcgetattr(m, &tio);
@@ -307,9 +308,9 @@ uart_pty_connect(
307308
if (xoff)
308309
avr_irq_register_notify(xoff, uart_pty_xoff_hook, p);
309310

310-
for (int ti = 0; ti < 1; ti++) if (p->port[ti].s) {
311+
for (int ti = 0; ti < 1+(p->hastap?1:0); ti++) if (p->port[ti].s) {
311312
char link[128];
312-
sprintf(link, "/tmp/simavr-uart%s%c", ti == 1 ? "tap" : "", uart);
313+
snprintf(link, sizeof(link), "/tmp/simavr-uart%c%s", uart, ti == 1 ? "-tap" : "");
313314
unlink(link);
314315
if (symlink(p->port[ti].slavename, link) != 0) {
315316
fprintf(stderr, "WARN %s: Can't create %s: %s", __func__, link, strerror(errno));
@@ -325,4 +326,3 @@ uart_pty_connect(
325326
} else
326327
printf("note: export SIMAVR_UART_XTERM=1 and install picocom to get a terminal\n");
327328
}
328-

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)