Deleted Added
full compact
kern_fork.c (17366) kern_fork.c (17660)
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 * $Id: kern_fork.c,v 1.22 1996/06/12 05:07:30 gpalmer Exp $
39 * $Id: kern_fork.c,v 1.23 1996/07/31 09:26:34 davidg Exp $
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/sysproto.h>
47#include <sys/filedesc.h>

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

59#include <vm/lock.h>
60#include <vm/pmap.h>
61#include <vm/vm_map.h>
62#include <vm/vm_extern.h>
63#include <vm/vm_inherit.h>
64
65static int fork1 __P((struct proc *p, int flags, int *retval));
66
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/sysproto.h>
47#include <sys/filedesc.h>

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

59#include <vm/lock.h>
60#include <vm/pmap.h>
61#include <vm/vm_map.h>
62#include <vm/vm_extern.h>
63#include <vm/vm_inherit.h>
64
65static int fork1 __P((struct proc *p, int flags, int *retval));
66
67/*
68 * callout list for things to do at fork time
69 */
70typedef struct fork_list_element {
71 struct fork_list_element *next;
72 forklist_fn function;
73} *fle_p;
74
75static fle_p fork_list;
76
67#ifndef _SYS_SYSPROTO_H_
68struct fork_args {
69 int dummy;
70};
71#endif
72
73/* ARGSUSED */
74int

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

109 int flags;
110 int retval[];
111{
112 register struct proc *p2, *pptr;
113 register uid_t uid;
114 struct proc *newproc;
115 int count;
116 static int nextpid, pidchecked = 0;
77#ifndef _SYS_SYSPROTO_H_
78struct fork_args {
79 int dummy;
80};
81#endif
82
83/* ARGSUSED */
84int

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

119 int flags;
120 int retval[];
121{
122 register struct proc *p2, *pptr;
123 register uid_t uid;
124 struct proc *newproc;
125 int count;
126 static int nextpid, pidchecked = 0;
127 fle_p ep = fork_list;
117
118 if ((flags & RFPROC) == 0)
119 return (EINVAL);
120 if ((flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG))
121 return (EINVAL);
122
123 /*
124 * Although process entries are dynamically created, we still keep

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

330 */
331 microtime(&runtime);
332 p2->p_stats->p_start = runtime;
333 p2->p_acflag = AFORK;
334 return (0);
335 }
336
337 /*
128
129 if ((flags & RFPROC) == 0)
130 return (EINVAL);
131 if ((flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG))
132 return (EINVAL);
133
134 /*
135 * Although process entries are dynamically created, we still keep

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

341 */
342 microtime(&runtime);
343 p2->p_stats->p_start = runtime;
344 p2->p_acflag = AFORK;
345 return (0);
346 }
347
348 /*
349 * Both processes are set up,
350 * check if any LKMs want to adjust anything
351 * What if they have an error? XXX
352 */
353 while(ep) {
354 (*ep->function)(p1,p2,flags);
355 ep = ep->next;
356 }
357
358 /*
338 * Make child runnable and add to run queue.
339 */
340 (void) splhigh();
341 p2->p_stat = SRUN;
342 setrunqueue(p2);
343 (void) spl0();
344
345 /*

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

358 /*
359 * Return child pid to parent process,
360 * marking us as parent via retval[1].
361 */
362 retval[0] = p2->p_pid;
363 retval[1] = 0;
364 return (0);
365}
359 * Make child runnable and add to run queue.
360 */
361 (void) splhigh();
362 p2->p_stat = SRUN;
363 setrunqueue(p2);
364 (void) spl0();
365
366 /*

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

379 /*
380 * Return child pid to parent process,
381 * marking us as parent via retval[1].
382 */
383 retval[0] = p2->p_pid;
384 retval[1] = 0;
385 return (0);
386}
387
388
389/*********************************************************
390 * general routines to handle adding/deleting items on the
391 * fork callout list
392 *****
393 * Take the arguments given and put them onto the fork callout list.
394 * However first make sure that it's not already there.
395 * returns 0 on success.
396 */
397int
398at_fork(forklist_fn function)
399{
400 fle_p ep;
401 if(rm_at_fork(function)) {
402 printf("fork callout entry already present\n");
403 }
404 ep = malloc(sizeof(*ep),M_TEMP,M_NOWAIT);
405 if(!ep) return ENOMEM;
406 ep->next = fork_list;
407 ep->function = function;
408 fork_list = ep;
409 return 0;
410}
411/*
412 * Scan the exit callout list for the given items and remove them.
413 * Returns the number of items removed.
414 */
415int
416rm_at_fork(forklist_fn function)
417{
418 fle_p *epp,ep;
419 int count = 0;
420
421 epp = &fork_list;
422 ep = *epp;
423 while(ep) {
424 if(ep->function == function) {
425 *epp = ep->next;
426 free(ep,M_TEMP);
427 count++;
428 } else {
429 epp = &ep->next;
430 }
431 ep = *epp;
432 }
433 return count;
434}
435
436