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

Not closing stdout when setting clipboard from stdin #20

Open
astrand opened this issue Apr 17, 2013 · 7 comments
Open

Not closing stdout when setting clipboard from stdin #20

astrand opened this issue Apr 17, 2013 · 7 comments

Comments

@astrand
Copy link
Owner

astrand commented Apr 17, 2013

xclip does not appear to be closing stdout. This was noticed to cause compatibility problems when used with newer versions of tmux.

The tmux developer was able to identify this as the cause of an issue originally reported against tmux.

More info: https://sourceforge.net/p/tmux/tickets/40/?limit=10&page=1#9a2b

Reported by: wadetc

Original Ticket: xclip/bugs/9

@astrand
Copy link
Owner Author

astrand commented Jan 31, 2014

See this StackOverflow question for an explanation of why xclip does not exit/close stdout until another selection is made:

http://stackoverflow.com/questions/19254114/xclip-does-not-terminate-when-tracing-it

Basically, it seems the only place the text buffer exists for other X clients to copy from is xclip itself, so if it exits the text goes with it. To stay alive, xclip fork's and daemonizes. I'm not sure how xsel handles this.

I guess maybe xclip could close stdout when it knows it has nothing else to write to it?

Original comment by: jaredcasper

@astrand astrand self-assigned this Feb 3, 2016
janlazo added a commit to janlazo/neovim that referenced this issue Dec 26, 2019
janlazo added a commit to janlazo/neovim that referenced this issue Dec 26, 2019
janlazo added a commit to janlazo/neovim that referenced this issue Dec 26, 2019
janlazo added a commit to janlazo/neovim that referenced this issue Dec 28, 2019
test_registers.vim can fail even if a clipboard manager is running.
If a clipboard manager is not running, this test always fails with xclip.
Use xsel as a workaround.
astrand/xclip#20 suggests closing stdout
when sending input via stdin.

Environment
- Ubuntu Xenial
- Vim 7.4 (any app with broken clipboard code will do)
- Neovim nightly

Steps to reproduce:
0. Start the clipboard manager.
1. Open a file in Vim on Linux.
   Vim should have +clipboard enabled.
   'set clipboard='
2. Yank some text to the clipboard register.
3. Quit Vim.
4. Run 'cd /path/to/neovim/repo/'
5. Run 'make oldtest'.
   Do not run any individual tests.
   They likely pass with or without this fix.

Before fix: test_registers.vim can fail.
After fix: test_registers.vim always passes.

Close neovim#7958

https://wiki.ubuntu.com/ClipboardPersistence#The_state_of_things
janlazo added a commit to janlazo/neovim that referenced this issue Dec 31, 2019
test_registers.vim can fail even if a clipboard manager is running.
If a clipboard manager is not running, this test always fails with xclip.
Use xsel as a workaround.
astrand/xclip#20 suggests closing stdout
when sending input via stdin.

Environment
- Ubuntu Xenial
- Vim 7.4 (any app with broken clipboard code will do)
- Neovim nightly

Steps to reproduce:
0. Start the clipboard manager.
1. Open a file in Vim on Linux.
   Vim should have +clipboard enabled.
   'set clipboard='
2. Yank some text to the clipboard register.
3. Quit Vim.
4. Run 'cd /path/to/neovim/repo/'
5. Run 'make oldtest'.
   Do not run any individual tests.
   They likely pass with or without this fix.

Before fix: test_registers.vim can fail.
After fix: test_registers.vim always passes.

Close neovim#7958

https://wiki.ubuntu.com/ClipboardPersistence#The_state_of_things
justinmk pushed a commit to neovim/neovim that referenced this issue Jan 2, 2020
test_registers.vim can fail even if a clipboard manager is running.
If a clipboard manager is not running, this test always fails with xclip.
Use xsel as a workaround.
astrand/xclip#20 suggests closing stdout
when sending input via stdin.

Environment
- Ubuntu Xenial
- Vim 7.4 (any app with broken clipboard code will do)
- Neovim nightly

Steps to reproduce:
0. Start the clipboard manager.
1. Open a file in Vim on Linux.
   Vim should have +clipboard enabled.
   'set clipboard='
2. Yank some text to the clipboard register.
3. Quit Vim.
4. Run 'cd /path/to/neovim/repo/'
5. Run 'make oldtest'.
   Do not run any individual tests.
   They likely pass with or without this fix.

Before fix: test_registers.vim can fail.
After fix: test_registers.vim always passes.

Close #7958

https://wiki.ubuntu.com/ClipboardPersistence#The_state_of_things
@Ian2020
Copy link

Ian2020 commented Jan 20, 2020

I'm not a C developer but xsel's (github.com) function set_selection__daemon around line 1770 seems to suggest it uses a similar daemon approach:

[create] a daemon process to handle selection requests for the specified selection

The daemon can have a timeout set via the selectionTimeout flag but the default is no timeout:

--selectionTimeout ms
specify the timeout in milliseconds within which the selection must be retrieved. A value of 0 (zero)
specifies no timeout (default)

So presumably the daemon remains as long as it's needed, just like xclip.

Using xsel is suggested as a fix for this issue in the Tmux article on ArchWiki so perhaps the real difference between the two is just the closing of stdout as @astrand suggests above?

@murlakatamenka
Copy link

murlakatamenka commented Aug 20, 2020

This issue won't let parent shell process exit, i.e.:

echo foo | xclip
exit # won't exit unless xclip process spawned above exits

As a workaround one can wrap xclip this way (.zshrc):

xclip() {
    /usr/bin/xclip "$@" &> /dev/null
}

&> /dev/null is zsh / bash way of redirecting both stdout and stdin.
> /dev/null 2&>1 for more portable way.

@ljrk0
Copy link

ljrk0 commented Sep 3, 2020

Cross-posting my solution from #34 (comment)_ , simply closing stdout/stderr using the shell works as well:

Closing stdout and stderr when running xclip with >&- 2>&- seems to do the trick.

@murlakatamenka
Copy link

murlakatamenka commented Sep 5, 2020

@leonardkoenig didn't know if such possibility.

Another one I found is to use nohup (https://linux.die.net/man/1/nohup).

@hackerb9
Copy link
Collaborator

hackerb9 commented Nov 5, 2020

I'm having the darnedest time trying to reproduce this bug. I've tried setting my shell to zsh and compiling old versions of xclip. And yet, I'm always able to just type 'exit' to logout. @murlakatamenka, @leonardkoenig, could you please provide a little bit more information about how to trigger this bug? What exactly is hanging? Is it ssh? Or does your shell say something like "you have running jobs"? Which shell are you using? What version of xclip?

@hackerb9
Copy link
Collaborator

hackerb9 commented Nov 5, 2020

I see that "nohup" is given as a solution. Should I presume it only works because it redirects stdout to a file? If not, then perhaps xclip could call setsid() as the child after forking (as suggested in #4). `

fdw added a commit to fdw/rofimoji that referenced this issue Mar 12, 2021
xclip behaves weirdly in that it hangs around after invocation. There
are lots of issues for this, and the common solution is to close stdout
and stderr (astrand/xclip#20).

Now we also close stderr and stdout, and it works again.

Issue: #79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants