summaryrefslogtreecommitdiffstats
path: root/kandy
diff options
context:
space:
mode:
Diffstat (limited to 'kandy')
-rw-r--r--kandy/configure.in.in12
-rw-r--r--kandy/src/CMakeLists.txt2
-rw-r--r--kandy/src/Makefile.am2
-rw-r--r--kandy/src/modem.cpp152
4 files changed, 45 insertions, 123 deletions
diff --git a/kandy/configure.in.in b/kandy/configure.in.in
deleted file mode 100644
index b3bd45583..000000000
--- a/kandy/configure.in.in
+++ /dev/null
@@ -1,12 +0,0 @@
-# check for lockdev, optionally used to lock serial device
-AH_TEMPLATE(HAVE_LOCKDEV)
-AC_CHECK_HEADERS(lockdev.h, HAVE_LOCKDEV_H=1, HAVE_LOCKDEV_H=)
-AC_SUBST(HAVE_LOCKDEV_H)
-# we check for dev_unlock since kmobile checks dev_lock, caches it
-# and the variables are messed up then... *sigh*
-if test -n "$HAVE_LOCKDEV_H"; then
- AC_CHECK_LIB(lockdev, dev_unlock,
- [KANDY_LIBLOCKDEV="-llockdev $KANDY_LIBLOCKDEV"
-AC_DEFINE(HAVE_LOCKDEV)], , $KANDY_LIBLOCKDEV)
-fi
-AC_SUBST(KANDY_LIBLOCKDEV)
diff --git a/kandy/src/CMakeLists.txt b/kandy/src/CMakeLists.txt
index 06889351e..041305919 100644
--- a/kandy/src/CMakeLists.txt
+++ b/kandy/src/CMakeLists.txt
@@ -47,7 +47,7 @@ tde_add_executable( kandy AUTOMOC
atcommand.cpp commanditem.cpp mobilegui_base.ui mobilegui.cpp
commandscheduler.cpp commandset.cpp kandyprefs.kcfgc
kandyprefsdialog.cpp mobilemain.cpp
- LINK tdepim-shared ${LOCKDEV_LIBRARY}
+ LINK tdepim-shared
DESTINATION ${BIN_INSTALL_DIR}
)
diff --git a/kandy/src/Makefile.am b/kandy/src/Makefile.am
index 7691d37be..f6187234b 100644
--- a/kandy/src/Makefile.am
+++ b/kandy/src/Makefile.am
@@ -3,7 +3,7 @@ bin_PROGRAMS = kandy kandy_client
INCLUDES = -I$(top_srcdir) $(all_includes)
kandy_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor
-kandy_LDADD = $(KANDY_LIBLOCKDEV) $(LIB_TDEFILE) -ltdeabc $(top_builddir)/libtdepim/libtdepim.la
+kandy_LDADD = $(LIB_TDEFILE) -ltdeabc $(top_builddir)/libtdepim/libtdepim.la
kandy_SOURCES = main.cpp kandy.cpp \
cmdpropertiesdialog_base.ui cmdpropertiesdialog.cpp \
kandyview.cpp \
diff --git a/kandy/src/modem.cpp b/kandy/src/modem.cpp
index 86c36d675..2a275bf4d 100644
--- a/kandy/src/modem.cpp
+++ b/kandy/src/modem.cpp
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <sys/file.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
@@ -75,10 +76,10 @@
Modem::Modem( KandyPrefs *kprefs, TQObject *parent, const char *name ) :
- TQObject(parent, name)
+ TQObject(parent, name), fd(-1)
{
mOpen = false;
-
+
prefs = kprefs;
timer = new TQTimer( this, "modemtimer" );
@@ -185,28 +186,31 @@ bool Modem::open()
{
struct termios tty;
-
close();
- if ( !lockDevice() )
- return false;
+ if (fd == -1)
+ {
+ TQCString dev = TQFile::encodeName( (*prefs).serialDevice() );
+ const char *fdev = dev.data();
+ if ( ( fd = ::open( fdev, O_RDWR | O_NOCTTY | O_NONBLOCK ) ) == -1 ) {
+ emit errorMessage( i18n( "Unable to open device '%1'. "
+ "Please check that you have sufficient permissions." )
+ .arg( fdev ) );
+ return false;
+ }
+ }
- TQCString dev = TQFile::encodeName( (*prefs).serialDevice() );
- const char *fdev = dev.data();
- if ( ( fd = ::open( fdev, O_RDWR | O_NOCTTY | O_NONBLOCK ) ) == -1 ) {
- emit errorMessage( i18n( "Unable to open device '%1'. "
- "Please check that you have sufficient permissions." )
- .arg( fdev ) );
+ if ( !lockDevice() )
return false;
- }
tcflush( fd, TCIOFLUSH );
if ( tcgetattr( fd, &init_tty ) == -1 ) {
int errnumber = errno;
emit errorMessage( i18n( "Communication setup failed (tcgetattr code: %1)" )
.arg(strerror(errnumber)) );
+ unlockDevice();
::close( fd );
- fd = 0;
+ fd = -1;
return false;
}
@@ -221,8 +225,9 @@ bool Modem::open()
if ( tcsetattr( fd, TCSANOW, &tty ) == -1 ) {
emit errorMessage( i18n( "tcsetattr() failed." ) );
+ unlockDevice();
::close( fd );
- fd = 0;
+ fd = -1;
return false;
}
@@ -244,127 +249,56 @@ void Modem::close()
delete sn;
sn = 0;
+ unlockDevice();
+
if ( fd ) {
tcflush( fd, TCIOFLUSH );
tcsetattr( fd, TCSANOW, &init_tty );
::close( fd );
- fd = 0;
+ fd = -1;
}
xreset();
- unlockDevice();
-
mOpen = false;
}
void Modem::flush()
{
- if ( fd ) {
+ if ( fd != -1) {
tcflush( fd, TCIOFLUSH );
bufpos = 0;
}
}
-#ifdef HAVE_LOCKDEV
-#include <lockdev.h>
-#endif
-
bool Modem::lockDevice()
{
- if ( is_locked )
+ 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;
- int lfd;
- struct passwd *pw;
- TQStringList pathList;
- TQString fileName, content;
-
- pathList = TQStringList::split( "/", (*prefs).serialDevice() );
- fileName = (*prefs).lockDirectory() + "/LCK.." + pathList.last();
-
- if ( !access( TQFile::encodeName( fileName ).data(), F_OK ) ) {
- char buf[256];
-
-
- if ( ( lfd = ::open( TQFile::encodeName( fileName ), O_RDONLY ) ) < 0 ) {
- emit errorMessage( i18n( "Unable to open lock file '%1'.")
- .arg( fileName ) );
- return false;
- }
-
- count = read( lfd, buf, 79 );
-
- if ( count < 0 ) {
- emit errorMessage( i18n( "Unable to read lock file '%1'.")
- .arg( fileName ) );
- ::close( lfd );
- return false;
- }
- buf[ count ] = 0;
- ::close( lfd );
-
- count = sscanf( buf, "%d", &pid );
- if ( ( count != 1 ) || ( pid <= 0 ) ) {
- emit errorMessage( i18n( "Unable to get PID from file '%1'.")
- .arg( fileName ) );
- return false;
- }
-
- if ( !kill( (pid_t) pid, 0 ) ) {
- emit errorMessage( i18n( "Process with PID %1, which is locking the device, is still running.")
- .arg( pid ) );
- return false;
- }
-
- if ( errno != ESRCH ) {
- emit errorMessage( i18n( "Unable to emit signal to PID of existing lock file.") );
- return false;
- }
- }
-
- if ( ( lfd = creat( TQFile::encodeName( fileName ).data(), 0644 ) ) == -1 ) {
- emit errorMessage( i18n( "Unable to create lock file '%1'. "
- "Please check that you have sufficient permissions.")
- .arg( fileName ) );
- return false;
+ if (flock(fd, LOCK_EX))
+ {
+ // Locking failed
+ is_locked = false;
+ emit errorMessage(i18n("Unable to lock device '%1'.").arg((*prefs).serialDevice()));
+ }
+ else
+ {
+ is_locked = true;
}
- pid = (int) getpid();
- pw = getpwuid( getuid() );
- content.sprintf( "%08d %s %s", pid, "kandy", pw->pw_name );
- write( lfd, TQFile::encodeName( content ).data(), content.length() );
- ::close( lfd );
-
- is_locked = true;
-
- return true;
-#endif
+ return is_locked;
}
void Modem::unlockDevice()
{
-#ifdef HAVE_LOCKDEV
- dev_unlock( (*prefs).serialDevice().local8Bit(), getpid() );
-#else
- if ( is_locked ) {
- TQStringList pathList = TQStringList::split( "/", (*prefs).serialDevice() );
-
- TQFile::remove( (*prefs).lockDirectory() + "/LCK.." + pathList.last() );
- is_locked = false;
- }
-#endif
+ if (fd != -1 && is_locked)
+ {
+ flock(fd, LOCK_UN);
+ is_locked = false;
+ }
}
@@ -373,7 +307,7 @@ bool Modem::dsrOn()
int flags;
- if ( !fd ) {
+ if ( fd == -1 ) {
#ifdef MODEM_DEBUG
fprintf( stderr, "Modem: dsrOn(): File not open.\n" );
#endif
@@ -396,7 +330,7 @@ bool Modem::ctsOn()
int flags;
- if ( !fd ) {
+ if ( fd == -1 ) {
#ifdef MODEM_DEBUG
fprintf( stderr, "Modem: ctsOn(): File not open.\n" );
#endif
@@ -640,7 +574,7 @@ void Modem::init()
{
is_locked = false;
- fd = 0;
+ fd = -1;
sn = 0;
cspeed = B38400;
@@ -687,7 +621,7 @@ ushort Modem::calcCRC()
int i, j;
ushort c = 0;
-
+
for ( i = 0; i < xsize; i++ ) {
c ^= (ushort) buffer[ i ] << 8;
for ( j = 0; j < 8; j++ )