FreeEMS User And Dev App Serial Device Locking Compatibility

FreeEMS topics that aren't specific to hardware development or firmware development.
Post Reply
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

FreeEMS User And Dev App Serial Device Locking Compatibility

Post 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.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
EssEss
LQFP112 - Up with the play
Posts: 244
Joined: Thu Sep 10, 2009 9:23 am
Location: Dayton, OH

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Post by EssEss »

User avatar
nitrousnrg
LQFP144 - On Top Of The Game
Posts: 468
Joined: Tue Jun 24, 2008 5:31 pm

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Post 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 :-)
Marcos
dandruczyk
LQFP112 - Up with the play
Posts: 100
Joined: Sun Apr 06, 2008 6:30 pm

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Post 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.
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Post by Fred »

What is the deal on the mac?
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
EssEss
LQFP112 - Up with the play
Posts: 244
Joined: Thu Sep 10, 2009 9:23 am
Location: Dayton, OH

Re: FreeEMS User And Dev App Serial Device Locking Compatibi

Post by EssEss »

Post Reply