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

always use the passed fd in generated saferead() and safewrite() functions #272

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DerDakon
Copy link
Member

Fixes #270.

There were situations where the generated functions would ignore the fd that was passed as their argument because if was always "-1". This happened when the substdio was statically initialized but a socket was dynamically allocated at runtime and was actually used for communication. Update the substdio when the socket is known, and then just use the passed fd.

@DerDakon DerDakon added this to the 1.10 milestone Mar 23, 2024
@@ -5,11 +5,11 @@

extern ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len);

#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,writefd,doexit) \
#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,doexit) \
ssize_t funcname(int fd, const void *buf, size_t len) \
Copy link

Choose a reason for hiding this comment

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

The fd argument was never used there. Maybe an omission or a change of mind mid-way...
This sounds like pursuing some work, makes sense to me.
Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

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

Not entirely. Some callers passed "fd" as the "writefd" macro argument, so they actually used the fd passed to the function. And now just all do.

The "to" and "from" substdios are initialized with fd -1 because the socket is
dynamically allocated at runtime. That is why the passed fd in the saferead()
and safewrite() functions was ignored and the socket descriptor was always used.
Update the fd in the substdios once the socket is allocated and then use the
provided fd.
The "to" and "from" substdios are initialized with fd -1 because the socket is
dynamically allocated at runtime. That is why the passed fd in the saferead()
and safewrite() functions was ignored and the socket descriptor was always used.
Update the fd in the substdios once the socket is allocated and then use the
provided fd.
…ator macros

All instances now use the fd that is passed through the interface, so this can
be removed from the macro.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why do saferead and safewrite sometimes ignore the file descriptor that is passed to them?
3 participants