From 1fd1786122ca735841535ed53c07d8354c1998b7 Mon Sep 17 00:00:00 2001
From: Norman Feske <norman.feske@genode-labs.com>
Date: Wed, 28 Jun 2023 15:46:04 +0200
Subject: [PATCH] test/lx_hybrid: don't call glibc exit

This patch removes the use of the Entrypoint::schedule_suspend mechanism
and the call of glibc's exit from the lx_hybrid tests, for two reasons.

First, the interplay of atexit handlers executed by the glibc and
Genode's lx_hybrid library is complicated while bringing no benefits in
practice as lx_hybrid applications are usually servers that don't exit
anyway.

Second, the Entrypoint::schedule_suspend mechanism in not used by any
other component. By removing its use from the lx_hybrid tests, we can
remove this mechanism from the base library.

Issue #4940
---
 repos/base-linux/src/test/lx_hybrid_ctors/main.cc     |  7 +------
 repos/base-linux/src/test/lx_hybrid_errno/main.cc     | 11 ++---------
 repos/base-linux/src/test/lx_hybrid_exception/main.cc |  9 +--------
 .../base-linux/src/test/lx_hybrid_pthread_ipc/main.cc | 10 +---------
 4 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/repos/base-linux/src/test/lx_hybrid_ctors/main.cc b/repos/base-linux/src/test/lx_hybrid_ctors/main.cc
index 273b07b391..0d6b06783b 100644
--- a/repos/base-linux/src/test/lx_hybrid_ctors/main.cc
+++ b/repos/base-linux/src/test/lx_hybrid_ctors/main.cc
@@ -44,10 +44,6 @@ extern Testlib_testclass testlib_testobject;
 Testapp_testclass testapp_testobject;
 
 
-static int exit_status;
-static void exit_on_suspended() { exit(exit_status); }
-
-
 /*
  * Component implements classical main function in construct.
  */
@@ -63,6 +59,5 @@ void Component::construct(Genode::Env &env)
 	testapp_testobject.dummy();
 
 	log("--- returning from main ---");
-	exit_status = 0;
-	env.ep().schedule_suspend(exit_on_suspended, nullptr);
+	env.parent().exit(0);
 }
diff --git a/repos/base-linux/src/test/lx_hybrid_errno/main.cc b/repos/base-linux/src/test/lx_hybrid_errno/main.cc
index b20cdc9550..8ef45ddbf7 100644
--- a/repos/base-linux/src/test/lx_hybrid_errno/main.cc
+++ b/repos/base-linux/src/test/lx_hybrid_errno/main.cc
@@ -42,15 +42,9 @@ struct Thread : Genode::Thread
 };
 
 
-static int exit_status;
-static void exit_on_suspended() { exit(exit_status); }
-
-
 struct Unexpected_errno_change { };
 
-/*
- * Component implements classical main function in construct.
- */
+
 void Component::construct(Genode::Env &env)
 {
 	Genode::log("--- thread-local errno test ---");
@@ -75,6 +69,5 @@ void Component::construct(Genode::Env &env)
 	}
 
 	Genode::log("--- finished thread-local errno test ---");
-	exit_status = 0;
-	env.ep().schedule_suspend(exit_on_suspended, nullptr);
+	env.parent().exit(0);
 }
diff --git a/repos/base-linux/src/test/lx_hybrid_exception/main.cc b/repos/base-linux/src/test/lx_hybrid_exception/main.cc
index d18a17a232..76cc164472 100644
--- a/repos/base-linux/src/test/lx_hybrid_exception/main.cc
+++ b/repos/base-linux/src/test/lx_hybrid_exception/main.cc
@@ -23,13 +23,7 @@ using namespace Genode;
 
 class Test_exception { };
 
-static int exit_status;
-static void exit_on_suspended() { exit(exit_status); }
 
-
-/*
- * Component implements classical main function in construct.
- */
 void Component::construct(Genode::Env &env)
 {
 	log("--- lx_hybrid exception test ---");
@@ -42,6 +36,5 @@ void Component::construct(Genode::Env &env)
 	}
 
 	log("--- returning from main ---");
-	exit_status = 0;
-	env.ep().schedule_suspend(exit_on_suspended, nullptr);
+	env.parent().exit(0);
 }
diff --git a/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc b/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc
index 7d75d22619..a6ac592e00 100644
--- a/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc
+++ b/repos/base-linux/src/test/lx_hybrid_pthread_ipc/main.cc
@@ -50,13 +50,6 @@ static void *pthread_entry(void *)
 }
 
 
-static int exit_status;
-static void exit_on_suspended() { exit(exit_status); }
-
-
-/*
- * Component implements classical main function in construct.
- */
 void Component::construct(Genode::Env &env)
 {
 	Genode::log("--- pthread IPC test ---");
@@ -69,6 +62,5 @@ void Component::construct(Genode::Env &env)
 	main_wait_lock()->block();
 
 	Genode::log("--- finished pthread IPC test ---");
-	exit_status = 0;
-	env.ep().schedule_suspend(exit_on_suspended, nullptr);
+	env.parent().exit(0);
 }