fork(): Follow-up fix to 17b2a3cfc.

* Ingo rightly noticed that the defer_signals counter is reinitialized on
  thread's user area creation. Setting the flag THREAD_CREATION_FLAG_DEFER_SIGNALS
  indeed gives the expected behavior, deferring signals until undefer_signals() is
  called in the child thread. Thanks for the review and fix suggestion.
* Added a simple test showing the values of the defer_signals counter after fork().
This commit is contained in:
Jérôme Duval 2016-12-18 09:28:52 +01:00
parent 941c240ab0
commit 9969137ced
3 changed files with 34 additions and 0 deletions

View File

@ -2185,6 +2185,7 @@ fork_team(void)
ThreadCreationAttributes threadCreationAttributes(NULL,
parentThread->name, parentThread->priority, NULL, team->id, thread);
threadCreationAttributes.forkArgs = forkArgs;
threadCreationAttributes.flags |= THREAD_CREATION_FLAG_DEFER_SIGNALS;
threadID = thread_create_thread(threadCreationAttributes, false);
if (threadID < 0) {
status = threadID;

View File

@ -1,5 +1,7 @@
SubDir HAIKU_TOP src tests system libroot posix ;
UsePrivateHeaders libroot system ;
# filter warnings about strftime()-formats in locale_test
TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)
on [ FGristFiles locale_test.o ] += -Wno-format ;
@ -34,6 +36,7 @@ SimpleTest test_time : test_time.c ;
SimpleTest tst-mktime : tst-mktime.c ;
SimpleTest <test>truncate : truncate.cpp ;
SimpleTest init_rld_after_fork_test : init_rld_after_fork_test.cpp ;
SimpleTest user_thread_fork_test : user_thread_fork_test.cpp ;
# XSI tests
SimpleTest xsi_msg_queue_test1 : xsi_msg_queue_test1.cpp ;

View File

@ -0,0 +1,30 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <OS.h>
#include "user_thread.h"
int
main()
{
pid_t child = fork();
if (child < 0) {
fprintf(stderr, "Error: fork() failed: %s\n", strerror(errno));
exit(1);
}
if (child > 0) {
// the parent process -- wait for the child to finish
status_t result;
wait_for_thread(child, &result);
}
struct user_thread *t = get_user_thread();
printf("defer_signals: %" B_PRId32 "\n", t->defer_signals);
return 0;
}