aseba-community / aseba

Aseba is a set of tools which allow beginners to program robots easily and efficiently. To contact us, please open an issue.
http://aseba.wikidot.com
GNU Lesser General Public License v3.0
49 stars 61 forks source link

Thymio Flasher needs to close other Aseba programs before loading #188

Closed sharon13m closed 11 years ago

sharon13m commented 11 years ago

If Aseba Studio is open while you open Thymio Flasher.. it severely (and maybe permanently) damages the robot. Thymio Flasher needs to run a check to see if Aseba Studio (and possibly other programs) are open and communicating with the robot, and then shut them down or tell that user that it cannot proceed if the other software is open.

stephanemagnenat commented 11 years ago

I am somewhat puzzled that this happens, as this problem implies that the serial port device can be opened twice. We have to do further tests to see whether this happens on Windows and OS X as well. This problems should be solved in Dashel, by not allowing serial ports to be opened twice.

retornaz commented 11 years ago

fcntl(fd, F_SETLK,...)

stephanemagnenat commented 11 years ago

Interesting, but this function provides "advisory" locks, they are not enforced. A quick search on the net seems to indicate that the only way is through lock files, but then we have to handle dandling lock files in case of crash. We could implement some semi-intelligent check on the lock file to verify that the locking program still runs, but although doable, that's non trivial.

retornaz commented 11 years ago

hem at least if implemented through dashel, it would avoid the asebastudio/thymioflasher mixup. Or we could put back thymioflasher into an asebastudio plugin ......

stephanemagnenat commented 11 years ago

I'm for implementing something in Dashel, for serial ports. First we need to see on which platform this problem happens. Is it only posix? Only OS X?

retornaz commented 11 years ago

Posix

stephanemagnenat commented 11 years ago

Ok, so we go for lock files. This raises some questions:

I think that flock(2) can work. It exists both on Linux and OS X, and by using the LOCK_NB flag directly after opening the file descriptor, we can check whether there is already a lock, and if, so, return an error in Dashel. One question is then what happens if a Dashel-enabled application crashes and does not release the lock?

retornaz commented 11 years ago

You are mixing two completely unrelated "locking" mechanism.

I think the first one is sufficient as we just want to avoid asebastudio/thymioflasher mixing.

stephanemagnenat commented 11 years ago

I was indeed mixing the two, but note that the first one is linked to a file through its descriptor, so I was afraid it would not be released upon crash.

retornaz commented 11 years ago

huh, why not ?

retornaz commented 11 years ago

manpage of fcntl (we should avoid using flock): "As well as being removed by an explicit F_UNLCK, record locks are automatically released when the process terminates or if it closes any file descriptor referring to a file on which locks are held."

stephanemagnenat commented 11 years ago

why not using flock, the call is simpler and does not include arguments about position which are meaningless for a serial stream?

retornaz commented 11 years ago

ok, go for flock()

stephanemagnenat commented 11 years ago

Fixed in aseba-community/dashel@d13bbbd1df4802101e13e93fb6229d1f7f164e85, we have to see how we propagate this to Aseba.