Bug 17296 – EINTR awareness - posix system calls can be interrupted by posix signal

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2017-04-03T23:04:23Z
Last change time
2024-12-01T16:30:02Z
Assigned to
No Owner
Creator
Roman
Moved to GitHub: phobos#9714 →

Comments

Comment #0 by freeslave93 — 2017-04-03T23:04:23Z
Phobos does not look to be EINTR-aware. Many posix functions used in phobos can be potentially interrupted by delivering a signal. Examples are posix write and read used in std.file.write and std.file.read. It's easy to make EINTR-aware wrappers for such interruptible functions. import core.stdc.errno; import std.traits; template deintr(alias func, Args...) if (isFunction!func && isIntegral!(ReturnType!func)) { ReturnType!func deintr(Parameters!func args) { ReturnType!func result; do { result = func(args); } while(result == -1 && .errno == EINTR); return result; } } then use it like this: import core.sys.posix.unistd; alias dwrite = deintr!(.write); dwrite(fd, buf.ptr, buf.length); The question is if it's really needed. What is the current phobos policy on signals?
Comment #1 by freeslave93 — 2017-04-05T19:20:46Z
It turned out that the problem can appear even if user does not do signal handling himself. It's enough to just do multithreading, so signals used by GC can interrupt syscall in other thread. Whether the hack is applied or not, the behavior of functions will need to be documented. If hack is applied, it should say about possible looping, if it's not applied it should say that interruption is considered error for these functions. There's also updated version of the hack: template deintr(alias func) if (isFunction!func && isIntegral!(ReturnType!func) && isSigned!(ReturnType!func) && functionLinkage!func == "C") { ReturnType!func deintr(Args...)(Parameters!func args, Args varArgs) { ReturnType!func result; do { result = func(args, varArgs); } while(result == -1 && .errno == EINTR); return result; } }
Comment #2 by greensunny12 — 2017-06-26T18:52:46Z
Comment #3 by robert.schadek — 2024-12-01T16:30:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9714 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB