Properly copy the P_ALTSTACK flag in struct proc::p_flag to the child

process on fork(2).

It is the supposed behavior stated in the manpage of sigaction(2), and
Solaris, NetBSD and FreeBSD 3-STABLE correctly do so.

The previous fix against libc_r/uthread/uthread_fork.c fixed the
problem only for the programs linked with libc_r, so back it out and
fix fork(2) itself to help those not linked with libc_r as well.

PR:		kern/26705
Submitted by:	KUROSAWA Takahiro <fwkg7679@mb.infoweb.ne.jp>
Tested by:	knu, GOTOU Yuuzou <gotoyuzo@notwork.org>,
		and some other people
Not objected by:	hackers
MFC in:		3 days
This commit is contained in:
Akinori MUSHA 2001-05-07 18:07:29 +00:00
parent a66173abd2
commit 3b26be6ae1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=76336
5 changed files with 5 additions and 34 deletions

View File

@ -32,7 +32,6 @@
* $FreeBSD$
*/
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@ -113,16 +112,7 @@ _fork(void)
else if (_pq_init(&_readyq) != 0) {
/* Abort this application: */
PANIC("Cannot initialize priority ready queue.");
} else if ((_thread_sigstack.ss_sp == NULL) &&
((_thread_sigstack.ss_sp = malloc(SIGSTKSZ)) == NULL))
PANIC("Unable to allocate alternate signal stack");
else {
/* Install the alternate signal stack: */
_thread_sigstack.ss_size = SIGSTKSZ;
_thread_sigstack.ss_flags = 0;
if (__sys_sigaltstack(&_thread_sigstack, NULL) != 0)
PANIC("Unable to install alternate signal stack");
} else {
/*
* Enter a loop to remove all threads other than
* the running thread from the thread list:

View File

@ -32,7 +32,6 @@
* $FreeBSD$
*/
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@ -113,16 +112,7 @@ _fork(void)
else if (_pq_init(&_readyq) != 0) {
/* Abort this application: */
PANIC("Cannot initialize priority ready queue.");
} else if ((_thread_sigstack.ss_sp == NULL) &&
((_thread_sigstack.ss_sp = malloc(SIGSTKSZ)) == NULL))
PANIC("Unable to allocate alternate signal stack");
else {
/* Install the alternate signal stack: */
_thread_sigstack.ss_size = SIGSTKSZ;
_thread_sigstack.ss_flags = 0;
if (__sys_sigaltstack(&_thread_sigstack, NULL) != 0)
PANIC("Unable to install alternate signal stack");
} else {
/*
* Enter a loop to remove all threads other than
* the running thread from the thread list:

View File

@ -32,7 +32,6 @@
* $FreeBSD$
*/
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@ -113,16 +112,7 @@ _fork(void)
else if (_pq_init(&_readyq) != 0) {
/* Abort this application: */
PANIC("Cannot initialize priority ready queue.");
} else if ((_thread_sigstack.ss_sp == NULL) &&
((_thread_sigstack.ss_sp = malloc(SIGSTKSZ)) == NULL))
PANIC("Unable to allocate alternate signal stack");
else {
/* Install the alternate signal stack: */
_thread_sigstack.ss_size = SIGSTKSZ;
_thread_sigstack.ss_flags = 0;
if (__sys_sigaltstack(&_thread_sigstack, NULL) != 0)
PANIC("Unable to install alternate signal stack");
} else {
/*
* Enter a loop to remove all threads other than
* the running thread from the thread list:

View File

@ -495,7 +495,7 @@ fork1(p1, flags, procp)
* Preserve some more flags in subprocess. PS_PROFIL has already
* been preserved.
*/
p2->p_flag |= p1->p_flag & P_SUGID;
p2->p_flag |= p1->p_flag & (P_SUGID | P_ALTSTACK);
if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
p2->p_flag |= P_CONTROLT;
if (flags & RFPPWAIT)

View File

@ -464,6 +464,7 @@ execsigs(p)
p->p_sigstk.ss_flags = SS_DISABLE;
p->p_sigstk.ss_size = 0;
p->p_sigstk.ss_sp = 0;
p->p_flag &= ~P_ALTSTACK;
/*
* Reset no zombies if child dies flag as Solaris does.
*/