1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Added support for locking using flock(2) (now default)

Fixes #26
Old-style UUCP-lockdir code is maintained.
Preferred locking style is selected via the Makefile
This commit is contained in:
Nick Patavalis
2015-08-07 08:21:09 +03:00
parent 208bb118e6
commit 110c15ea3c
2 changed files with 23 additions and 6 deletions

View File

@ -16,9 +16,15 @@ CPPFLAGS += -DTTY_Q_SZ=$(TTY_Q_SZ)
## Comment this out to disable high-baudrate support
CPPFLAGS += -DHIGH_BAUD
## Normally you should NOT enable both: UUCP-style and flock(2)
## locking.
## Comment this out to disable locking with flock
CPPFLAGS += -DUSE_FLOCK
## Comment these out to disable UUCP-style lockdirs
UUCP_LOCK_DIR=/var/lock
CPPFLAGS += -DUUCP_LOCK_DIR=\"$(UUCP_LOCK_DIR)\"
#UUCP_LOCK_DIR=/var/lock
#CPPFLAGS += -DUUCP_LOCK_DIR=\"$(UUCP_LOCK_DIR)\"
## Comment these out to disable "linenoise"-library support
SEND_RECEIVE_HISTFILE = .picocom_send_receive

View File

@ -37,6 +37,9 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <limits.h>
#ifdef USE_FLOCK
#include <sys/file.h>
#endif
#ifdef LINENOISE
#include <dirent.h>
#include <libgen.h>
@ -151,7 +154,7 @@ struct {
int lecho;
int noinit;
int noreset;
#ifdef UUCP_LOCK_DIR
#if defined (UUCP_LOCK_DIR) || defined (USE_FLOCK)
int nolock;
#endif
unsigned char escape;
@ -171,7 +174,7 @@ struct {
.lecho = 0,
.noinit = 0,
.noreset = 0,
#ifdef UUCP_LOCK_DIR
#if defined (UUCP_LOCK_DIR) || defined (USE_FLOCK)
.nolock = 0,
#endif
.escape = '\x01',
@ -1172,7 +1175,7 @@ parse_args(int argc, char *argv[])
opts.noreset = 1;
break;
case 'l':
#ifdef UUCP_LOCK_DIR
#if defined (UUCP_LOCK_DIR) || defined (USE_FLOCK)
opts.nolock = 1;
#endif
break;
@ -1274,7 +1277,7 @@ parse_args(int argc, char *argv[])
printf("local echo is : %s\n", opts.lecho ? "yes" : "no");
printf("noinit is : %s\n", opts.noinit ? "yes" : "no");
printf("noreset is : %s\n", opts.noreset ? "yes" : "no");
#ifdef UUCP_LOCK_DIR
#if defined (UUCP_LOCK_DIR) || defined (USE_FLOCK)
printf("nolock is : %s\n", opts.nolock ? "yes" : "no");
#endif
printf("send_cmd is : %s\n", opts.send_cmd);
@ -1311,6 +1314,14 @@ main(int argc, char *argv[])
if (tty_fd < 0)
fatal("cannot open %s: %s", opts.port, strerror(errno));
#ifdef USE_FLOCK
if ( ! opts.nolock ) {
r = flock(tty_fd, LOCK_EX | LOCK_NB);
if ( r < 0 )
fatal("cannot lock %s: %s", opts.port, strerror(errno));
}
#endif
if ( opts.noinit ) {
r = term_add(tty_fd);
} else {