You are not logged in.

#1 2016-09-27 17:52:33

amodr
Member
Registered: 2013-08-25
Posts: 10

[SOLVED] 4000 character maximum when copyng to clipboard from xsel

I use the "xsel" program to copy text in emacs and tmux to the clipboard to paste into the browser. It appears that there is a limit for the number of characters that "xsel" will accept through STDIN:

$ yes | head -2000 | xsel --clipboard --input && xsel --clipboard --output | wc
   2000    2000    4000
$ yes | head -2001 | xsel --clipboard --input && xsel --clipboard --output | wc
      0       0       0

Perhaps my memory is foggy, but I thought this used to work before on input sizes larger than 4000. I searched the Arch forums for "clipboard" and "xsel" and didn't see any recent threads and it doesn't look like there have been any upstream "xsel" releases in forever: http://www.vergenet.net/~conrad/software/xsel/download/ or for awhile in Arch: https://www.archlinux.org/packages/?q=xsel

I verified that this does not work with xsel 1.2.0-6 in bash 4.3.046-1 and rxvt-unicode 9.22-2, all x86_64. Anybody have any more context? Is this a known problem? Thanks.

Last edited by amodr (2016-09-28 15:07:08)

Offline

#2 2016-09-27 20:35:56

seth
Member
Registered: 2012-09-03
Posts: 49,951

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Not xsel, bash. No problems in zsh, but in bash I can reproduce the behavior.
Could be some ulimit quota, but I don't see, at hand, which.

Offline

#3 2016-09-27 20:37:45

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Seth: If you were wondering where you post went, I think you hit the report link, not the reply link.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2016-09-27 20:41:45

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Thanks Seth. I can actually reproduce in zsh 5.2-1 x86_64 as well.

I'm currently looking at the source https://github.com/kfish/xsel (Didn't realize it was under active development) and intend to try reverting the xsel package against older Arch versions to see if that fixes it.

Offline

#5 2016-09-27 20:48:11

seth
Member
Registered: 2012-09-03
Posts: 49,951

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

@ewaller, I noticed. Sorry for the noise.

@amodr, zsh 5.2-1, bash 4.3.046-1, xsel 1.2.0-6.

Bash limits:
-----------------
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16097
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 99
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16097
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Zsh limits:
-----------------
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         unlimited
-m: resident set size (kbytes)      unlimited
-u: processes                       16097
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  unlimited
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 16097
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 99
-N 15:                              unlimited

Interestingly, I cannot "ulimit -p" on bash, not even "ulimit -p 8" - always complains about a bad parameter.

Offline

#6 2016-09-27 21:00:44

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Sorry, I was right before. Nothing has changed in the xsel Arch package in a long time.

Offline

#7 2016-09-27 21:01:50

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Seth: What What should I be looking at here? Pipe size?

Offline

#8 2016-09-27 21:05:57

seth
Member
Registered: 2012-09-03
Posts: 49,951

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Wait, bad testing on my side:
ONLY the range 2000 - 4000 fails (on bash and zsh),

yes | head -5000 | xsel --clipboard --input && xsel --clipboard --output | wc

works fine everywhere (as does with 4001)

Offline

#9 2016-09-27 21:06:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

This has nothing to do with pipes.  This is either xsel, or a xserver limit:

$ yes | head -2000 | xsel
$ xsel | wc
   2000    2000    4000
$ yes | head -2001 | xsel
$ xsel | wc
      0       0       0
$ yes | head -2001 | cat > file
$ wc file
2001 2001 4002 file

And in either case it is definitely not a limit on the number of characters, but the number of lines.

EDIT: scratch that, it is neither of the above.  I just copied ~3000 lines from a web browser and was not only able to paste them, xsel could manage them:

$ xsel | wc
   2999    3000   13889

What I suspect it is is when xsel is the selection owner it only allocates a specific buffer size.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2016-09-27 21:14:23

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

How strange! 4001-8000 don't work, but above seems fine.

yes | head -2000

is probably not the best measure because it has newlines. We should probably be using

head -c 2000

:

$ yes | head -c 4000 | xsel --clipboard --input && xsel --clipboard --output | wc
   2000    2000    4000
$ yes | head -c 4001 | xsel --clipboard --input && xsel --clipboard --output | wc 
      0       0       0
$ yes | head -c 8000 | xsel --clipboard --input && xsel --clipboard --output | wc
      0       0       0
$ yes | head -c 8001 | xsel --clipboard --input && xsel --clipboard --output | wc
   4004    4004    8009

Last edited by amodr (2016-09-27 21:14:58)

Offline

#11 2016-09-27 21:18:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

This is looking like a bug in xsel in allocating specific sizes of buffers for the selection.  When it is not the selection owner there should be no such problem.

Id suggest further testing separate whether xsel is the selection owner or not.  Feeding something to xsel then immediately getting it out conflates the size it can handle with the size it can allocate.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2016-09-28 02:36:07

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Thank you Trilby; I did not have context on the "selection owner". So, just to confirm, it always fails during the input phase. I don't have much familiarity with the X environment/API. This is what https://en.wikipedia.org/wiki/X_Window_selection says:

The owner of the selection is typically the window in which the selected text is located, if any.

I did some digging in the xsel source:

https://github.com/kfish/xsel/blob/master/xsel.c#L2061 main sets a flag based on the --input arg
https://github.com/kfish/xsel/blob/master/xsel.c#L2279 main calls set_selection__daemon
https://github.com/kfish/xsel/blob/master/xsel.c#L1775 set_selection__dameon calls set_selection
https://github.com/kfish/xsel/blob/master/xsel.c#L1719 set_selection calls own_selection
https://github.com/kfish/xsel/blob/master/xsel.c#L1022 own_selection calls XGetSelectionOwner. If xsel is asked to select something but is not the owner, then there's an error

This suggests to me that the xsel process should always be the owner when we hit this codepath using the "--input" param. So like Trilby said, there may be some buffer allocation issue. The maximum request size to the X server may be set to 4000 (https://github.com/kfish/xsel/blob/master/xsel.c#L2156) which suggests to me that maybe there's a bug when the number of requests == 2 (4001-8000 bytes doesn't work). Still investigating.

Offline

#13 2016-09-28 14:47:29

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

Don't know why I didn't check for this in the github issues before: https://github.com/kfish/xsel/issues/14 (data corruption after 4000 bytes). I just downloaded the github source and compiled it and ran it. It works fine. So maybe all we need is a new release?

EDIT: Works on master with SHA aa7f57eed805adb09e9c59c8ea841870e8206b81

Last edited by amodr (2016-09-28 14:48:11)

Offline

#14 2016-09-28 15:05:21

amodr
Member
Registered: 2013-08-25
Posts: 10

Re: [SOLVED] 4000 character maximum when copyng to clipboard from xsel

I'm going to flag this as out-of-date in the Arch packages, but I'm not sure that's correct because we're technically on the most recent stable release.

In the meantime, a workaround is to use the AUR package "xsel-git" (https://aur.archlinux.org/packages/xsel-git). If you do, you need to symlink/copy the markdown "README.md" to "README" file:

...

build() {
        cd "$srcdir/${pkgname%-git}"
        ln -s README.md README
        ./autogen.sh
        ./configure --prefix=/usr
        make
}

...

Otherwise, "autoconf" will fail. I might file a bug on github/AUR about this as well.

Offline

Board footer

Powered by FluxBB