xref: /minix/minix/lib/libc/sys/setpgid.c (revision 9f988b79)
1 #include <sys/cdefs.h>
2 #include <lib.h>
3 #include "namespace.h"
4 
5 #include <string.h>
6 
7 #include <unistd.h>
8 
9 /*
10  * "Smart" stub for now. This requires job control to be properly implemented.
11  */
12 int setpgid(pid_t pid, pid_t pgid)
13 {
14 	pid_t _pid, _pgid, cpid;
15 
16 	_pid = pid;
17 	_pgid = pgid;
18 
19 	/* Who are we? */
20 	cpid = getpid();
21 
22 	/* if zero, means current process. */
23 	if (_pid == 0) {
24 		_pid = cpid;
25 	}
26 
27 	/* if zero, means given pid. */
28 	if (_pgid == 0) {
29 		_pgid = _pid;
30 	}
31 
32 	/* right now we only support the equivalent of setsid(), which is
33 	 * setpgid(0,0) */
34 	if ((_pid != cpid) || (_pgid != cpid)) {
35 	    errno = EINVAL;
36 	    return -1;
37 	}
38 
39 	if (setsid() == cpid) {
40 		return 0;
41 	} else {
42 		return -1;
43 	}
44 }
45