Page 1 of 1

FreeEMS User And Dev App Serial Device Locking Compatibility

Posted: Mon Jan 10, 2011 4:23 am
by Fred
I know very little about this, BUT, mtx_man is a guru, so he can lead the circus on this... :-)

The goal of this thread is to make sure that all of our core tools lock compatibly on as many OSes as possible. At least linux.

Apps that should lock compatibily :
  • MegaTunix
  • ECUManager
  • FreeEMS-Tuner
  • CuteCom
  • EssEss' thrasher/tester
  • SeanK's loader
  • hcs12mem (probably not as it needs to be replaced)
  • minicom
  • others?
Dave, fill us in on the details of what is required, not advised, advised, copy paste from #freeems-dev IRC if you like, good conversation going on there.

If we have to try to upstream some things, fine.

Fred.

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Posted: Mon Jan 10, 2011 4:50 am
by EssEss

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Posted: Mon Jan 10, 2011 5:36 am
by nitrousnrg
I'm not quite sure about the meaning of the thread title... but ECUmanager serial comms relies on qextserialport, which claims to support win/linux/mac/FreeBSD OS. I've only tested the comms under linux, but I'm pretty sure it will work on other OS.

I hope that is what the thread pointed to... if not, just delete this.

EDIT [just found the discussion on irc, feel free to delete]

ECUmanager doesn't lock anything so far, but I'm interested in this topic :-)

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Posted: Mon Jan 10, 2011 5:07 pm
by dandruczyk
From what I can gather looking at kernel docs (install kernel-doc pkg, read /usr/share/doc/linux-doc/filesystems/ locks.txt and mandatory-locking.txt.gz), it appears that locking in general in linux is basically a mess, and its because every other unix seems to have done it differently over the years. I couldn't find any information whether the serial layer in linux blocks multiple access, but a simple check of running megatunix and cutecom seems to indicate there's nothing to stop two processes from opening the same device and trouncing all over each other.

I even tried adding calls to flock() as well as fcntl() in mtx and it still lets the other process take the stream, so I'd say the only solution is either no locking at all (which seems to be the case of most apps), or advisory locking using /var/lock/..., though that requires each app have the implementation done correctly, neither of which are completely ideal. MegaTunix DOES do the /var/lock/.. advistory locking correctly however. if you start one instance and let it find an ecu, and then start another mtx instance, it won't trounce the first, and the comms tab will show on the second instance, another app has /dev/ttyUSB0 open and not try and override it . MegaTunix is checking the contents of the lockfile (which should contain the PID of the process that created it), and seeing if that process is still running, thus its able to recover from a crashed instance that left a stale lockfile..

So, as it stands, to advisory lock, or not, that is the question?. Beware this isn't portable to windows, but windows may prevent multiple apps talking to the same device anyways so it may be moot, I haven't investigated this thoroughly.

To see the ugly code that does this, look at locking.c in the megatunix source or https://github.com/djandruczyk/MegaTuni ... /locking.c The functions of interest are "lock_serial()" and unlock_serial()", Most of the others are disabled and will eventually be removed.

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Posted: Mon Jan 10, 2011 7:04 pm
by Fred
What is the deal on the mac?

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Posted: Tue Jan 11, 2011 11:28 pm
by EssEss