-
Notifications
You must be signed in to change notification settings - Fork 23
Delete lock file if contained pid is stale #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3982c7f to
cd4c31c
Compare
Previously, a different process could create the lock between both calls to open(2) with the result that two processes access the same serial port. Fix this by only opening the lock file with O_CREAT | O_EXCL. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
This is the format specified by the FHS[1]. While at it remove the now outdated comment about kermit compatibility. It no longer applies to ckermit, which now follows the HDB UUCP format as well[2]. [1]: http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLOCKLOCKFILES [2]: pengutronix#9 (comment) Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
If microcom crashes, e.g. due to the buffer underflow described in pengutronix#10, it may leave a stale lock file behind. Teach microcom detection of these stale lock files. Note that this is racy, two processes may detect a stale lock file and one might unlink the other's lock. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
|
I've changed microcom to use the HDB UUCP format for its lock files. Deleting stale lock files though is racy and I think it can't be fixed without file locks, but as it was racy before anyway, it might still be good enough for inclusion :-) |
While at it remove the now outdated comment about kermit compatibility. It no longer applies to ckermit [1]. [1]: pengutronix#9 (comment) Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
While at it remove the now outdated comment about kermit compatibility. It no longer applies to ckermit [1]. [1]: pengutronix#9 (comment) Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
|
Any comments on this? |
| if (opt_force) { | ||
| printf("lockfile for port exists, ignoring\n"); | ||
| serial_unlock(); | ||
| goto relock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if serial_unlock() fails to delete the lockfile, this is an endless loop.
ukleinek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| do { | ||
| ret = read(fd, &pidbuf[nbytes], sizeof(pidbuf) - nbytes - 1); | ||
| nbytes += ret; | ||
| } while (ret > 0 && nbytes < sizeof (pidbuf) - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense here to do some additional checks on the format? E.g. check you read the file completely? If the lockfile happens to be created by an older microcom with pid 33333333 you check for pid 3333 instead. (I think, didn't test.)
| if (ret == 1 && kill(pid, 0) < 0 && errno == ESRCH) { | ||
| printf("lockfile contains stale pid, ignoring\n"); | ||
| serial_unlock(); | ||
| goto relock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue as with the first patch in this series (i.e. endless loop if serial_unlock fails to remove lockfile)
|
With move to flock, this is no longer applicable. |
Fixes #2.