Skip to content
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

Set FD_CLOEXEC on the LMDB FD manually #287

Merged
merged 1 commit into from Nov 12, 2020
Merged

Conversation

Vogtinator
Copy link
Contributor

Currently the FD referring to the appstreacm-cache-FOO.mdb is leaked into
child processes. The only way to fix is in a race-free way is by passing
O_CLOEXEC when opening it inside LMDB, but that's currently not done.

}
if (db_fd_flags != -1) {
fcntl (db_fd, F_SETFD, db_fd_flags | FD_CLOEXEC);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove the extra brackets? If there's just a single line following an if statement, they should be omitted in AppStream's coding style

src/as-cache.c Outdated
https://www.openldap.org/lists/openldap-bugs/201702/msg00003.html */
rc = mdb_env_get_fd (priv->db_env, &db_fd);
if (rc == MDB_SUCCESS) {
db_fd_flags = fcntl (db_fd, F_GETFD);
Copy link
Owner

Choose a reason for hiding this comment

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

Could you move the db_fd_flags variable into this block, so it only is visible when we actually need it, and also move the if (db_fd_flags != -1) into this block as well, to logically group this together?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looked to me like it was using the old C style to declare all variables at the function start...

Done.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, some older parts of the code do, but for new code we can use fancy "new" things! - Even the cleanup attribute and g_autofree, which is one of the best things that ever happened to a C developer ;-)

@ximion
Copy link
Owner

ximion commented Nov 12, 2020

Oof, I kind of implicitly expected LMDB to do the right thing here and already use O_CLOEXEC - good catch! The race condition isn't great, but I think something we can live with until LMDB gets changed upstream.
Thank you for the patch!

Currently the FD referring to the appstreacm-cache-FOO.mdb is leaked into
child processes. The only way to fix is in a race-free way is by passing
O_CLOEXEC when opening it inside LMDB, but that's currently not done.
@ximion
Copy link
Owner

ximion commented Nov 12, 2020

Looks good to me, thank you for the quick changes :-)

@ximion ximion merged commit ccfbff0 into ximion:master Nov 12, 2020
1 check was pending
@Vogtinator Vogtinator deleted the cloexec branch November 12, 2020 13:44
@Vogtinator
Copy link
Contributor Author

Thanks for the quick merge!

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.

None yet

2 participants