Skip to content
This repository was archived by the owner on Feb 4, 2024. It is now read-only.

Add an option for exclusive port access #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions picocom.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ Picocom accepts the following command-line options.
is system dependent. On most systems the signal is raised.


**--excl**

: Open the port exclusively using TIOCEXCL ioctl.

**--exit-aftrer** | **-x**

: Exit picocom if it remains idle for the specified time (in
Expand Down
11 changes: 11 additions & 0 deletions picocom.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <limits.h>
#ifdef USE_FLOCK
#include <sys/file.h>
Expand Down Expand Up @@ -218,6 +219,7 @@ struct {
int lower_dtr;
int raise_rts;
int raise_dtr;
int excl;
int quiet;
} opts = {
.port = NULL,
Expand Down Expand Up @@ -248,6 +250,7 @@ struct {
.lower_dtr = 0,
.raise_rts = 0,
.raise_dtr = 0,
.excl = 0,
.quiet = 0
};

Expand Down Expand Up @@ -1657,6 +1660,7 @@ show_usage(char *name)
printf(" --raise-rts\n");
printf(" --lower-dtr\n");
printf(" --raise-dtr\n");
printf(" --excl\n");
printf(" --<q>uiet\n");
printf(" --<h>elp\n");
printf("<map> is a comma-separated list of one or more of:\n");
Expand Down Expand Up @@ -1716,6 +1720,7 @@ parse_args(int argc, char *argv[])
{"lower-dtr", no_argument, 0, 2},
{"raise-rts", no_argument, 0, 3},
{"raise-dtr", no_argument, 0, 4},
{"excl", no_argument, 0, 5},
{"quiet", no_argument, 0, 'q'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
Expand Down Expand Up @@ -1895,6 +1900,9 @@ parse_args(int argc, char *argv[])
case 4:
opts.raise_dtr = 1;
break;
case 5:
opts.excl = 1;
break;
case 'x':
opts.exit_after = strtol(optarg, &ep, 10);
if ( ! ep || *ep != '\0' || opts.exit_after < 0 ) {
Expand Down Expand Up @@ -2072,6 +2080,9 @@ main (int argc, char *argv[])
if (tty_fd < 0)
fatal("cannot open %s: %s", opts.port, strerror(errno));

if (opts.excl)
ioctl(tty_fd, TIOCEXCL);

#ifdef USE_FLOCK
if ( ! opts.nolock ) {
r = flock(tty_fd, LOCK_EX | LOCK_NB);
Expand Down