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

Add support for exiting on stdin or stdout EOF #159

Merged
merged 7 commits into from
May 9, 2024

Conversation

DemiMarie
Copy link
Contributor

This adds two new boolean service configuration options:

  • exit-on-stdout-eof: exit when the socket service shuts down its output stream for writing.
  • exit-on-stdin-eof: exit when the client sends EOF.

To avoid compatibility problems, global variables are used to pass this information from the configuration parser to the I/O code. In the future, there should be a better way to pass this information, but this is not possible without more extensive changes. Fortunately, the configuration parser only runs once in the life of any process right now, so this commit adds assertions to check this. Qubes OS ships with assertions enabled, so any violation of this rule will be detected.

The main use of these features is to emulate the old qubes.ConnectTCP and qubes.UpdatesProxy services, which already had this behavior due to the use of socat.

These features are only supported for socket-based services, as executable services are more complicated and do not have a use case right now.

Currently, if a service exits due to exit-on-stdin-eof, the empty MSG_DATA_STDOUT that indicates EOF is not sent. This is not a problem because qrexec-client-vm interprets MSG_DATA_EXIT_CODE as also indicating EOF on stdout and stderr.

Fixes: QubesOS/qubes-issues#9176

Various code that manipulates file descriptors assumes that they _are_
open.  When changing this code, I don't want to consider the
consequences of them not being open.  Just check at startup that they
are open and exit if they are not.
Copy link

codecov bot commented May 4, 2024

Codecov Report

Attention: Patch coverage is 96.11650% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 77.82%. Comparing base (adbf4a2) to head (64d6e06).

Files Patch % Lines
daemon/qrexec-daemon.c 50.00% 2 Missing ⚠️
libqrexec/log.c 50.00% 1 Missing ⚠️
libqrexec/process_io.c 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
+ Coverage   77.75%   77.82%   +0.06%     
==========================================
  Files          54       54              
  Lines        9498     9577      +79     
==========================================
+ Hits         7385     7453      +68     
- Misses       2113     2124      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DemiMarie
Copy link
Contributor Author

Is there a way to mark some lines as “don’t expect to have coverage here”? The lines that don’t have coverage are things like “junk data protocol version” (but that is caught long before) or “program started with one of its standard streams closed” (but that means a bug in the caller).

@qubesos-bot
Copy link

qubesos-bot commented May 4, 2024

OpenQA test summary

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

New failures, excluding unstable

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

Failed tests

7 failures
  • system_tests_basic_vm_qrexec_gui

  • system_tests_pvgrub_salt_storage

    • [unstable] TC_41_HVMGrub_fedora-39-xfce: test_000_standalone_vm (error)
      qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...

    • [unstable] TC_41_HVMGrub_fedora-39-xfce: test_010_template_based_vm (error)
      qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...

  • system_tests_network_updates

  • system_tests_dispvm

    • [unstable] TC_20_DispVM_fedora-39-xfce: test_100_open_in_dispvm (failure)
      AssertionError: Timeout waiting for editor window
  • system_tests_basic_vm_qrexec_gui_zfs

Fixed failures

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

2 fixed
  • system_tests_splitgpg

  • system_tests_extra

    • TC_00_QVCTest_whonix-workstation-17: test_020_webcam (failure)
      AssertionError: 'qubes-video-companion webcam' exited early (0): b'...

Unstable tests

  • system_tests_basic_vm_qrexec_gui

    TC_20_AudioVM_Pulse_whonix-workstation-17/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 97080 AssertionError: only silence detected, no useful audio data
    • job 97185 AssertionError: only silence detected, no useful audio data
    • job 97620 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_222_audio_rec_unmuted_pulseaudio (3/5 times with errors)
    • job 97080 AssertionError: only silence detected, no useful audio data
    • job 97185 AssertionError: only silence detected, no useful audio data
    • job 97620 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce/test_223_audio_play_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_223_audio_play_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_250_audio_playback_audiovm_pipewire (1/5 times with errors)
    • job 98601 AssertionError: only silence detected, no useful audio data
  • system_tests_pvgrub_salt_storage

    TC_41_HVMGrub_debian-12-xfce/test_000_standalone_vm (3/5 times with errors)
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-39-xfce/test_000_standalone_vm (4/5 times with errors)
    • job 95176 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-39-xfce/test_000_standalone_vm (4/5 times with errors)
    • job 95176 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_debian-12-xfce/test_010_template_based_vm (3/5 times with errors)
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_41_HVMGrub_fedora-39-xfce/test_010_template_based_vm (4/5 times with errors)
    • job 95176 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    TC_42_PVHGrub_fedora-39-xfce/test_010_template_based_vm (4/5 times with errors)
    • job 95176 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 96359 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97092 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
    • job 97197 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 120 seco...
  • system_tests_splitgpg

    TC_10_Thunderbird_fedora-39-xfce/test_000_send_receive_default (4/5 times with errors)
    • job 96361 Exception: Failed to send message with error 'unknown'
    • job 97094 Exception: Failed to send message with error 'unknown'
    • job 97199 Exception: Failed to send message with error 'unknown'
    • job 97634 Exception: Failed to send message with error 'unknown'
    TC_10_Thunderbird_fedora-39-xfce/test_010_send_receive_inline_signed_only (4/5 times with errors)
    • job 96361 Exception: Failed to send message with error 'unknown'
    • job 97094 Exception: Failed to send message with error 'unknown'
    • job 97199 Exception: Failed to send message with error 'unknown'
    • job 97634 Exception: Failed to send message with error 'unknown'
    TC_10_Thunderbird_fedora-39-xfce/test_020_send_receive_inline_with_attachment (4/5 times with errors)
    • job 96361 Exception: Failed to send message with error 'unknown'
    • job 97094 Exception: Failed to send message with error 'unknown'
    • job 97199 Exception: Failed to send message with error 'unknown'
    • job 97634 Exception: Failed to send message with error 'unknown'
  • system_tests_extra

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

    TC_20_USBProxy_core3_whonix-gateway-17/test_070_attach_not_installed_front (1/5 times with errors)
    • job 97173 qubesusbproxy.core3ext.QubesUSBException: Device attach failed: 202...
    TC_20_USBProxy_core3_whonix-workstation-17/test_070_attach_not_installed_front (1/5 times with errors)
    • job 98333 qubesusbproxy.core3ext.QubesUSBException: Device attach failed: 202...
    TC_20_USBProxy_core3_debian-12-xfce/test_090_attach_stubdom (2/5 times with errors)
    • job 97608 AssertionError: 1 != 0 : Device connection failed
    • job 98333 AssertionError: 1 != 0 : Device connection failed
    TC_20_USBProxy_core3_fedora-39-xfce/test_090_attach_stubdom (2/5 times with errors)
    • job 97608 AssertionError: 1 != 0 : Device connection failed
    • job 98333 AssertionError: 1 != 0 : Device connection failed
  • system_tests_network_ipv6

    VmIPv6Networking_debian-12-xfce/test_031_firewall_dynamic_block (1/5 times with errors)
    • job 97090 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    VmIPv6Networking_fedora-39-xfce/test_031_firewall_dynamic_block (2/5 times with errors)
    • job 96357 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... AssertionError
    • job 97090 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... AssertionError
  • system_tests_network_updates

    TC_10_QvmTemplate_fedora-39-xfce/test_010_template_install (1/5 times with errors)
    • job 97631 AssertionError: libvirt event impl drain timeout
    TC_10_QvmTemplate_whonix-gateway-17/test_010_template_install (1/5 times with errors)
    • job 97201 AssertionError: libvirt event impl drain timeout
    TC_11_QvmTemplateMgmtVM_fedora-39-xfce/test_010_template_install (1/5 times with errors)
    • job 96358 AssertionError: libvirt event impl drain timeout
  • system_tests_dispvm

    TC_20_DispVM_fedora-39-xfce/test_100_open_in_dispvm (2/5 times with errors)
    • job 97625 AssertionError: Timeout waiting for editor window
    • job 98346 AssertionError: Timeout waiting for editor window
  • system_tests_devices

    TC_00_List_debian-12-xfce/test_001_list_loop_mounted (1/5 times with errors)
    • job 96351 AssertionError: Device test-inst-vm:loop0 (/tmp/test.img) should no...
  • system_tests_basic_vm_qrexec_gui_btrfs

    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 95165 AssertionError: too short audio, expected 10s, got 8.28539682539682...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 95165 AssertionError: too short audio, expected 10s, got 9.25759637188208...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (5/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 96348 AssertionError: only silence detected, no useful audio data
    • job 97081 AssertionError: only silence detected, no useful audio data
    • job 97186 AssertionError: only silence detected, no useful audio data
    • job 97621 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (1/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (5/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 96348 AssertionError: only silence detected, no useful audio data
    • job 97081 AssertionError: only silence detected, no useful audio data
    • job 97186 AssertionError: only silence detected, no useful audio data
    • job 97621 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 97621 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 97621 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (1/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 97621 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 95165 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
  • system_tests_basic_vm_qrexec_gui_ext4

    TC_00_Basic/test_141_libvirt_objects_reconnect (1/5 times with errors)
    • job 98343 AssertionError: libvirt event impl drain timeout
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (4/5 times with errors)
    • job 96349 AssertionError: only silence detected, no useful audio data
    • job 97082 AssertionError: only silence detected, no useful audio data
    • job 97187 AssertionError: only silence detected, no useful audio data
    • job 97622 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (4/5 times with errors)
    • job 96349 AssertionError: only silence detected, no useful audio data
    • job 97082 AssertionError: only silence detected, no useful audio data
    • job 97187 AssertionError: only silence detected, no useful audio data
    • job 97622 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97622 AssertionError: only silence detected, no useful audio data
    • job 98343 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97622 AssertionError: only silence detected, no useful audio data
    • job 98343 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 97622 AssertionError: only silence detected, no useful audio data
    • job 98343 AssertionError: only silence detected, no useful audio data
  • system_tests_basic_vm_qrexec_gui_xfs

    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_220_audio_play_pulseaudio (1/5 times with errors)
    • job 95167 AssertionError: too short audio, expected 10s, got 8.98888888888888...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (4/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 97083 AssertionError: only silence detected, no useful audio data
    • job 97188 AssertionError: only silence detected, no useful audio data
    • job 97623 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_221_audio_rec_muted_pulseaudio (1/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_222_audio_rec_unmuted_pulseaudio (1/5 times with errors)
    • job 97083 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (4/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    • job 97083 AssertionError: only silence detected, no useful audio data
    • job 97188 AssertionError: only silence detected, no useful audio data
    • job 97623 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97623 AssertionError: only silence detected, no useful audio data
    • job 98344 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97623 AssertionError: only silence detected, no useful audio data
    • job 98344 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_224_audio_rec_muted_hvm (1/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 97623 AssertionError: only silence detected, no useful audio data
    • job 98344 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 95167 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_20_AudioVM_PipeWire_debian-12-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 95167 AssertionError: too short audio, expected 10s, got 9.48408163265306...
    TC_20_AudioVM_PipeWire_fedora-39-xfce-pool/test_226_audio_playback_pipewire (1/5 times with errors)
    • job 95167 AssertionError: too short audio, expected 10s, got 9.47213151927437...
  • system_tests_basic_vm_qrexec_gui_zfs

    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_220_audio_play_pulseaudio (4/5 times with errors)
    • job 96337 AssertionError: only silence detected, no useful audio data
    • job 97096 AssertionError: only silence detected, no useful audio data
    • job 97175 AssertionError: only silence detected, no useful audio data
    • job 97636 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17-pool/test_222_audio_rec_unmuted_pulseaudio (4/5 times with errors)
    • job 96337 AssertionError: only silence detected, no useful audio data
    • job 97096 AssertionError: only silence detected, no useful audio data
    • job 97175 AssertionError: only silence detected, no useful audio data
    • job 97636 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97636 AssertionError: only silence detected, no useful audio data
    • job 98335 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_223_audio_play_hvm (2/5 times with errors)
    • job 97636 AssertionError: only silence detected, no useful audio data
    • job 98335 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 97636 AssertionError: only silence detected, no useful audio data
    • job 98335 AssertionError: only silence detected, no useful audio data
  • system_tests_basic_vm_qrexec_gui@hw1

    TC_20_AudioVM_Pulse_whonix-workstation-17/test_220_audio_play_pulseaudio (3/5 times with errors)
    • job 97080 AssertionError: only silence detected, no useful audio data
    • job 97185 AssertionError: only silence detected, no useful audio data
    • job 97620 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_whonix-workstation-17/test_222_audio_rec_unmuted_pulseaudio (3/5 times with errors)
    • job 97080 AssertionError: only silence detected, no useful audio data
    • job 97185 AssertionError: only silence detected, no useful audio data
    • job 97620 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_debian-12-xfce/test_223_audio_play_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_223_audio_play_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_Pulse_fedora-39-xfce/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 97620 AssertionError: only silence detected, no useful audio data
    • job 98341 AssertionError: only silence detected, no useful audio data
    TC_20_AudioVM_PipeWire_debian-12-xfce/test_250_audio_playback_audiovm_pipewire (1/5 times with errors)
    • job 98601 AssertionError: only silence detected, no useful audio data

@marmarek
Copy link
Member

marmarek commented May 4, 2024

Is there a way to mark some lines as “don’t expect to have coverage here”?

I don't know, but sounds useful to have. Maybe gcov documentation says something about this? Or codecov one?

Copy link
Member

@marmarek marmarek left a comment

Choose a reason for hiding this comment

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

"Implement new version of process_io() that takes extensible struct" are partially included in "Add support for exiting on stdin or stdout EOF" - specifically the second iteration of process_io refactor. And also the commit message of the latter is outdated now - the global variables thing is not true.


if (type == MSG_EXEC_CMDLINE)
if (type == MSG_EXEC_CMDLINE && pid > 0)
LOG(INFO, "pid %d exited with %d", pid, exit_code);
Copy link
Member

Choose a reason for hiding this comment

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

Can I get some log message on service exit?

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 that should be a separate commit, since the current log message is completely unhelpful.

Copy link
Member

Choose a reason for hiding this comment

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

It is helpful in that journald adds the logging process PID to the message, which can be easily correlated with the service start log.

@@ -731,6 +742,18 @@ int find_qrexec_service(
path_buffer.data);
return -2;
}
if (cmd->exit_on_stdout_eof) {
LOG(ERROR, "Refusing to execute executable service %s with "
"exit-on-service-eof=true",
Copy link
Member

Choose a reason for hiding this comment

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

This is not the config name actually used.

}
if (cmd->exit_on_stdin_eof) {
LOG(ERROR, "Refusing to execute executable service %s with "
"exit-on-client-eof=true",
Copy link
Member

Choose a reason for hiding this comment

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

And here

Copy link
Contributor Author

@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.

Which name should I use in the config? exit-on-stdin-eof/exit-on-stdout-eof or exit-on-client-eof/exit-on-server-eof?


if (type == MSG_EXEC_CMDLINE)
if (type == MSG_EXEC_CMDLINE && pid > 0)
LOG(INFO, "pid %d exited with %d", pid, exit_code);
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 that should be a separate commit, since the current log message is completely unhelpful.

@marmarek
Copy link
Member

marmarek commented May 5, 2024

Which name should I use in the config? exit-on-stdin-eof/exit-on-stdout-eof or exit-on-client-eof/exit-on-server-eof?

That's a good question. Both require some documentation to clarify the behavior, but maybe the latter is a bit clearer? idk...

@DemiMarie
Copy link
Contributor Author

Which name should I use in the config? exit-on-stdin-eof/exit-on-stdout-eof or exit-on-client-eof/exit-on-server-eof?

That's a good question. Both require some documentation to clarify the behavior, but maybe the latter is a bit clearer? idk...

I think so too. I kept using stdin/stdout internally, though, because that is what the file descriptors are named and so it makes the code easier to read.

DemiMarie added 6 commits May 5, 2024 11:35
"pid 0 exited with 0" is not helpful.  Just log "Socket service exited"
and let the user use the PID recorded by systemd-journald to correlate
that with the service start log.
This adds two new boolean service configuration options:

- exit-on-service-eof: exit when the socket service shuts down its
  output stream for writing.

- exit-on-client-eof: exit when the client shuts down its output stream
  for writing.

The information is passed through an extended qrexec_parsed_command
struct.  New functions are added that avoid the executables having to
access members that are private to libqrexec.

The main use of these features is to emulate the old qubes.ConnectTCP
and qubes.UpdatesProxy services, which already had this behavior due to
the use of socat.

These features are only supported for socket-based services, as
executable services are more complicated and do not have a use case
right now.

Currently, if a service exits due to exit-on-stdin-eof, the empty
MSG_DATA_STDOUT that indicates EOF is not sent.  This is not a problem
because qrexec-client-vm interprets MSG_DATA_EXIT_CODE as also
indicating EOF on stdout and stderr.

Fixes: QubesOS/qubes-issues#9176
The agent might exit before the empty MSG_DATA_STDIN message is sent.
It is always -1, and an assertion would fail if it was not.
If finding the service config fails with an I/O error, bail out
promptly.
@marmarek marmarek merged commit 7d01e17 into QubesOS:main May 9, 2024
4 checks passed
@DemiMarie DemiMarie deleted the exit-eof branch May 9, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Socket-based services should support exiting when remote shuts down write end
3 participants