PortInUse Exception in SerialDemo

Using JRE 1.4.2_12 on SCO OpenServer 5.0.7, I was able to use the Java Comm Api to open and close serial ports. After upgrading to JRE 1.4.2_19, the Java Comm Api complains that the ports are in use. Does anyone have any thoughts on how to make 1.4.2_19 work with Java Comm API?
FYI. I was using the SerialDemo java program as a test.

Thanks in advance.

After further testing, I am able to open the Serial Port while logged in as root, but not logged in as a user. Any help would be appreciated.
Thanks.

This may be file permissions, check the permissions on the device file itself.

I changed the owner to the user logged in.
I changed the group to a group that user has access to.
The permissions read crw-rw-rw-
No luck.

Also, I no longer believe this is a java issue. I did a fresh install of sco using java 1.4.2_12 and have the same behavior.

What about the JVM, which their program techically runs inside?

Thanks Corona but I guess I am not as familiar with SCO as I should be. How would I go about changing the permissions for the JVM? Is it simply a matter of finding the .exe file and changing it's permissions?

---------- Post updated at 07:36 AM ---------- Previous update was at 07:26 AM ----------

As a follow-up, I tried changing the permissions on /opt/java2-1.4.2/bin/java using chmod 777 java. That did not fix it.
Thanks.

777 is not the magic sledgehammer to fix all permissions problems. You really need to change that back to what it was before someone accidentally edits the java binary. :eek:

What you did would not have fixed the problem even if the problem is the permissions of the Java runtime environment.

The question is, what user/group/permissions does the JVM run under?

I'm not worried about someone changing any binaries (unless that someone is me). It's a demo box and I'm the only one on it.

Excuse my ignorance, but I'm a windows guy and my unix person is out all week.
How do I know what user/group us running the JVM?
I did a ps -ef but did not see anything java related.

Thanks.

The person who corrupts the java binary by accident could easily be you. The sooner you get over this habit the better -- 777 is not the magic sledgehammer to fix all permissions problems, it's dumb, and dangerous.

Try running a java program then seeing if you see the JVM in ps.

I think its not an issue of what permissions are set on java binary but an issue of what permissions are set on the serial device.

That already appears to be 666, should not be a problem.

But java is an odd language with only threads, subject to contention within itself when it tries to use real system resources.

I promise to never use 777 willy-nilly again.
I ran the SerialDemo and the only thing I see using ps is 'java SerialDemo'. I do not see the JVM or any other java process.

Can we see the code for the serial demo? Perhaps it does something odd like try to open the device twice. The behavior of that would be potentially different on different platforms.

I'm pretty sure it's not the SerialDemo code as I have created a very simple app that does nothing but scroll through the list of ports and attempt to open them.
Here's the code (hand-typed so excuse the typos):

import javax.comm.*;
import java.util.Enumeration;
public class Main {
  public Main() {
  }
  public static void main(String[] args) {
    try {
      Enumeration portList = CommPortIdentifier.getPortIdentifiers();
      while(portList.hasMoreElements()){
        CommPortIdentifier pi = (CommPortIdentifier)portList.nextElement();
        try {
          SerialPort sp = (SerialPort)pi.open("TEST", 5000);
        } catch(PortInUseException piue) {
          System.out.println("Port In Use");
        }
      }
    } catch(Exception e) {
      System.out.println(e.getMessage());
    }
  }
}

You should have it print the name of the port, too. Perhaps something strange has ended up in the port list somehow, like a foreign TTY.

I had it print the name of the ports and the list is as expected (tty1a, tty1A, tty2a, tty2A). I also changed the owner and group of every file and directory associated with the JRE. I still get the same issue.

It doesn't appear that there is a fix for this issue.
I would have tried an updated Java Communications API, but 2.0Aa is the only version available. There was talk of a 3.0 version, but there is nowhere to download it from.

Maybe it isn't lying. Are any of these terminals being used for logins? As in, if you hooked up a serial terminal to them, would you get a login screen? If so, they will be busy.

No. Logins are disabled for these ports.

---------- Post updated at 01:32 PM ---------- Previous update was at 11:25 AM ----------

I tried setting java to run asroot, but this did not work.
Any idea how I can make java_vm run as root? When I set it up according to the instructions, it's still running as my user.
Here are the steps I took:
copy java_vm from jre/bin to /tcb/files/rootcmds
edit /etc/auth/system/authorize to include java_vm for the root subsystem authorization.
Using User Manager, grant my user the root authorization.
Restart and log in as me.
Start app.
run "ps -ef|grep java"
this shows java_vm running as me.

Any help would be greatly appreciated.

It runs as you because you're running it as you.

You really shouldn't be forcing java to run as root. If you have permissions to open the file, and java is running as you, java has permissions to open the file.

Do you have lsof? Try and track down what has the file open or locked. I'm not convinced the error message is a lie.

The problem is that I am not sure what's causing the issue. I can run my app fine when I am logged in as root but not when I am logged in as me.
I was really just running this as a test to see where the permissions issue is.
Apparently, I don't have access to something.

lsof returns nothing for /dev/tty1a

FYI. I did a fresh install of SCO and installed nothing but java. Still got the same error.