Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ if (COMMANDLINE_TESTS)
endif ()
enable_testing()
add_test(NAME commandline_tests COMMAND commandline_tests)
if (UNIX)
add_test(NAME regression_issue42
COMMAND bash "${CMAKE_SOURCE_DIR}/tests/regression_issue42.sh" "${CMAKE_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()
endif ()
6 changes: 6 additions & 0 deletions src/backends/InteractiveBackend.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "InteractiveBackend.h"

#include <cstdio>

#include "impls.h"

lk::InteractiveBackend::InteractiveBackend(const std::string& prompt)
Expand Down Expand Up @@ -235,6 +237,10 @@ void lk::InteractiveBackend::input_thread_main() {
if (m_key_debug) {
fprintf(stderr, "c: 0x%.2x\n", c);
}
if (c == EOF) {
m_shutdown.store(true);
break;
}
std::unique_lock<std::mutex> guard(m_current_buffer_mutex);
if (c != '\t') {
}
Expand Down
37 changes: 37 additions & 0 deletions tests/regression_issue42.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Regression test for #42: GNU screen -dmS causes commandline to break and CPU spin.
#
# Forced interactive mode + /dev/null stdin simulates the detached-screen scenario:
# stdin reaches EOF immediately. The input thread must detect EOF and shut down
# instead of spinning.
set -euo pipefail

if [ ! -e /dev/null ] || ! command -v /usr/bin/time >/dev/null 2>&1; then
echo "SKIP: /usr/bin/time and /dev/null required (Unix-only regression test)"
exit 0
fi

BINARY="${1:-build}/commandline_test"

TIME_OUT=$(mktemp)
trap 'rm -f "$TIME_OUT"' EXIT

COMMANDLINE_FORCE_INTERACTIVE=1 \
/usr/bin/time -o "$TIME_OUT" -v timeout 3 "$BINARY" \
< /dev/null >/dev/null 2>/dev/null || true

total_cpu=$(awk '
/User time \(seconds\)/ { u = $NF }
/System time \(seconds\)/ { s = $NF }
END {
if (u == "" || s == "") exit 1
print u + s
}
' "$TIME_OUT") || { echo "FAIL: could not parse CPU time from /usr/bin/time output"; exit 1; }

if awk "BEGIN {exit !($total_cpu >= 0.3)}"; then
echo "FAIL: CPU spin detected: ${total_cpu}s CPU in 3s"
exit 1
fi

echo "PASS: no CPU spin (${total_cpu}s CPU in 3s)"
Loading