Skip to content

On Linux, lock serial ports for exclusive access using flock() #156

@cmcqueen

Description

@cmcqueen

In dll/serialunix/libnserial/openserial.c, I notice the code can optionally do a TIOCEXCL lock.

#if defined HAVE_TERMIOS_EXCLUSIVE
  if (ioctl(handle->fd, TIOCEXCL)) {
    nslog(handle, NSLOG_NOTICE, "open: error setting TIOCEXCL: errno=%d", errno);
  }
#endif

But in Linux, it's common to use a flock() advisory lock on serial ports. Something like

  if (flock( handle->fd, LOCK_EX | LOCK_NB )) {
    nslog(handle, NSLOG_NOTICE, "open: error getting exclusive lock: errno=%d", errno);
  }

See eg picocom.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions