$OpenBSD: patch-unixserial_c,v 1.2 2002/09/06 06:25:31 pvalchev Exp $

--- libsock/unixserial.c.orig	Wed Jun  6 14:00:17 2001
+++ libsock/unixserial.c	Thu Sep  5 23:47:21 2002
@@ -156,6 +156,13 @@ pi_serial_open(struct pi_socket *ps, str
 
 	int i;
 
+	/* Here we need a workaround for BSD USB device used with newer
+	   Handspring devices (namely Platinum, Prism, Edge and Treo) */
+
+#define maxretries 100
+	int retries;
+	int rc;
+
 #ifndef SGTTY
 	struct termios tcn;
 #else
@@ -167,9 +174,20 @@ pi_serial_open(struct pi_socket *ps, str
 	if (!tty)
 		tty = "<Null>";
 
+	for (retries = 0 ; retries <= maxretries ; retries++ ) {
+	  if ((rc = open(tty, O_RDWR | O_NONBLOCK)) == -1) {
+	    usleep(50000);
+	  } else {
+	    ps->mac->fd = rc;
+	    break;
+	  }
+	}
+
+/* Huh? already open(2) above
 	if ((ps->mac->fd = open(tty, O_RDWR | O_NONBLOCK)) == -1) {
+*/
+	if (rc == -1)
 		return -1;	/* errno already set */
-	}
 
 	if (!isatty(ps->mac->fd)) {
 		close(ps->mac->fd);
