Disabling lockfile warnings when the device disappears (ttyUSB hot unplug)

This commit is contained in:
Jaromir Capik 2013-06-25 12:25:46 +02:00
parent 235527be66
commit b4bce1ce0b
8 changed files with 112 additions and 352 deletions

View File

@ -1,11 +0,0 @@
diff -Naur minicom-2.5.old/configure.in minicom-2.5/configure.in
--- minicom-2.5.old/configure.in 2012-11-21 17:10:32.000000000 +0100
+++ minicom-2.5/configure.in 2012-11-21 17:32:24.146297983 +0100
@@ -174,7 +174,6 @@
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
-AM_C_PROTOTYPES
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_PID_T

View File

@ -1,99 +0,0 @@
diff -up ./man/minicom.1.orig ./man/minicom.1
--- ./man/minicom.1.orig 2010-08-09 21:54:03.000000000 +0200
+++ ./man/minicom.1 2011-02-09 11:24:42.972547002 +0100
@@ -16,7 +16,7 @@ minicom \- friendly serial communication
.SH DESCRIPTION
.B minicom
is a communication program which somewhat resembles the shareware
-program TELIX but is free with source code and runs under most unices.
+program TELIX but is free with source code and runs under most Unices.
Features include dialing directory with auto-redial, support for
UUCP-style lock files on serial devices, a separate script language
interpreter, capture to file, multiple users with individual
@@ -35,10 +35,10 @@ minicom. For most systems, reasonable de
.TP 0.5i
.B \-o
Do not initialize. Minicom will skip the initialization code. This
-option is handy if you quitted from minicom without resetting, and
+option is handy if you quit from minicom without resetting, and
then want to restart a session. It is potentially dangerous though: no
check for lock files etc. is made, so a normal user could interfere
-with things like uucp... Maybe this will be taken out later. For now
+with things like UUCP... maybe this will be taken out later. For now
it is assumed, that users who are given access to a modem are
responsible enough for their actions.
.TP 0.5i
@@ -65,7 +65,7 @@ and that have the relevant information i
translation of characters with the high bit set. With this flag on,
minicom will try to translate the IBM line characters to ASCII. Many PC-unix
clones will display character correctly without translation (Linux in a
-special mode, Coherent and Sco).
+special mode, Coherent and SCO).
.TP 0.5i
.B \-L
Ditto but assume screen uses an ISO8859 character set.
@@ -118,7 +118,7 @@ completed.
.BR P seudo
terminal
to use. This overrides the terminal port defined in the configuration
-files, but only if it is a pseudo tty. The filename supplied must be of
+files, but only if it is a pseudo TTY. The filename supplied must be of
the form (/dev/)tty[p-z/][0-f], (/dev/)pts[p-z/][0-f] or
(/dev/)pty[p-z/][0-f]. For example, /dev/ttyp1, pts/0 or /dev/ptyp2.
.TP 0.5i
@@ -189,7 +189,7 @@ sensible is to use device names, such as
user creates his own configuration file, it will show up in his home
directory as ".minirc.dfl" or ".minirc.\fIconfiguration\fR\|".
.SH USE
-Minicom is window based. To popup a window with the function you
+Minicom is window based. To pop-up a window with the function you
want, press Control-A (from now on, we will use C-A to mean
Control-A), and then the function key (a-z or A-Z). By pressing C-A
first and then 'z', a help screen comes up with a short summary of all
@@ -500,8 +500,8 @@ file and directory menu is used.
.TP 0.5i
.B A - Serial device
/dev/tty1 or /dev/ttyS1 for most people.
-/dev/cua<n> is still possible under linux, but not recommended any more
-because these devices are obsolete and many newly installed systems
+/dev/cua<n> is still possible under GNU/Linux, but no longer recommended
+as these devices are obsolete and many systems
with kernel 2.2.x or newer don't have them.
Use /dev/ttyS<n> instead.
You may also have /dev/modem as a symlink to the real device.
@@ -510,7 +510,7 @@ If you have modems connected to two or m
all of them here in a list separated by space, comma or semicolon. When
Minicom starts, it checks the list until it finds an available modem and
uses that one. (However, you can't specify different init strings to
-them ..at least not yet.)
+them... at least not yet.)
.br
To use a UNIX socket for communication the device name must be prefixed
with "unix#" following by the full path and the filename of the socket.
@@ -520,7 +520,7 @@ establishes, minicom goes 'online'. If t
switches to 'offline' again.
.TP 0.5i
.B B - Lock file location
-On most systems This should be /usr/spool/uucp. Linux systems use
+On most systems This should be /usr/spool/uucp. GNU/Linux systems use
/var/lock. If this directory does not exist,
minicom will not attempt to use lockfiles.
.TP 0.5i
@@ -799,7 +799,7 @@ to get the escape key, you had to press
.PP
As of release 1.3 this has bettered a little: now a 1-second timeout
is builtin, like in vi. For systems that have the select() system call
-the timeout is 0.5 seconds. And... surprise: a special Linux-dependant
+the timeout is 0.5 seconds. And... surprise: a special Linux-dependent
.BR hack " :-) was added. Now, minicom can separate the escape key and"
escape-sequences. To see how dirty this was done, look into wkeys.c.
But it works like a charm!
@@ -837,7 +837,7 @@ for new versions since 1.78, helped by s
filipg@paranoia.com wrote the History buffer searching to 1.79.
.br
Arnaldo Carvalho de Melo (acme@conectiva.com.br) did the internationalization
-and the Brasilian Portuguese translations.
+and the Brazilian Portuguese translations.
.br
Jim Seymour (jseymour@jimsun.LinxNet.com) wrote the multiple modem support
and the filename selection window used since 1.80.

View File

@ -1,23 +0,0 @@
diff -up ./man/runscript.1.orig ./man/runscript.1
--- ./man/runscript.1.orig 2009-12-12 16:47:47.000000000 +0100
+++ ./man/runscript.1 2011-02-09 11:29:34.821547000 +0100
@@ -12,8 +12,8 @@ runscript \- script interpreter for mini
.SH DESCRIPTION
.B runscript
is a simple script interpreter that can be called from within the minicom
-communications program to automate tasks like logging in to a unix system
-or your favorite bbs.
+communications program to automate tasks like logging in to a Unix system
+or your favorite BBS.
.SH INVOCATION
The program expects a script name and optionally a filename and the
user's home directory as arguments, and it expects that it's input and
@@ -155,7 +155,7 @@ finishes without errors, the original sc
Write text to the logfile.
.SH NOTES
If you want to make your script to exit minicom (for example when
-you use minicom to dial up your ISP, and then start a ppp or slip
+you use minicom to dial up your ISP, and then start a PPP or SLIP
session from a script), try the command "! killall \-9 minicom" as
the last script command. The \-9 option should prevent minicom from
hanging up the line and resetting the modem before exiting.

View File

@ -1,18 +0,0 @@
diff --git a/src/file.c b/src/file.c
index ba3a1ee..fa60950 100644
--- a/src/file.c
+++ b/src/file.c
@@ -331,7 +331,12 @@ static int new_filedir(GETSDIR_ENTRY *o_dirdat, int flushit)
return -1;
}
- rval = chdir(work_dir);
+ /* chdir success doesn't guarantee that directory is readable */
+ if(access(work_dir, R_OK) == 0)
+ rval = chdir(work_dir);
+ else
+ rval = -1;
+
if (rval == 0) {
/* was able to change to new working directory */
free(prev_dir);

View File

@ -1,173 +0,0 @@
diff -up minicom-2.5/configure.in.rh minicom-2.5/configure.in
--- minicom-2.5/configure.in.rh 2011-10-07 18:59:53.741694461 +0200
+++ minicom-2.5/configure.in 2011-10-07 18:59:53.742694449 +0200
@@ -152,6 +152,7 @@ if test "x$found_termcap_h" != "x1"; the
fi
AC_CHECK_LIB(socket, socket)
+AC_CHECK_LIB(lockdev, ttylock)
dnl Checks for header files.
AC_HEADER_DIRENT
diff --git a/src/main.c b/src/main.c
index bc4db89..8e68e2c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -154,16 +154,22 @@ void term_socket_close(void)
int open_term(int doinit, int show_win_on_error, int no_msgs)
{
struct stat stt;
+#ifdef NOTNOW
union {
char bytes[128];
int kermit;
} buf;
- int fd, n = 0;
+ int fd;
int pid;
+#endif
+ int rc;
+ int n = 0;
#ifdef HAVE_ERRNO_H
int s_errno;
#endif
+#ifdef NOTNOW
+
/* First see if the lock file directory is present. */
if (P_LOCK[0] && stat(P_LOCK, &stt) == 0) {
@@ -215,6 +221,47 @@ int open_term(int doinit, int show_win_on_error, int no_msgs)
if (doinit > 0)
lockfile_create();
+#else
+ lockfile[0] = 0;
+ if (doinit > 0) {
+#ifdef USE_SOCKET
+ if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) == 0) {
+ if (stat(dial_tty+strlen(SOCKET_PREFIX), &stt) == 0 &&
+ S_ISSOCK(stt.st_mode)) {
+ rc = 0;
+ } else {
+ rc = 1;
+ if (!no_msgs)
+ fprintf(stderr, _("File %s is not a socket.\n"),
+ dial_tty+strlen(SOCKET_PREFIX));
+ }
+ } else {
+#endif
+ rc = ttylock(dial_tty);
+ if(!no_msgs) {
+ if (rc < 0) {
+ if (access(dial_tty, W_OK) == -1)
+ fprintf(stderr, _("Device %s access failed: %s.\n"),
+ dial_tty, strerror(errno));
+ else
+ fprintf(stderr, _("Device %s lock failed: %s.\n"),
+ dial_tty, strerror(-rc));
+ } else if (rc > 0) {
+ fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
+ }
+ }
+#ifdef USE_SOCKET
+ }
+#endif
+ if (rc == 0) {
+ snprintf(lockfile, sizeof(lockfile), "%s", dial_tty);
+ } else {
+ if (!no_msgs && stdwin) mc_wclose(stdwin, 1);
+ return(-1);
+ }
+ }
+#endif
+
/* Run a special program to disable callin if needed. */
if (doinit > 0 && P_CALLOUT[0]) {
if (fastsystem(P_CALLOUT, NULL, NULL, NULL) < 0) {
@@ -232,7 +276,6 @@ int open_term(int doinit, int show_win_on_error, int no_msgs)
signal(SIGALRM, get_alrm);
alarm(4);
#ifdef USE_SOCKET
-#define SOCKET_PREFIX "unix#"
portfd_is_socket = portfd_is_connected = 0;
if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) == 0) {
portfd_is_socket = 1;
diff --git a/src/minicom.c b/src/minicom.c
index 7780ff7..8b26f0d 100644
--- a/src/minicom.c
+++ b/src/minicom.c
@@ -1569,8 +1569,7 @@ dirty_goto:
mc_wclose(st, 0);
mc_wclose(stdwin, 1);
keyboard(KUNINSTALL, 0);
- if (lockfile[0])
- unlink(lockfile);
+ lockfile_remove();
close(portfd);
if (quit != NORESET && P_CALLIN[0])
diff --git a/src/minicom.h b/src/minicom.h
index 309d54a..83f3fca 100644
--- a/src/minicom.h
+++ b/src/minicom.h
@@ -34,10 +34,14 @@
#include "libport.h"
#include <time.h>
+#include <limits.h>
+#include <ttylock.h>
#ifdef USE_SOCKET
#include <sys/socket.h>
#include <sys/un.h>
+
+#define SOCKET_PREFIX "unix#"
#endif
/*
@@ -82,7 +86,7 @@ EXTERN int tempst; /* Status line is temporary */
EXTERN int escape; /* Escape code. */
EXTERN int disable_online_time; /* disable online time display */
-EXTERN char lockfile[128]; /* UUCP lock file of terminal */
+EXTERN char lockfile[PATH_MAX]; /* UUCP lock file of terminal */
EXTERN char homedir[256]; /* Home directory of user */
EXTERN char logfname[PARS_VAL_LEN]; /* Name of the logfile */
EXTERN char username[16]; /* Who is using minicom? */
diff --git a/src/updown.c b/src/updown.c
index 24531a2..23194e4 100644
--- a/src/updown.c
+++ b/src/updown.c
@@ -441,12 +441,14 @@ void updown(int what, int nr)
void lockfile_remove(void)
{
- if (lockfile[0])
- unlink(lockfile);
+ if (lockfile[0] && strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) != 0)
+ ttyunlock(lockfile);
}
void lockfile_create(void)
{
+ int rc;
+#ifdef NOTNOW
int fd, n;
if (!lockfile[0])
@@ -468,6 +470,14 @@ void lockfile_create(void)
close(fd);
}
umask(n);
+#else
+ if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) != 0) {
+ rc = ttylock(lockfile);
+ if (rc) {
+ werror(_("Cannot lock device!"));
+ }
+ }
+#endif
}
/*

View File

@ -1,27 +0,0 @@
diff -Naur minicom-2.6.1.orig/src/config.c minicom-2.6.1/src/config.c
--- minicom-2.6.1.orig/src/config.c 2011-12-27 23:23:10.000000000 +0100
+++ minicom-2.6.1/src/config.c 2013-01-23 12:22:04.231148834 +0100
@@ -545,7 +545,11 @@
w = mc_wopen(5, 4, 75, 12, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
mc_wprintf(w, "%s %.41s\n", serial_device, P_PORT);
+#if !HAVE_LOCKDEV
mc_wprintf(w, "%s %.41s\n", lockfile_location, P_LOCK);
+#else
+ mc_wprintf(w, "\n");
+#endif
mc_wprintf(w, "%s %.41s\n", callin_program, P_CALLIN);
mc_wprintf(w, "%s %.41s\n", callout_program, P_CALLOUT);
mc_wprintf(w, "%s %s %s%s%s\n",
@@ -565,9 +569,11 @@
case 'A':
pgets(w, mbslen (serial_device) + 1, 0, P_PORT, 64, 64, 1);
break;
+#if !HAVE_LOCKDEV
case 'B':
pgets(w, mbslen (lockfile_location) + 1, 1, P_LOCK, 64, 64, 1);
break;
+#endif
case 'C':
pgets(w, mbslen (callin_program) + 1, 2, P_CALLIN, 64, 64, 1);
break;

View File

@ -0,0 +1,104 @@
diff -r 7bc59ff7fd31 -r 60a0efeec606 ChangeLog
--- a/ChangeLog Thu Feb 07 20:59:16 2013 +0100
+++ b/ChangeLog Thu Feb 07 21:00:08 2013 +0100
@@ -1,3 +1,9 @@
+2013-02-07 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
+
+ * src/main.c, src/minicom.h, src/updown.c:
+ [#314018] [PATCH] Disabling lockfile warnings when the
+ device disappears (ttyUSB hot-unplug), by Jaromir Capik
+
2013-02-06 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* NEWS: Release 2.6.2
diff -r 7bc59ff7fd31 -r 60a0efeec606 src/main.c
--- a/src/main.c Thu Feb 07 20:59:16 2013 +0100
+++ b/src/main.c Thu Feb 07 21:00:08 2013 +0100
@@ -225,7 +225,7 @@
}
#endif
- if (doinit > 0 && lockfile_create() != 0)
+ if (doinit > 0 && lockfile_create(no_msgs) != 0)
return -1;
nolock:
diff -r 7bc59ff7fd31 -r 60a0efeec606 src/minicom.h
--- a/src/minicom.h Thu Feb 07 20:59:16 2013 +0100
+++ b/src/minicom.h Thu Feb 07 21:00:08 2013 +0100
@@ -301,7 +301,7 @@
void domacros(void);
-int lockfile_create(void);
+int lockfile_create(int no_msgs);
void lockfile_remove(void);
diff -r 7bc59ff7fd31 -r 60a0efeec606 src/updown.c
--- a/src/updown.c Thu Feb 07 20:59:16 2013 +0100
+++ b/src/updown.c Thu Feb 07 21:00:08 2013 +0100
@@ -413,7 +413,7 @@
if (win == (WIN *)0)
mc_wreturn();
- lockfile_create();
+ lockfile_create(0);
/* MARK updated 02/17/94 - Flush modem port before displaying READY msg */
/* because a BBS often displays menu text right after a download, and we */
@@ -459,7 +459,7 @@
#endif
}
-int lockfile_create(void)
+int lockfile_create(int no_msgs)
{
int n;
@@ -474,25 +474,29 @@
n = umask(022);
/* Create lockfile compatible with UUCP-1.2 */
if ((fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) {
- werror(_("Cannot create lockfile!"));
+ if (!no_msgs)
+ werror(_("Cannot create lockfile!"));
} else {
// FHS format:
char buf[12];
snprintf(buf, sizeof(buf), "%10d\n", getpid());
buf[sizeof(buf) - 1] = 0;
if (write(fd, buf, strlen(buf)) < (ssize_t)strlen(buf))
- fprintf(stderr, _("Failed to write lockfile %s\n"), lockfile);
+ if (!no_msgs)
+ fprintf(stderr, _("Failed to write lockfile %s\n"), lockfile);
close(fd);
}
umask(n);
return 0;
#else
n = ttylock(dial_tty);
- if (n < 0) {
- fprintf(stderr, _("Cannot create lockfile for %s: %s\n"), dial_tty, strerror(-n));
- } else if (n > 0) {
- fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
- }
+ if (!no_msgs)
+ {
+ if (n < 0)
+ fprintf(stderr, _("Cannot create lockfile for %s: %s\n"), dial_tty, strerror(-n));
+ else if (n > 0)
+ fprintf(stderr, _("Device %s is locked.\n"), dial_tty);
+ }
return n;
#endif
}
@@ -546,7 +550,7 @@
mc_wreturn();
/* Re-create lockfile */
- lockfile_create();
+ lockfile_create(0);
m_flush(portfd);
port_init();

View File

@ -1,7 +1,7 @@
Summary: A text-based modem control and terminal emulation program
Name: minicom
Version: 2.6.2
Release: 1%{?dist}
Release: 2%{?dist}
URL: http://alioth.debian.org/projects/minicom/
License: GPL+ and GPLv2+ and GPLv2 and Public Domain and Copyright only
Group: Applications/Communications
@ -11,6 +11,8 @@ Requires: lockdev lrzsz
Source0: https://alioth.debian.org/frs/download.php/3869/minicom-2.6.2.tar.gz
Patch0: minicom-2.6.2-no-lockfile-messages-with-detached-ttyusb.patch
%description
Minicom is a simple text-based modem control and terminal emulation
program somewhat similar to MSDOS Telix. Minicom includes a dialing
@ -20,6 +22,8 @@ language, and other features.
%prep
%setup -q
%patch0 -p1 -b .no-lock-warn
cp -pr doc doc_
rm -f doc_/Makefile*
@ -45,6 +49,9 @@ mkdir -p %{buildroot}%{_sysconfdir}
%{_mandir}/man1/*
%changelog
* Thu Feb 07 2013 Jaromir Capik <jcapik@redhat.com> - 2.6.2-2
- Disabling lockfile warnings when the device disappears (ttyUSB hot unplug)
* Thu Feb 07 2013 Jaromir Capik <jcapik@redhat.com> - 2.6.2-1
- Update to 2.6.2