Skip to content

Commit 17131f9

Browse files
Fix kissattach 'Device or resource busy'
Sometimes kissattach had an issue using the pseudo terminal on some versions of Linux: 'Error setting line discipline: TIOCSETD: Device or resource busy'. This fix resolves the issue by not reading from the pty's master fd, until kissattach has opened and configured the slave. This is implemented using select() to wait for data before reading from the master fd.
1 parent 283b768 commit 17131f9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

kiss.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -884,25 +884,28 @@ static int kiss_get (/* MYFDTYPE fd*/ void )
884884
#else /* Linux/Cygwin version */
885885

886886
int n = 0;
887+
fd_set fd_in;
888+
int rc;
887889

888890
while ( n == 0 ) {
891+
/* Reading from master fd of the pty before the client has connected leads to trouble with kissattach. */
892+
/* Use select to check if the slave has sent any data before trying to read from it. */
893+
FD_ZERO(&fd_in);
894+
rc = select(pt_master_fd + 1, &fd_in, NULL, &fd_in, NULL);
889895

890-
n = read(pt_master_fd, &ch, (size_t)1);
896+
if (rc == 0)
897+
{
898+
continue;
899+
}
891900

892-
if (n != 1) {
901+
if (rc == MYFDERROR
902+
|| (n = read(pt_master_fd, &ch, (size_t)1)) != 1)
903+
{
893904

894905
text_color_set(DW_COLOR_ERROR);
895906
dw_printf ("\nError receiving kiss message from client application. Closing %s.\n\n", pt_slave_name);
896907
perror ("");
897908

898-
/* Message added between 1.1 beta test and final version 1.1 */
899-
900-
/* TODO: Determine root cause and find proper solution. */
901-
902-
dw_printf ("This is a known problem that sometimes shows up when using with kissattach.\n");
903-
dw_printf ("There are a couple work-arounds described in the Dire Wolf User Guide\n");
904-
dw_printf ("and the Raspberry Pi APRS documents.\n");
905-
906909
close (pt_master_fd);
907910

908911
pt_master_fd = MYFDERROR;

0 commit comments

Comments
 (0)