openbsd-ports/comms/pilot-link/patches/patch-unixserial_c
pvalchev c3c6ffc11a do not open(3) the device twice (once in the loop is enough)
unbreaks after last patch, thanks to Andreas Gunnarsson <andreas@crt.se>
2002-09-06 06:25:31 +00:00

41 lines
983 B
Plaintext

$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);