Open2300 - Bug Report 2006x 02x 06x 211509
You are here: Foswiki>Open2300 Web>BugReports>BugReport2006x02x06x211509 (11 Feb 2007, DiomidisSpinellis)Edit Attach

BUG: Opening of serial device fails under FreeBSD 6.0 and Open2300 v1.10

Running Open2300 v1.10 under FreeBSD 6.0 produces:
Serial device is locked by other program
: Operation not supported
First I thought changes in FreeBSD were to blame (the serial device in 6.0 is now at /dev/cuad0), but interestingly, v1.8 of Open2300 works fine on the same system.

Obviously, the new code in linux2300.c must be problematic under FreeBSD 6.0 in some way. Here is the relevant portion of the diff between v1.8 and v1.10 of linux2300.c:
@@ -14,6 +14,7 @@
 #define DEBUG 0

 #include <errno.h>
+#include <sys/file.h>
 #include "rw2300.h"

 /********************************************************************
@@ -35,10 +36,18 @@
        if ((ws2300 = open(device, O_RDWR | O_NOCTTY)) < 0)
        {
                printf("\nUnable to open serial device %s\n", device);
- -               exit(0);
+               exit(EXIT_FAILURE);
        }
- -
- -       tcgetattr(ws2300, &adtio);
+
+       if ( flock(ws2300, LOCK_EX) < 0 ) {
+               perror("\nSerial device is locked by other program\n");
+               exit(EXIT_FAILURE);
+       }
+
+       //We want full control of what is set and simply reset the entire adtio struct
+       memset(&adtio, 0, sizeof(adtio));
+
+       //tcgetattr(ws2300, &adtio);   // Commented out and replaced by the memset above

        // Serial control options
        adtio.c_cflag &= ~PARENB;      // No parity

Test case

Environment

Open2300 version: 1.10
Shared libraries:  
Server OS: FreeBSD 6.0

-- MartinDoege - 06 Feb 2006

Follow up

Is there any easy way to let the compilor skip the flock?

Is there some environment variable that you usually use to know that it is FreeBSD?

There is another patch that I implemented which change the flock call. Maybe that works also with FreeBSD.

We will see when I release 1.11

-- KennethLavrsen - 19 Jul 2006

You can use a preprocessor macro definition as in
#ifndef __FreeBSD__
       if ( flock(ws2300, LOCK_EX) < 0 ) {
              perror("\nSerial device is locked by other program\n");
              exit(EXIT_FAILURE);
      }
#endif

Locking of serial devices in FreeBSD should be done using the uu_lock(3) function, but simply removing Linux's flock when compiling under FreeBSD is better than nothing.

-- DiomidisSpinellis - 11 Feb 2007

Fix record

BugReportForm edit

TopicTitle Opening of serial device fails under FreeBSD 6.0 and Open2300 v1.10
BugStatus Assigned
AssignedBugTo KennethLavrsen
SubmittedBy MartinDoege
Topic revision: r4 - 11 Feb 2007, DiomidisSpinellis
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.