From d47541a3d7a20fd522dfad032d5d26bebf87e4f4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 8 Dec 2019 11:44:21 -0800 Subject: [PATCH] Add a tricky test to verify disowning an in-flight job There's some logic in fish to prevent blowing up when an under-construction job is disowned. Add a test for it. --- src/fish_test_helper.cpp | 8 ++++++++ tests/checks/disown-parent.fish | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/checks/disown-parent.fish diff --git a/src/fish_test_helper.cpp b/src/fish_test_helper.cpp index 20310f495..5f3035a5b 100644 --- a/src/fish_test_helper.cpp +++ b/src/fish_test_helper.cpp @@ -46,6 +46,12 @@ static void print_stdout_stderr() { fflush(nullptr); } +static void print_pid_then_sleep() { + fprintf(stdout, "%d\n", getpid()); + fflush(nullptr); + usleep(1000000 / .5); //.5 secs +} + int main(int argc, char *argv[]) { if (argc <= 1) { fprintf(stderr, "No commands given.\n"); @@ -60,6 +66,8 @@ int main(int argc, char *argv[]) { sigint_parent(); } else if (!strcmp(argv[i], "print_stdout_stderr")) { print_stdout_stderr(); + } else if (!strcmp(argv[i], "print_pid_then_sleep")) { + print_pid_then_sleep(); } else { fprintf(stderr, "%s: Unknown command: %s\n", argv[0], argv[i]); return EXIT_FAILURE; diff --git a/tests/checks/disown-parent.fish b/tests/checks/disown-parent.fish new file mode 100644 index 000000000..adfe8e344 --- /dev/null +++ b/tests/checks/disown-parent.fish @@ -0,0 +1,14 @@ +# RUN: env fish_test_helper=%fish_test_helper %fish %s + +# Ensure that a job which attempts to disown itself does not explode. +# Here fish_test_helper is the process group leader; we attempt to disown +# its pid within a pipeline containing it. + +function disowner + read -l pid + echo Disown $pid + disown $pid +end +$fish_test_helper print_pid_then_sleep | disowner + +# CHECK: Disown {{\d+}}