-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-46021: fcntl module update supporting FreeBSD's F_KINFO proposal. #30000
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
Open
devnexen
wants to merge
1
commit into
python:main
Choose a base branch
from
devnexen:fcntl_fbsd_upd2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
#include <stropts.h> | ||
#endif | ||
|
||
#ifdef __FreeBSD__ | ||
#include <sys/user.h> | ||
#endif | ||
|
||
/*[clinic input] | ||
module fcntl | ||
[clinic start generated code]*/ | ||
|
@@ -60,6 +64,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) | |
|
||
if (arg != NULL) { | ||
int parse_result; | ||
#ifdef F_KINFO | ||
if (code == F_KINFO) { | ||
PyErr_SetString(PyExc_ValueError, | ||
"fnctl arg not permitted with F_KINFO"); | ||
return NULL; | ||
} | ||
#endif | ||
|
||
if (PyArg_Parse(arg, "s#", &str, &len)) { | ||
if ((size_t)len > sizeof buf) { | ||
|
@@ -89,6 +100,33 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) | |
} | ||
} | ||
|
||
#ifdef F_KINFO | ||
if (code == F_KINFO) { | ||
struct kinfo_file f = {.kf_structsize = KINFO_FILE_SIZE}; | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, &f); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
if (ret < 0) { | ||
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; | ||
} | ||
|
||
PyObject *ret = PyDict_New(); | ||
if (ret) { | ||
PyDict_SetItemString(ret, "status", PyLong_FromLong(f.kf_status)); | ||
PyDict_SetItemString(ret, "type", PyLong_FromLong(f.kf_type)); | ||
PyDict_SetItemString(ret, "offset", PyLong_FromLongLong(f.kf_offset)); | ||
PyDict_SetItemString(ret, "path", PyBytes_FromString(f.kf_path)); | ||
return ret; | ||
Comment on lines
+116
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
PyErr_SetString(PyExc_ValueError, | ||
"fcntl could not create F_KINFO data"); | ||
return NULL; | ||
} | ||
} | ||
#endif | ||
|
||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, (int)int_arg); | ||
|
@@ -588,6 +626,9 @@ all_ins(PyObject* m) | |
#ifdef F_DUP2FD_CLOEXEC | ||
if (PyModule_AddIntMacro(m, F_DUP2FD_CLOEXEC)) return -1; | ||
#endif | ||
#ifdef F_KINFO | ||
if (PyModule_AddIntMacro(m, F_KINFO)) return -1; | ||
#endif | ||
|
||
/* For F_{GET|SET}FL */ | ||
#ifdef FD_CLOEXEC | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This needs an
AC_CHECK_HEADERS
check in configure.ac