Bug 80228 - Kandy can not lock device, needs to use lockdev
Summary: Kandy can not lock device, needs to use lockdev
Status: RESOLVED FIXED
Alias: None
Product: kandy
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Peter Rockai
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-23 21:40 UTC by Aleksey Nogin
Modified: 2005-04-08 15:26 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksey Nogin 2004-04-23 21:40:43 UTC
Version:            (using KDE KDE 3.2.2)
Installed from:    RedHat RPMs
OS:          Linux

In Red Hat (and probably some other distros as well), applications are not allowed to write to /var/lock directly. Instead they are supposed to use the lockdev library (which implements locking by calling a setgid helper binary). The configure script for kandy should check for the presence of the ttylock.h (or lockdev.h if a lower-level access is desired) and use lockdev for locking.
Comment 1 Aleksey Nogin 2004-04-23 21:41:24 UTC
See also https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=84143
Comment 2 Cornelius Schumacher 2004-04-24 10:54:31 UTC
I don't have a distribution using lockdev here, so if you would like to see support for this the best way would be to provide a patch.
Comment 3 Heiko Falk 2004-11-17 08:52:39 UTC
Similar problems arise on Sun's Solaris OS, since /var/lock doesn't exist at all. This problem is solved by providing a new element in the Kandy configuration dialog, category "Serial Device". There, you can now enter a directory where Kandy should place its LOCK file. If you enter /tmp there, it works on my Sun, and it's likely to work also for Red Hat.

However, it's not very nice that Kandy doesn't issue any warning or so if the modem connection can not be established. The user is left alone here without any helpful notifications...
Comment 4 Aleksey Nogin 2004-11-17 10:27:08 UTC
Placing the locks in /tmp defeats the purpose of locking since other applications would not look for them in there. On Red Hat and other distors that use lockdev, this is the preferred way of locking and it would be nice if it was supported.
Comment 5 Peter Rockai 2005-03-15 17:49:43 UTC
Gonna address this (see also https://bugzilla.redhat.com/beta/show_bug.cgi?id=84143).
Comment 6 Peter Rockai 2005-03-17 15:21:36 UTC
CVS commit by mornfall: 

Make kandy use lockdev instead of by-hand locking code, if available.
BUGS:80228


  M +12 -15    configure.in.in   1.3
  M +1 -1      src/Makefile.am   1.13
  M +18 -4     src/modem.cpp   1.10


--- kdepim/kandy/src/Makefile.am  #1.12:1.13
@@ -4,5 +4,5 @@
 
 kandy_LDFLAGS = $(KDE_RPATH) $(all_libraries)
-kandy_LDADD   = $(LIB_KFILE) -lkabc $(top_builddir)/libkdepim/libkdepim.la
+kandy_LDADD   = $(KANDY_LIBLOCKDEV) $(LIB_KFILE) -lkabc $(top_builddir)/libkdepim/libkdepim.la
 kandy_SOURCES = main.cpp kandy.cpp \
                 cmdpropertiesdialog_base.ui cmdpropertiesdialog.cpp \

--- kdepim/kandy/src/modem.cpp  #1.9:1.10
@@ -265,7 +265,20 @@ void Modem::flush()
 }
 
+#ifdef HAVE_LOCKDEV
+#include <lockdev.h>
+#endif
 
 bool Modem::lockDevice()
 {
+  if ( is_locked )
+    return true;
+
+#ifdef HAVE_LOCKDEV
+  is_locked = !dev_lock( (*prefs).serialDevice().local8Bit() );
+  if (!is_locked)
+      emit errorMessage( i18n( "Unable to lock device '%1'." ).arg(
+                             (*prefs).serialDevice() ));
+  return is_locked;
+#else
   ssize_t count;
   pid_t pid;
@@ -275,8 +288,4 @@ bool Modem::lockDevice()
   QString fileName, content;
 
-
-  if ( is_locked )
-    return true;
-
   pathList = QStringList::split( "/", (*prefs).serialDevice() );
   fileName = (*prefs).lockDirectory() + "/LCK.." + pathList.last();
@@ -338,4 +347,5 @@ bool Modem::lockDevice()
 
   return true;
+#endif
 }
 
@@ -343,4 +353,7 @@ bool Modem::lockDevice()
 void Modem::unlockDevice()
 {
+#ifdef HAVE_LOCKDEV
+  dev_unlock( (*prefs).serialDevice().local8Bit(), getpid() );
+#else
   if ( is_locked ) {
     QStringList pathList = QStringList::split( "/", (*prefs).serialDevice() );
@@ -349,4 +362,5 @@ void Modem::unlockDevice()
     is_locked = false;
   }
+#endif
 }