From 72f85e1c16bf6ba5e88da08d45ef2c0d63537040 Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Wed, 9 Oct 2019 19:12:40 +0300 Subject: [PATCH] Add an option for exclusive port access --- picocom.1.md | 4 ++++ picocom.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/picocom.1.md b/picocom.1.md index 15fc74a..1664a79 100644 --- a/picocom.1.md +++ b/picocom.1.md @@ -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 diff --git a/picocom.c b/picocom.c index 96021a1..8e42ea0 100644 --- a/picocom.c +++ b/picocom.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #ifdef USE_FLOCK #include @@ -218,6 +219,7 @@ struct { int lower_dtr; int raise_rts; int raise_dtr; + int excl; int quiet; } opts = { .port = NULL, @@ -248,6 +250,7 @@ struct { .lower_dtr = 0, .raise_rts = 0, .raise_dtr = 0, + .excl = 0, .quiet = 0 }; @@ -1657,6 +1660,7 @@ show_usage(char *name) printf(" --raise-rts\n"); printf(" --lower-dtr\n"); printf(" --raise-dtr\n"); + printf(" --excl\n"); printf(" --uiet\n"); printf(" --elp\n"); printf(" is a comma-separated list of one or more of:\n"); @@ -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} @@ -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 ) { @@ -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);