Skip to content

Commit 667df45

Browse files
committed
qubes: qpass.ClipOpenURL uses xclip or xsel
Some troubleshooting why the old version never exited. Xclip is tricky as it leaves a child process running
1 parent e910845 commit 667df45

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

qubes/qpass.ClipOpenURL

+39-11
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,69 @@
66
# On dom0, create /etc/qubes-rpc/policy/qpass.ClipOpenURL. I recommend:
77
# `sudo cp /etc/qubes-rpc/policy/qubes.ClipboardPaste /etc/qubes-rpc/policy/qpass.ClipOpenURL`
88

9+
# Choose between xsel and xclip, by commenting one definition of
10+
# $clipper and $clearer
11+
clipper="echo install xclip or xsel to support clipboard feature"
12+
sleeper=""
13+
clearer="exit 1"
14+
15+
command -v xclip >/dev/null 2>&1 && {
16+
# xclip will allow 1 single paste (-loops 1).
17+
# xclip spawned process will not terminate until pasted!
18+
# clearer prevents the first xclip from exiting! TODO fix that
19+
clipper="xclip -selection clipboard -loops 1"
20+
sleeper=""
21+
#clearer="xclip -selection clipboard"
22+
clearer=""
23+
}
24+
25+
command -v xsel >/dev/null 2>&1 && {
26+
# xsel, after some time passes, the clearer erases the clipboard
27+
clipper="xsel --input --clipboard"
28+
sleeper="sleep 20"
29+
clearer="xsel --clipboard -c"
30+
}
931

1032
# first line of stdin will be sent to clipboard
1133
read -s clip
1234

1335
# anything else on stdin we open
1436

15-
while read -r url
16-
do
37+
read -r url
38+
1739
case "$url" in
1840
http://*|\
1941
https://*|\
2042
ftp://*)
21-
exec qubes-open "$url" &
43+
qubes-open "$url" &
2244
;;
2345
*)
2446
echo "Invalid URL" >&2
2547
exit 1
2648
;;
2749
esac
28-
done
2950

30-
# write to clipboard, via `xclip`
31-
# we use xclip here, because xsel fails to write to clipboard ("Conversion refused")
32-
command -v xclip >/dev/null 2>&1 || { echo >&2 "xclip not found"; exit 1; }
51+
52+
#echo "populating clipboard..."
53+
3354
(cat <<EOF
3455
$clip
3556
EOF
36-
) | xclip -selection clipboard
57+
) | ($clipper &)
58+
59+
#echo "clipper: $?"
3760

61+
#echo "sleeping..."
3862
# after some time passes, clear the clipboard
39-
sleep 20
63+
$sleeper
4064

4165
# (TODO: clear only if clipboard contents have not changed)
4266

43-
# clear password from clipboard
44-
echo "" | xclip -selection clipboard
67+
echo "" | ($clearer)
68+
status=$?
69+
70+
#echo "clearer: $?"
4571

72+
#echo "exiting."
73+
exit $status
4674

qvm.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bufio"
66
"fmt"
77
"io"
8-
"log"
98
"os/exec"
109
"strings"
1110
)
@@ -74,19 +73,32 @@ func (this appvmCommand) open(group, passwd, url string) error {
7473
//args = append(args, url)
7574

7675
cmd := exec.Command(command, args...)
77-
stdin, err := cmd.StdinPipe()
76+
77+
// qpass.ClipOpenURL expects a password on the first line (will by
78+
// copied to clipboard), followed by URLs to open (one, in our case)
79+
// TODO: ensure passwd has no newlines
80+
cmdIn, err := cmd.StdinPipe()
7881
if err != nil {
7982
return err
8083
}
8184
err = cmd.Start()
8285
if err != nil {
8386
return err
8487
}
85-
log.Println("HERE", passwd)
86-
io.WriteString(stdin, passwd)
87-
io.WriteString(stdin, "\n")
88-
io.WriteString(stdin, url)
89-
io.WriteString(stdin, "\n")
90-
stdin.Close()
88+
89+
io.WriteString(cmdIn, fmt.Sprintf("%s\n%s\n", passwd, url))
90+
cmdIn.Close() // explicit close, in case qpass.ClipOpenURL requires it (one version did).
91+
92+
// comments here as I am figuring the best way to log output of qrexec call.
93+
//out, err := cmd.CombinedOutput()
94+
//log.Printf("output from %s:\n%s\n", command, out)
95+
96+
//log.Println("WAITING", command)
97+
err = cmd.Wait()
98+
//log.Println("DONE", command, err)
99+
if err != nil {
100+
return err
101+
}
102+
91103
return err
92104
}

0 commit comments

Comments
 (0)