Skip to content

Conversation

@michael-o
Copy link
Member

lock(3) mandates that the passed file descriptor must be in O_RDWR or O_WRONLY mode. This was caused by f361cf1.

Downstream bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291822

@michael-o michael-o requested a review from markt-asf December 24, 2025 12:13
@michael-o
Copy link
Member Author

@alexdupre

@markt-asf
Copy link
Contributor

Is this a regression or did adding the logging expose a bug that had existed in the lock code for a quite a while (looks like the last lock related change was 8 years ago)? Based on the proposed fix, it looks like there was a bug in the lock code that was exposed by adding the logging.

@michael-o
Copy link
Member Author

Is this a regression or did adding the logging expose a bug that had existed in the lock code for a quite a while (looks like the last lock related change was 8 years ago)? Based on the proposed fix, it looks like there was a bug in the lock code that was exposed by adding the logging.

Both, but the rather the latter. The logging code triggered this bug which has always been there. So your understand of the issue is correct.

@alexdupre
Copy link

The change didn't simply add logging, but also some new return, so the actual behavior changed. All issues were already there, but hidden.

@michael-o
Copy link
Member Author

@markt-asf Any objections to merge this?

char buff[80];

fd = open(args->pidf, O_RDONLY, 0);
fd = open(args->pidf, O_RDWR, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Since this flag is used more than once, should it be extracted into a constant to ensure we show the intent of using the same value?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean the zero? Or O_RDWR?

Copy link
Member

Choose a reason for hiding this comment

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

I was talking about the flags parameter but I suppose the same could be said of the mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a benefit adding a define for a define.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, but I think the reason for allowing WRite should be documented in the code.

Possibly consider a private function to obtain the fd; this can then be fully documented.

lockf(3) mandates that the passed file descriptor must be in O_RDWR or
O_WRONLY mode. This was caused by f361cf1.

Downstream bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291822
@markt-asf
Copy link
Contributor

Looking at this now.

There look to be fixes for multiple issues wrapped up into a single commit. I'll likely break each one out into a separate commit so the commit message for each change can explain why the change is being made.

I might have follow up questions for some of the changes if it isn't obvious to me why the change has been made.

@michael-o
Copy link
Member Author

Looking at this now.

There look to be fixes for multiple issues wrapped up into a single commit. I'll likely break each one out into a separate commit so the commit message for each change can explain why the change is being made.

I might have follow up questions for some of the changes if it isn't obvious to me why the change has been made.

Totally fine

@markt-asf
Copy link
Contributor

Fixed in a series of commits heavily based on this PR.

@markt-asf markt-asf closed this Jan 7, 2026
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.

5 participants