delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/06/14/01:59:57

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-49.9 required=5.0 tests=AWL,BAYES_20,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_JP,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Subject: Nonblocking serial ports
From: "Yaakov (Cygwin/X)" <yselkowitz AT users DOT sourceforge DOT net>
To: cygwin AT cygwin DOT com
Date: Mon, 14 Jun 2010 00:59:39 -0500
Message-ID: <1276495179.5780.13.camel@YAAKOV04>
Mime-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--=-afkzDIsQJg8YOmbF+gaJ
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

I came across this while working on getting my Palm to hook up to
gnome-pilot over Bluetooth.  COM3 is an incoming COM Port created within
Bluetooth Settings, although the STC has the same results on COM1 (a
standard serial port).

Unlike pilot-link's tools and jpilot (all three use pilot-link's
libpisock under the hood), gnome-pilot open()s a serial port with
O_NONBLOCK when first started in order to initialize a GIOChannel, then
later pi_bind()s a different fd pointing to the same port.  Works great
on Linux, but on Cygwin the latter call fails, as the serial port is
already blocked by the first open() call.  FWIW, both pilot-xfer and
friends and jpilot work fine over the Bluetooth serial port, and all
three work over the network.

Attached is a STC.  On Linux, this succeeds, but on Cygwin (both 1.7.5
and latest snapshot), it fails:

second open(/dev/ttyS2) failed: Permission denied

HTH,


Yaakov


--=-afkzDIsQJg8YOmbF+gaJ
Content-Disposition: attachment; filename="test.c"
Content-Type: text/x-csrc; name="test.c"; charset="UTF-8"
Content-Transfer-Encoding: 7bit

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define DEVICE "/dev/ttyS2"

int main(void) {
	int fd;
	fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fd < 0) {
        fprintf(stderr, "first open(%s) failed: %s\n", DEVICE, strerror(errno));
		return 1;
	}
	fd = open(DEVICE, O_RDWR);
	if (fd < 0)
        fprintf(stderr, "second open(%s) failed: %s\n", DEVICE, strerror(errno));
		return 2;
	close(fd);
	return 0;
}


--=-afkzDIsQJg8YOmbF+gaJ
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--=-afkzDIsQJg8YOmbF+gaJ--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019