-
Notifications
You must be signed in to change notification settings - Fork 59
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
wl-copy does not close stderr when forking #212
Comments
Seeing as this has been brought up before in #110 and #154 let me elaborate: A reasonably common case for mpv Lua scripts is to copy something to the clipboard. local function copy_to_clipboard(text)
if os.getenv("WAYLAND_DISPLAY") then
local r = mp.command_native({
name = "subprocess",
args = {"wl-copy", text},
playback_only = false,
})
if r.status == 0 then
return true
end
else
-- omitted for brevity
end
msg.error("Error writing clipboard")
end The only problem with this is that is hangs, until something else is selected because at that point wl-copy exits. For me what speaks against keeping stderr open:
Now I understand you don't want to swallow the error so how about logging to syslog instead? |
@bugaevc thoughts? |
Hi,
well, this sounds like something to be fixed in mpv, no?
It does fork, but are you sure mpv doesn't have the same issue with xclip? It certainly doesn't look like xclip closes its stderr (or stdout), neither from skimming their source code, nor in practice:
That would make sense, yes. Do you know if there's a way to do this nicely? It's possible to send messages to the log using explicit |
I re-did my testing and you're right. xclip behaves exactly the same and results in the same issue with mpv.
True. This unfortunately requires some annoying workarounds since you can't
wl-copy's code could be refactored to use a logging mechanism that can be redirected. I believe external libraries printing directly to stderr is considered bad practice so hopefully that's not a thing that actually happens. If you don't want to pursue this request I can understand, however looking at the issues other people have opened relating to this behavior I think it would be worthwhile. |
FWIW, you can combine volatile sig_atomic_t got_sigchld= 0;
static void sigchld_handler(int signum) {
assert(signum == SIGCHLD);
got_sigchld = 1;
}
// Block SIGCHLD, remembering the previous mask.
sigset_t sigmask;
sigprocmask(SIG_SETMASK, NULL, &sigmask);
sigaddset(&sigmask, SIGCHLD);
sigprocmask(SIG_SETMASK, &sigmask, &sigmask);
while (!got_sigchld) {
int rc = ppoll(pollfds, nfds, &timeout, &sigmask);
if (rc == -1 && errno == EINTR) continue;
// handle pollfds...
}
// The child has exited, wait for it (or something).
wait(...); |
https://github.com/bugaevc/wl-clipboard/blob/master/src/wl-copy.c#L65
This trips up applications that try to capture output from child processes (because stderr remains open)
The text was updated successfully, but these errors were encountered: