* [PATCH 1/2] support: Add delayed__exit (with two underscores)
@ 2023-06-06 9:40 Florian Weimer
2023-06-06 9:40 ` [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test Florian Weimer
2023-06-06 11:14 ` [PATCH 1/2] support: Add delayed__exit (with two underscores) Andreas Schwab
0 siblings, 2 replies; 4+ messages in thread
From: Florian Weimer @ 2023-06-06 9:40 UTC (permalink / raw)
To: libc-alpha
It calls _exit instead of exit once the timeout expires.
---
support/delayed_exit.c | 41 +++++++++++++++++++++++++++++++++--------
support/xthread.h | 9 ++++++---
2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/support/delayed_exit.c b/support/delayed_exit.c
index 53aa40c275..bc64ff0d3e 100644
--- a/support/delayed_exit.c
+++ b/support/delayed_exit.c
@@ -23,33 +23,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
+#include <support/support.h>
#include <time.h>
+#include <unistd.h>
+
+struct delayed_exit_request
+{
+ void (*exitfunc) (int);
+ int seconds;
+};
static void *
-delayed_exit_thread (void *seconds_as_ptr)
+delayed_exit_thread (void *closure)
{
- int seconds = (uintptr_t) seconds_as_ptr;
- struct timespec delay = { seconds, 0 };
+ struct delayed_exit_request *request = closure;
+ void (*exitfunc) (int) = request->exitfunc;
+ struct timespec delay = { request->seconds, 0 };
struct timespec remaining = { 0 };
+ free (request);
+
if (nanosleep (&delay, &remaining) != 0)
FAIL_EXIT1 ("nanosleep: %m");
/* Exit the process successfully. */
- exit (0);
+ exitfunc (0);
return NULL;
}
-void
-delayed_exit (int seconds)
+static void
+delayed_exit_1 (int seconds, void (*exitfunc) (int))
{
/* Create the new thread with all signals blocked. */
sigset_t all_blocked;
sigfillset (&all_blocked);
sigset_t old_set;
xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set);
+ struct delayed_exit_request *request = xmalloc (sizeof (*request));
+ request->seconds = seconds;
+ request->exitfunc = exitfunc;
/* Create a detached thread. */
- pthread_t thr = xpthread_create
- (NULL, delayed_exit_thread, (void *) (uintptr_t) seconds);
+ pthread_t thr = xpthread_create (NULL, delayed_exit_thread, request);
xpthread_detach (thr);
/* Restore the original signal mask. */
xpthread_sigmask (SIG_SETMASK, &old_set, NULL);
}
+
+void
+delayed_exit (int seconds)
+{
+ delayed_exit_1 (seconds, exit);
+}
+
+void
+delayed__exit (int seconds)
+{
+ delayed_exit_1 (seconds, _exit);
+}
diff --git a/support/xthread.h b/support/xthread.h
index b1e85a9b56..402df561aa 100644
--- a/support/xthread.h
+++ b/support/xthread.h
@@ -25,11 +25,14 @@
__BEGIN_DECLS
-/* Terminate the process (with exit status 0) after SECONDS have
- elapsed, from a helper thread. The process is terminated with the
- exit function, so atexit handlers are executed. */
+/* Terminate the process (with exit (0)) after SECONDS have elapsed,
+ from a helper thread. The process is terminated with the exit
+ function, so atexit handlers are executed. */
void delayed_exit (int seconds);
+/* Like delayed_exit, but use _exit (0). */
+void delayed__exit (int seconds);
+
/* Returns true if Priority Inheritance support CLOCK_MONOTONIC. */
bool support_mutex_pi_monotonic (void);
base-commit: e3622a8f391deea3b75a577dce70d023dfa3f1c7
--
2.40.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test
2023-06-06 9:40 [PATCH 1/2] support: Add delayed__exit (with two underscores) Florian Weimer
@ 2023-06-06 9:40 ` Florian Weimer
2023-06-06 11:14 ` Andreas Schwab
2023-06-06 11:14 ` [PATCH 1/2] support: Add delayed__exit (with two underscores) Andreas Schwab
1 sibling, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2023-06-06 9:40 UTC (permalink / raw)
To: libc-alpha
Previously, the exit function was used, but this causes the test to
block (until the timeout) once exit is changed to lock stdio streams
during flush.
---
sysdeps/pthread/tst-stdio1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysdeps/pthread/tst-stdio1.c b/sysdeps/pthread/tst-stdio1.c
index 1266181505..b198576319 100644
--- a/sysdeps/pthread/tst-stdio1.c
+++ b/sysdeps/pthread/tst-stdio1.c
@@ -46,7 +46,7 @@ do_test (void)
_exit (1);
}
- delayed_exit (1);
+ delayed__exit (1);
xpthread_join (th);
puts ("join returned");
--
2.40.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] support: Add delayed__exit (with two underscores)
2023-06-06 9:40 [PATCH 1/2] support: Add delayed__exit (with two underscores) Florian Weimer
2023-06-06 9:40 ` [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test Florian Weimer
@ 2023-06-06 11:14 ` Andreas Schwab
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2023-06-06 11:14 UTC (permalink / raw)
To: Florian Weimer via Libc-alpha; +Cc: Florian Weimer
On Jun 06 2023, Florian Weimer via Libc-alpha wrote:
> It calls _exit instead of exit once the timeout expires.
Ok.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test
2023-06-06 9:40 ` [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test Florian Weimer
@ 2023-06-06 11:14 ` Andreas Schwab
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2023-06-06 11:14 UTC (permalink / raw)
To: Florian Weimer via Libc-alpha; +Cc: Florian Weimer
On Jun 06 2023, Florian Weimer via Libc-alpha wrote:
> Previously, the exit function was used, but this causes the test to
> block (until the timeout) once exit is changed to lock stdio streams
> during flush.
Ok.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-06 11:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 9:40 [PATCH 1/2] support: Add delayed__exit (with two underscores) Florian Weimer
2023-06-06 9:40 ` [PATCH 2/2] pthreads: Use _exit to terminate the tst-stdio1 test Florian Weimer
2023-06-06 11:14 ` Andreas Schwab
2023-06-06 11:14 ` [PATCH 1/2] support: Add delayed__exit (with two underscores) Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).