Blob Blame History Raw
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
 }
 
 /*