Skip to content

Conversation

@a3f
Copy link
Member

@a3f a3f commented Sep 14, 2018

Fixes #2.

@a3f a3f force-pushed the delete-stale-lockfile branch from 3982c7f to cd4c31c Compare September 14, 2018 10:01
a3f added 3 commits May 4, 2019 16:14
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>
@a3f a3f force-pushed the delete-stale-lockfile branch from cd4c31c to 91a6aec Compare May 4, 2019 14:17
@a3f
Copy link
Member Author

a3f commented May 4, 2019

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 :-)

@a3f a3f requested a review from ukleinek May 4, 2019 14:28
a3f added a commit to a3f/microcom that referenced this pull request May 4, 2019
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>
a3f added a commit to a3f/microcom that referenced this pull request Aug 25, 2019
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>
@a3f
Copy link
Member Author

a3f commented Aug 25, 2019

Any comments on this?

@a3f a3f mentioned this pull request Aug 25, 2019
if (opt_force) {
printf("lockfile for port exists, ignoring\n");
serial_unlock();
goto relock;
Copy link
Contributor

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.

Copy link
Contributor

@ukleinek ukleinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if you wrote "#10" instead of "#10"
in the commit log to make this actually useful when not looked at via github.

do {
ret = read(fd, &pidbuf[nbytes], sizeof(pidbuf) - nbytes - 1);
nbytes += ret;
} while (ret > 0 && nbytes < sizeof (pidbuf) - 1);
Copy link
Contributor

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;
Copy link
Contributor

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)

@a3f
Copy link
Member Author

a3f commented Feb 23, 2022

With move to flock, this is no longer applicable.

@a3f a3f closed this Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detect stale lock file

2 participants