$OpenBSD: patch-libpisock_unixserial_c,v 1.3 2008/01/20 15:19:31 ajacoutot Exp $ --- libpisock/unixserial.c.orig Thu Oct 12 16:21:23 2006 +++ libpisock/unixserial.c Thu Jan 17 09:00:40 2008 @@ -161,13 +161,23 @@ s_open(pi_socket_t *ps, struct pi_sockaddr *addr, size struct pi_serial_data *data = (struct pi_serial_data *)ps->device->data; +#define maxretries 100 + int retries; #ifndef SGTTY struct termios tcn; #else struct sgttyb tcn; #endif - if ((fd = open(tty, O_RDWR | O_NONBLOCK)) < 0) { + + for (retries = 0 ; retries <= maxretries ; retries++ ) { + if ((fd = open(tty, O_RDWR | O_NONBLOCK)) != -1) { + break; + } + usleep(50000); + } + + if (fd == -1) { ps->last_error = PI_ERR_GENERIC_SYSTEM; return PI_ERR_GENERIC_SYSTEM; /* errno already set */ }