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

Clear global clipboard after specified seconds #158

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alimirjamali
Copy link
Contributor

@alimirjamali
Copy link
Contributor Author

alimirjamali commented Nov 12, 2024

Last second thoughts: If we store g->clipboard_timeout in metadata.sent_size, the clipboard systray widget could show a better pop-up message. Something like:

Global clipboard belonging to {vmname} automatically cleared after {sent_size} seconds

gui-daemon/xside.c Outdated Show resolved Hide resolved
gui-daemon/xside.c Outdated Show resolved Hide resolved
gui-daemon/xside.c Outdated Show resolved Hide resolved
gui-daemon/xside.c Outdated Show resolved Hide resolved
@marmarek
Copy link
Member

ast second thoughts: If we store g->clipboard_timeout in metadata.sent_size, the clipboard systray widget could show a better pop-up message. Something like:

Interesting idea. The copy notification could also say something like "... and will be cleared in XX seconds".

@alimirjamali
Copy link
Contributor Author

Interesting idea. The copy notification could also say something like "... and will be cleared in XX seconds".

In this case, I think it is better to have dedicated key for it in the JSON (like) metadata. Easy to implement. I will do it.

@alimirjamali alimirjamali force-pushed the issue-6641-clipboard_timeout branch 3 times, most recently from 0b77a64 to f215e31 Compare November 14, 2024 19:58
@alimirjamali
Copy link
Contributor Author

Further notes:
We have to consider the qrexec clipboard case. And what to do for Microsoft Windows. I did not bother for the time while the QWT support is not officially restored. I will work on it afterwards. As there are many corner cases to cover.

@qubesos-bot
Copy link

OpenQA test summary

Complete test suite and dependencies: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.3&build=2024111418-4.3&flavor=pull-requests

Test run included the following:

New failures, excluding unstable

Compared to: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.3&build=2024091704-4.3&flavor=update

  • system_tests_extra

    • TC_00_QVCTest_whonix-workstation-17: test_010_screenshare (failure)
      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^... AssertionError: 0 == 0
  • system_tests_kde_gui_interactive

    • gui_keyboard_layout: Failed (test died)
      # Test died: command 'test "$(cd ~user;ls e1*)" = "$(qvm-run -p wor...

Failed tests

5 failures
  • system_tests_extra

    • TC_00_QVCTest_whonix-workstation-17: test_010_screenshare (failure)
      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^... AssertionError: 0 == 0
  • system_tests_network_updates

  • system_tests_kde_gui_interactive

    • gui_keyboard_layout: Failed (test died)
      # Test died: command 'test "$(cd ~user;ls e1*)" = "$(qvm-run -p wor...
  • system_tests_basic_vm_qrexec_gui_zfs

    • switch_pool: Failed (test died)
      # Test died: command 'dnf install -y ./zfs-release.rpm' failed at /...
  • system_tests_audio@hw1

Fixed failures

Compared to: https://openqa.qubes-os.org/tests/112766#dependencies

201 fixed

Unstable tests

  • system_tests_suspend

    suspend/ (1/5 times with errors)
    suspend/Failed (1/5 times with errors)
    • job 115081 # Test died: no candidate needle with tag(s) 'xscreensaver-prompt' ...
    suspend/wait_serial (1/5 times with errors)
    • job 115081 # wait_serial expected: qr/2E8vz-\d+-/...
  • system_tests_basic_vm_qrexec_gui

    TC_20_NonAudio_whonix-workstation-17/test_140_qrexec_filecopy_unsafe_name (1/5 times with errors)
    • job 115635 libvirt.libvirtError: internal error: libxenlight failed to create ...
  • system_tests_pvgrub_salt_storage

    TC_41_HVMGrub_debian-12-xfce/test_000_standalone_vm (1/5 times with errors)
    • job 115648 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-40-xfce/test_000_standalone_vm (2/5 times with errors)
    • job 114628 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115648 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_debian-12-xfce/test_010_template_based_vm (1/5 times with errors)
    • job 115648 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-40-xfce/test_010_template_based_vm (3/5 times with errors)
    • job 114628 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115078 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115648 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
  • system_tests_extra

    TC_00_QVCTest_whonix-workstation-17/test_020_webcam (1/5 times with errors)
    • job 115072 AssertionError: 'qubes-video-companion webcam' exited early (0): b'...
  • system_tests_usbproxy

    TC_20_USBProxy_core3_fedora-40-xfce/test_070_attach_not_installed_front (1/5 times with errors)
    • job 117582 NameError: name 'santizied_stderr' is not defined
  • system_tests_qrexec

    TC_00_Qrexec_fedora-40-xfce/test_065_qrexec_exit_code_vm (1/5 times with errors)
    • job 115649 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_00_Qrexec_fedora-40-xfce/test_080_qrexec_service_argument_allow_default (1/5 times with errors)
    • job 115649 libvirt.libvirtError: internal error: libxenlight failed to create ...
  • system_tests_network_ipv6

    VmIPv6Networking_fedora-40-xfce/test_520_ipv6_simple_proxyvm_nm (1/5 times with errors)
    • job 115076 AssertionError: 1 != 0 : nm-applet window not found
  • system_tests_network_updates

    VmUpdates_fedora-40-xfce/test_000_simple_update (1/5 times with errors)
    • job 116867 AssertionError: 1 not found in [0, 100] : dnf clean all; dnf check-...
    TC_10_QvmTemplate_whonix-gateway-17/test_000_template_list (1/5 times with errors)
    • job 115077 qvm-template: error: No matching templates to list
    VmUpdates_debian-12-xfce/test_020_updates_available_notification (1/5 times with errors)
    • job 117610 subprocess.CalledProcessError: Command '/usr/lib/qubes/upgrades-sta...
    VmUpdates_debian-12-xfce/test_120_updates_available_notification_qubes_vm_update (1/5 times with errors)
    • job 115077 subprocess.CalledProcessError: Command '/usr/lib/qubes/upgrades-sta...
    VmUpdates_debian-12-xfce/test_121_updates_available_notification_qubes_vm_update_cli (1/5 times with errors)
    • job 116867 subprocess.CalledProcessError: Command '/usr/lib/qubes/upgrades-sta...
  • system_tests_audio

    TC_20_AudioVM_Pulse_fedora-40-xfce/test_223_audio_play_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 115053 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_228_audio_rec_unmuted_pipewire (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.41970521541950...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_250_audio_playback_audiovm_pipewire (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.06471655328798...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_251_audio_playback_audiovm_pipewire_late_start (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.2878231292517,...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_251_audio_playback_audiovm_pipewire_late_start (1/5 times with errors)
    • job 115623 AssertionError: too short audio, expected 10s, got 9.34507936507936...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_252_audio_playback_audiovm_switch_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_fedora-40-xfce/test_252_audio_playback_audiovm_switch_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_252_audio_playback_audiovm_switch_hvm (2/5 times with errors)
    • job 115053 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_260_audio_mic_enabled_switch_audiovm (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    TC_20_AudioVM_PipeWire_fedora-40-xfce/test_260_audio_mic_enabled_switch_audiovm (2/5 times with errors)
    • job 116847 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    • job 117586 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_260_audio_mic_enabled_switch_audiovm (1/5 times with errors)
    • job 115623 AssertionError: too short audio, expected 10s, got 9.05353741496598...
  • system_tests_audio@hw1

    TC_20_AudioVM_Pulse_fedora-40-xfce/test_223_audio_play_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_224_audio_rec_muted_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 115053 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_228_audio_rec_unmuted_pipewire (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.41970521541950...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_250_audio_playback_audiovm_pipewire (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.06471655328798...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_251_audio_playback_audiovm_pipewire_late_start (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 9.2878231292517,...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_251_audio_playback_audiovm_pipewire_late_start (1/5 times with errors)
    • job 115623 AssertionError: too short audio, expected 10s, got 9.34507936507936...
    TC_20_AudioVM_Pulse_debian-12-xfce/test_252_audio_playback_audiovm_switch_hvm (1/5 times with errors)
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_fedora-40-xfce/test_252_audio_playback_audiovm_switch_hvm (2/5 times with errors)
    • job 115053 libvirt.libvirtError: internal error: libxenlight failed to create ...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_252_audio_playback_audiovm_switch_hvm (2/5 times with errors)
    • job 115053 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 115623 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_260_audio_mic_enabled_switch_audiovm (1/5 times with errors)
    • job 115053 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    TC_20_AudioVM_PipeWire_fedora-40-xfce/test_260_audio_mic_enabled_switch_audiovm (2/5 times with errors)
    • job 116847 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    • job 117586 AssertionError: too short audio, expected 10s, got 0.00013605442176...
    TC_20_AudioVM_PipeWire_whonix-workstation-17/test_260_audio_mic_enabled_switch_audiovm (1/5 times with errors)
    • job 115623 AssertionError: too short audio, expected 10s, got 9.05353741496598...
  • system_tests_basic_vm_qrexec_gui_btrfs

    TC_30_Gui_daemon/test_002_clipboard_300k (1/5 times with errors)
    • job 116856 : Clipboard copy operation failed - content...
  • system_tests_basic_vm_qrexec_gui_ext4

    TC_20_NonAudio_debian-12-xfce-pool/test_105_qrexec_filemove (1/5 times with errors)
    • job 115067 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_NonAudio_whonix-gateway-17-pool/test_105_qrexec_filemove (1/5 times with errors)
    • job 115067 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_NonAudio_whonix-workstation-17-pool/test_130_qrexec_filemove_disk_full (1/5 times with errors)
    • job 115067 libvirt.libvirtError: internal error: libxenlight failed to create ...
    TC_20_NonAudio_debian-12-xfce-pool/test_141_qrexec_filecopy_unsafe_symlink (1/5 times with errors)
    • job 115067 libvirt.libvirtError: internal error: libxenlight failed to create ...
  • system_tests_basic_vm_qrexec_gui@hw1

    TC_20_NonAudio_whonix-workstation-17/test_140_qrexec_filecopy_unsafe_name (1/5 times with errors)
    • job 115635 libvirt.libvirtError: internal error: libxenlight failed to create ...
  • system_tests_suspend@hw1

    suspend/ (1/5 times with errors)
    suspend/Failed (1/5 times with errors)
    • job 115081 # Test died: no candidate needle with tag(s) 'xscreensaver-prompt' ...
    suspend/wait_serial (1/5 times with errors)
    • job 115081 # wait_serial expected: qr/2E8vz-\d+-/...

gui-daemon/xside.c Outdated Show resolved Hide resolved
gui-daemon/xside.c Outdated Show resolved Hide resolved
perror("Can not get clipboard data file status");
exit(1);
}
switch (g->clipboard_timeout_pid = fork()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if you clear the pid variable on SIGCHLD, depending on the execution order, it may override the new PID instead of the old one, so be careful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am losing this and I need to study a lot. The way I did it at the beginning was to assure that the clearing child process(es) assure that the clipboard content belongs to their original intended clearing event. Otherwise simply exit. The disadvantage would have been possibility for multiple useless waiting child processes.

Trying to keep track of a clearing child process and terminating it (and nothing else) is something I have difficulty with doing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a subprocess, I recommend using a timer integrated with the event loop. This is much cleaner and avoids all of the problems you are having with subprocesses. Using fork() for concurrency is something Qubes OS does a lot, but it’s generally considered bad practice nowadays. Newer programs usually an event loop.

The two ways to deal with timeouts are to either use a timeout for poll() (updated each call) or a Linux timerfd.

Copy link
Contributor

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid using fork(). Managing child processes creates a lot of complexity and isn’t needed here.

perror("Can not get clipboard data file status");
exit(1);
}
switch (g->clipboard_timeout_pid = fork()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a subprocess, I recommend using a timer integrated with the event loop. This is much cleaner and avoids all of the problems you are having with subprocesses. Using fork() for concurrency is something Qubes OS does a lot, but it’s generally considered bad practice nowadays. Newer programs usually an event loop.

The two ways to deal with timeouts are to either use a timeout for poll() (updated each call) or a Linux timerfd.

@marmarek
Copy link
Member

Actually, there is one benefit of using fork() here. It allows to clear the clipboard even if qube is shutdown in the meantime. @marmarta said it would be confusing if clearing the clipboard would depend on the source qube remain running long enough.

@marmarek
Copy link
Member

But also, the child process could be used just for the case of early qube shutdown, and otherwise use the event loop.

@DemiMarie
Copy link
Contributor

But also, the child process could be used just for the case of early qube shutdown, and otherwise use the event loop.

Alternatively the process could keep running even if the qube shut down, or just wipe the clipboard on qube shutdown.

@marmarta: what do you think of wiping the clipboard when the qube that pasted into it is shut down?

@marmarek
Copy link
Member

or just wipe the clipboard on qube shutdown.

I already asked, see my comment above.

Alternatively the process could keep running even if the qube shut down

That may be messy to do. You'll need to do most cleanup (destroy windows, unlink pidfile etc) but not the actual exit. But I don't have much better idea (keeping a child running is quite similar).

@alimirjamali
Copy link
Contributor Author

I have been thinking about this. The way we are trying to do it is wrong. We do not need multiple clipboard clearing processes or even one per GUI daemon instance. We only need one per entire GUIVM since there is only one instance of global clipboard.

On a new copy action, the GUI daemon instance handling the copy action should check if the mentioned clearing process exists and terminate it gracefully before overwriting the global clipboard. Then launch a new one if needed. This program is not necessarily the GUI daemon itself. It does not even require connection to X Window.

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

Successfully merging this pull request may close these issues.

Clear inter-VM global clipboard after a certain amount of time
4 participants