1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <errno.h>
30 #include <unistd.h>
31 #include <sys/lx_misc.h>
32
33 /*
34 * fork() and vfork()
35 *
36 * These cannot be pass thru system calls because we need libc to do its own
37 * initialization or else bad things will happen (i.e. ending up with a bad
38 * schedctl page). On Linux, there is no such thing as forkall(), so we use
39 * fork1() here.
40 */
41 int
42 lx_fork(void)
43 {
44 int ret = fork1();
45
46 if (ret == 0 && lx_is_rpm)
47 (void) sleep(lx_rpm_delay);
48
49 return (ret == -1 ? -errno : ret);
50 }
51
52 /*
53 * For vfork(), we have a serious problem because the child is not allowed to
54 * return from the current frame because it will corrupt the parent's stack.
55 * Since the semantics of vfork() are rather ill-defined (other than "it's
56 * faster than fork"), we should theoretically be safe by falling back to
57 * fork1().
58 */
59 int
60 lx_vfork(void)
61 {
62 int ret = fork1();
63
64 return (ret == -1 ? -errno : ret);
65 }