1/*
2 * Copyright 2002-2007, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT 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#include <errno_private.h>
15#include <syscall_utils.h>
16
17
18extern thread_id __main_thread_id;
19
20
21pid_t
22getpgrp(void)
23{
24	return getpgid(__main_thread_id);
25}
26
27
28pid_t
29getpid(void)
30{
31	// this one returns the ID of the main thread
32	return __main_thread_id;
33}
34
35
36pid_t
37getppid(void)
38{
39	return _kern_process_info(0, PARENT_ID);
40		// this is not supposed to return an error value
41}
42
43
44pid_t
45getsid(pid_t process)
46{
47	pid_t session = _kern_process_info(process, SESSION_ID);
48
49	RETURN_AND_SET_ERRNO(session);
50}
51
52
53pid_t
54getpgid(pid_t process)
55{
56	pid_t group = _kern_process_info(process, GROUP_ID);
57
58	RETURN_AND_SET_ERRNO(group);
59}
60
61
62int
63setpgid(pid_t process, pid_t group)
64{
65	pid_t result = _kern_setpgid(process, group);
66	if (result >= 0)
67		return 0;
68
69	RETURN_AND_SET_ERRNO(result);
70}
71
72
73pid_t
74setpgrp(void)
75{
76	// setpgrp() never fails -- setpgid() fails when the process is a session
77	// leader, though.
78	pid_t result = _kern_setpgid(0, 0);
79	return result >= 0 ? result : getpgrp();
80}
81
82
83pid_t
84setsid(void)
85{
86	status_t status = _kern_setsid();
87
88	RETURN_AND_SET_ERRNO(status);
89}
90
91