xref: /haiku/src/system/libroot/posix/unistd/process.c (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*
2 ** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
5 
6 
7 #include <syscalls.h>
8 #include <syscall_process_info.h>
9 
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 
14 
15 #define RETURN_AND_SET_ERRNO(err) \
16 	if (err < 0) { \
17 		errno = err; \
18 		return -1; \
19 	} \
20 	return err;
21 
22 
23 extern thread_id __main_thread_id;
24 
25 
26 pid_t
27 getpgrp(void)
28 {
29 	return getpgid(__main_thread_id);
30 }
31 
32 
33 pid_t
34 getpid(void)
35 {
36 	// this one returns the ID of the main thread
37 	return __main_thread_id;
38 }
39 
40 
41 pid_t
42 getppid(void)
43 {
44 	return _kern_process_info(0, PARENT_ID);
45 		// this is not supposed to return an error value
46 }
47 
48 
49 pid_t
50 getsid(pid_t process)
51 {
52 	pid_t session = _kern_process_info(process, SESSION_ID);
53 
54 	RETURN_AND_SET_ERRNO(session);
55 }
56 
57 
58 pid_t
59 getpgid(pid_t process)
60 {
61 	pid_t group = _kern_process_info(process, GROUP_ID);
62 
63 	RETURN_AND_SET_ERRNO(group);
64 }
65 
66 
67 int
68 setpgid(pid_t process, pid_t group)
69 {
70 	status_t status = _kern_setpgid(process, group);
71 
72 	RETURN_AND_SET_ERRNO(status);
73 }
74 
75 
76 int
77 setpgrp(void)
78 {
79 	return setpgid(0, 0);
80 }
81 
82 
83 pid_t
84 setsid(void)
85 {
86 	status_t status = _kern_setsid();
87 
88 	RETURN_AND_SET_ERRNO(status);
89 }
90 
91