c3605080e8eac4ad38ec96557bbae96b77da4277
[lttng-tools.git] / src / common / compat / clone.h
1 /*
2 * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 #ifndef _COMPAT_CLONE_H
19 #define _COMPAT_CLONE_H
20
21 #ifdef __linux__
22
23 #include <sched.h>
24
25 static inline
26 pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg)
27 {
28 return clone(fn, child_stack, CLONE_FILES | SIGCHLD, arg);
29 }
30
31 #elif defined(__FreeBSD__)
32
33 #include <unistd.h>
34
35 static inline
36 pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg)
37 {
38 pid_t pid;
39
40 pid = rfork(RFPROC | RFTHREAD);
41 if (pid == 0) {
42 /* child */
43 int ret;
44
45 ret = fn(arg);
46 exit(ret);
47 } else if (pid > 0) {
48 /* parent */
49 /*
50 * Just return, the caller will wait for the child.
51 */
52 return pid;
53 } else {
54 /* Error */
55 return pid;
56 }
57 }
58
59 #else
60 #error "Please add support for your OS."
61 #endif /* __linux__ , __FreeBSD__ */
62
63 #endif /* _COMPAT_CLONE_H */
This page took 0.029613 seconds and 3 git commands to generate.