Deleted Added
full compact
kern_fork.c (114983) kern_fork.c (115702)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94
39 * $FreeBSD: head/sys/kern/kern_fork.c 114983 2003-05-13 20:36:02Z jhb $
39 * $FreeBSD: head/sys/kern/kern_fork.c 115702 2003-06-02 16:05:32Z tegge $
40 */
41
42#include "opt_ktrace.h"
43#include "opt_mac.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 86 unchanged lines hidden (view full) ---

134 struct rfork_args *uap;
135{
136 int error;
137 struct proc *p2;
138
139 /* Don't allow kernel only flags. */
140 if ((uap->flags & RFKERNELONLY) != 0)
141 return (EINVAL);
40 */
41
42#include "opt_ktrace.h"
43#include "opt_mac.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 86 unchanged lines hidden (view full) ---

134 struct rfork_args *uap;
135{
136 int error;
137 struct proc *p2;
138
139 /* Don't allow kernel only flags. */
140 if ((uap->flags & RFKERNELONLY) != 0)
141 return (EINVAL);
142 /*
143 * Don't allow sharing of file descriptor table unless
144 * RFTHREAD flag is supplied
145 */
146 if ((uap->flags & (RFPROC | RFTHREAD | RFFDG | RFCFDG)) ==
147 RFPROC)
148 return(EINVAL);
149 error = fork1(td, uap->flags, 0, &p2);
150 if (error == 0) {
151 td->td_retval[0] = p2 ? p2->p_pid : 0;
152 td->td_retval[1] = 0;
153 }
154 return error;
155}
156

--- 47 unchanged lines hidden (view full) ---

204{
205 struct proc *p2, *pptr;
206 uid_t uid;
207 struct proc *newproc;
208 int trypid;
209 int ok;
210 static int pidchecked = 0;
211 struct filedesc *fd;
142 error = fork1(td, uap->flags, 0, &p2);
143 if (error == 0) {
144 td->td_retval[0] = p2 ? p2->p_pid : 0;
145 td->td_retval[1] = 0;
146 }
147 return error;
148}
149

--- 47 unchanged lines hidden (view full) ---

197{
198 struct proc *p2, *pptr;
199 uid_t uid;
200 struct proc *newproc;
201 int trypid;
202 int ok;
203 static int pidchecked = 0;
204 struct filedesc *fd;
205 struct filedesc_to_leader *fdtol;
212 struct proc *p1 = td->td_proc;
213 struct thread *td2;
214 struct kse *ke2;
215 struct ksegrp *kg2;
216 struct sigacts *newsigacts;
217 int error;
218
219 /* Can't copy and clear */

--- 194 unchanged lines hidden (view full) ---

414 if (flags & RFSIGSHARE)
415 newsigacts = NULL;
416 else
417 newsigacts = sigacts_alloc();
418
419 /*
420 * Copy filedesc.
421 */
206 struct proc *p1 = td->td_proc;
207 struct thread *td2;
208 struct kse *ke2;
209 struct ksegrp *kg2;
210 struct sigacts *newsigacts;
211 int error;
212
213 /* Can't copy and clear */

--- 194 unchanged lines hidden (view full) ---

408 if (flags & RFSIGSHARE)
409 newsigacts = NULL;
410 else
411 newsigacts = sigacts_alloc();
412
413 /*
414 * Copy filedesc.
415 */
422 if (flags & RFCFDG)
416 if (flags & RFCFDG) {
423 fd = fdinit(td->td_proc->p_fd);
417 fd = fdinit(td->td_proc->p_fd);
424 else if (flags & RFFDG) {
418 fdtol = NULL;
419 } else if (flags & RFFDG) {
425 FILEDESC_LOCK(p1->p_fd);
426 fd = fdcopy(td->td_proc->p_fd);
427 FILEDESC_UNLOCK(p1->p_fd);
420 FILEDESC_LOCK(p1->p_fd);
421 fd = fdcopy(td->td_proc->p_fd);
422 FILEDESC_UNLOCK(p1->p_fd);
428 } else
423 fdtol = NULL;
424 } else {
429 fd = fdshare(p1->p_fd);
425 fd = fdshare(p1->p_fd);
430
426 if (p1->p_fdtol == NULL)
427 p1->p_fdtol =
428 filedesc_to_leader_alloc(NULL,
429 NULL,
430 p1->p_leader);
431 if ((flags & RFTHREAD) != 0) {
432 /*
433 * Shared file descriptor table and
434 * shared process leaders.
435 */
436 fdtol = p1->p_fdtol;
437 FILEDESC_LOCK(p1->p_fd);
438 fdtol->fdl_refcount++;
439 FILEDESC_UNLOCK(p1->p_fd);
440 } else {
441 /*
442 * Shared file descriptor table, and
443 * different process leaders
444 */
445 fdtol = filedesc_to_leader_alloc(p1->p_fdtol,
446 p1->p_fd,
447 p2);
448 }
449 }
431 /*
432 * Make a proc table entry for the new process.
433 * Start by zeroing the section of proc that is zero-initialized,
434 * then copy the section that is copied directly from the parent.
435 */
436 td2 = FIRST_THREAD_IN_PROC(p2);
437 kg2 = FIRST_KSEGRP_IN_PROC(p2);
438 ke2 = FIRST_KSE_IN_KSEGRP(kg2);

--- 62 unchanged lines hidden (view full) ---

501 else
502 p2->p_sigparent = SIGCHLD;
503
504 /* Bump references to the text vnode (for procfs) */
505 p2->p_textvp = p1->p_textvp;
506 if (p2->p_textvp)
507 VREF(p2->p_textvp);
508 p2->p_fd = fd;
450 /*
451 * Make a proc table entry for the new process.
452 * Start by zeroing the section of proc that is zero-initialized,
453 * then copy the section that is copied directly from the parent.
454 */
455 td2 = FIRST_THREAD_IN_PROC(p2);
456 kg2 = FIRST_KSEGRP_IN_PROC(p2);
457 ke2 = FIRST_KSE_IN_KSEGRP(kg2);

--- 62 unchanged lines hidden (view full) ---

520 else
521 p2->p_sigparent = SIGCHLD;
522
523 /* Bump references to the text vnode (for procfs) */
524 p2->p_textvp = p1->p_textvp;
525 if (p2->p_textvp)
526 VREF(p2->p_textvp);
527 p2->p_fd = fd;
528 p2->p_fdtol = fdtol;
509 PROC_UNLOCK(p1);
510 PROC_UNLOCK(p2);
511
512 /*
513 * p_limit is copy-on-write, bump refcnt,
514 */
515 p2->p_limit = p1->p_limit;
516 p2->p_limit->p_refcnt++;

--- 291 unchanged lines hidden ---
529 PROC_UNLOCK(p1);
530 PROC_UNLOCK(p2);
531
532 /*
533 * p_limit is copy-on-write, bump refcnt,
534 */
535 p2->p_limit = p1->p_limit;
536 p2->p_limit->p_refcnt++;

--- 291 unchanged lines hidden ---