[PATCH] add lockdev support

Ludwig Nussel ludwig.nussel at suse.de
Wed Aug 24 10:02:38 UTC 2011


# HG changeset patch
# User Ludwig Nussel <ludwig.nussel at suse.de>
# Date 1314179450 -7200
# Node ID 6390a90a5b628a36e2a7103b915f63f7e822fa30
# Parent  be40545ff1e5705c0c34abe8f64f190a39c6cc7e
add lockdev support

diff -r be40545ff1e5 -r 6390a90a5b62 configure.in
--- a/configure.in	Sat Jul 23 21:23:52 2011 +0200
+++ b/configure.in	Wed Aug 24 11:50:50 2011 +0200
@@ -39,6 +39,11 @@
 	AC_DEFINE(USE_SOCKET, [1], [Socket support is enabled])
 fi
 
+PKG_PROG_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+	PKG_CHECK_MODULES([LOCKDEV], [lockdev], AC_DEFINE([HAVE_LOCKDEV],[1],[Define if you have lockdev]),[:])
+fi
+
 AC_ARG_ENABLE([lock-dir],
 	AS_HELP_STRING([--enable-lock-dir=DIR],
 	               [Set com line lock directory (def: try common locations)]),
diff -r be40545ff1e5 -r 6390a90a5b62 src/Makefile.am
--- a/src/Makefile.am	Sat Jul 23 21:23:52 2011 +0200
+++ b/src/Makefile.am	Wed Aug 24 11:50:50 2011 +0200
@@ -29,7 +29,7 @@
 AM_CPPFLAGS = @CPPFLAGS@ -I$(top_srcdir)/lib -DCONFDIR=\"$(confdir)\" \
               -DLOCALEDIR=\"$(datadir)/locale\"
 
-minicom_LDADD = @LIBINTL@ $(LIBICONV) $(MINICOM_LIBPORT)
+minicom_LDADD = @LIBINTL@ $(LIBICONV) $(MINICOM_LIBPORT) $(LOCKDEV_LIBS)
 minicom_keyserv_LDADD = @LIBINTL@ $(MINICOM_LIBPORT)
 runscript_LDADD = @LIBINTL@ $(MINICOM_LIBPORT)
 
diff -r be40545ff1e5 -r 6390a90a5b62 src/main.c
--- a/src/main.c	Sat Jul 23 21:23:52 2011 +0200
+++ b/src/main.c	Wed Aug 24 11:50:50 2011 +0200
@@ -165,6 +165,18 @@
   int s_errno;
 #endif
 
+#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;
+    }
+#endif
+
+  if (portfd_is_socket)
+    goto nolock;
+
+#if !HAVE_LOCKDEV
   /* First see if the lock file directory is present. */
   if (P_LOCK[0] && stat(P_LOCK, &stt) == 0) {
 
@@ -212,10 +224,12 @@
       return -1;
     }
   }
+#endif
 
-  if (doinit > 0)
-    lockfile_create();
+  if (doinit > 0 && lockfile_create() != 0)
+	  return -1;
 
+nolock:
   /* Run a special program to disable callin if needed. */
     if (doinit > 0 && P_CALLOUT[0]) {
       if (fastsystem(P_CALLOUT, NULL, NULL, NULL) < 0) {
@@ -233,11 +247,7 @@
     signal(SIGALRM, get_alrm);
     alarm(20);
 #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;
-
+    if (portfd_is_socket) {
       portfd_sock_addr.sun_family = AF_UNIX;
       strncpy(portfd_sock_addr.sun_path,
               dial_tty + strlen(SOCKET_PREFIX),
diff -r be40545ff1e5 -r 6390a90a5b62 src/minicom.c
--- a/src/minicom.c	Sat Jul 23 21:23:52 2011 +0200
+++ b/src/minicom.c	Wed Aug 24 11:50:50 2011 +0200
@@ -1627,8 +1627,7 @@
   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 -r be40545ff1e5 -r 6390a90a5b62 src/minicom.h
--- a/src/minicom.h	Sat Jul 23 21:23:52 2011 +0200
+++ b/src/minicom.h	Wed Aug 24 11:50:50 2011 +0200
@@ -35,6 +35,10 @@
 
 #include <time.h>
 
+#if HAVE_LOCKDEV
+#include <ttylock.h>
+#endif
+
 #ifdef USE_SOCKET
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -294,7 +298,7 @@
 void domacros(void);
 
 
-void lockfile_create(void);
+int lockfile_create(void);
 void lockfile_remove(void);
 
 
diff -r be40545ff1e5 -r 6390a90a5b62 src/updown.c
--- a/src/updown.c	Sat Jul 23 21:23:52 2011 +0200
+++ b/src/updown.c	Wed Aug 24 11:50:50 2011 +0200
@@ -29,6 +29,8 @@
 #include <config.h>
 #endif
 
+#include <wchar.h>
+
 #include "port.h"
 #include "minicom.h"
 #include "intl.h"
@@ -441,16 +443,31 @@
 
 void lockfile_remove(void)
 {
+  if (portfd_is_socket)
+    return;
+
+#if !HAVE_LOCKDEV
   if (lockfile[0])
     unlink(lockfile);
+#else
+  ttyunlock(dial_tty);
+#endif
 }
 
-void lockfile_create(void)
+int lockfile_create(void)
 {
-  int fd, n;
+  int n;
+#if !HAVE_LOCKDEV
+  int fd;
+  char buf[81];
+#endif
 
+  if (portfd_is_socket)
+    return 0;
+
+#if !HAVE_LOCKDEV
   if (!lockfile[0])
-    return;
+    return 0;
 
   n = umask(022);
   /* Create lockfile compatible with UUCP-1.2 */
@@ -468,6 +485,16 @@
     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);
+  }
+  return n;
+#endif
 }
 
 /*



More information about the minicom-devel mailing list