summaryrefslogtreecommitdiff
path: root/minix/lib/libc/sys/setpgid.c
blob: b724fa44c20537533c607ddd41906b47dbb30fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <sys/cdefs.h>
#include <lib.h>
#include "namespace.h"

#include <string.h>

#include <unistd.h>

/*
 * "Smart" stub for now. This requires job control to be properly implemented.
 */
int setpgid(pid_t pid, pid_t pgid)
{
	pid_t _pid, _pgid, cpid;

	_pid = pid;
	_pgid = pgid;

	/* Who are we? */
	cpid = getpid();

	/* if zero, means current process. */
	if (_pid == 0) {
		_pid = cpid;
	}

	/* if zero, means given pid. */
	if (_pgid == 0) {
		_pgid = _pid;
	}

	/* right now we only support the equivalent of setsid(), which is
	 * setpgid(0,0) */
	if ((_pid != cpid) || (_pgid != cpid)) {
	    errno = EINVAL;
	    return -1;
	}

	if (setsid() == cpid) {
		return 0;
	} else {
		return -1;
	}
}