xref: /minix3/minix/lib/libc/sys/setpgid.c (revision 5dd8da10c5368f1f7c641252b24203c14ed8d051)
1433d6423SLionel Sambuc #include <sys/cdefs.h>
2433d6423SLionel Sambuc #include <lib.h>
3433d6423SLionel Sambuc #include "namespace.h"
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #include <string.h>
6433d6423SLionel Sambuc 
7433d6423SLionel Sambuc #include <unistd.h>
8433d6423SLionel Sambuc 
9433d6423SLionel Sambuc /*
10433d6423SLionel Sambuc  * "Smart" stub for now. This requires job control to be properly implemented.
11433d6423SLionel Sambuc  */
setpgid(pid_t pid,pid_t pgid)12433d6423SLionel Sambuc int setpgid(pid_t pid, pid_t pgid)
13433d6423SLionel Sambuc {
14*5dd8da10SDavid van Moolenbroek 	pid_t _pid, _pgid, cpid;
15433d6423SLionel Sambuc 
16433d6423SLionel Sambuc 	_pid = pid;
17433d6423SLionel Sambuc 	_pgid = pgid;
18433d6423SLionel Sambuc 
19433d6423SLionel Sambuc 	/* Who are we? */
20433d6423SLionel Sambuc 	cpid = getpid();
21433d6423SLionel Sambuc 
22433d6423SLionel Sambuc 	/* if zero, means current process. */
23433d6423SLionel Sambuc 	if (_pid == 0) {
24433d6423SLionel Sambuc 		_pid = cpid;
25433d6423SLionel Sambuc 	}
26433d6423SLionel Sambuc 
27433d6423SLionel Sambuc 	/* if zero, means given pid. */
28433d6423SLionel Sambuc 	if (_pgid == 0) {
29433d6423SLionel Sambuc 		_pgid = _pid;
30433d6423SLionel Sambuc 	}
31433d6423SLionel Sambuc 
32433d6423SLionel Sambuc 	/* right now we only support the equivalent of setsid(), which is
33433d6423SLionel Sambuc 	 * setpgid(0,0) */
34433d6423SLionel Sambuc 	if ((_pid != cpid) || (_pgid != cpid)) {
35433d6423SLionel Sambuc 	    errno = EINVAL;
36433d6423SLionel Sambuc 	    return -1;
37433d6423SLionel Sambuc 	}
38433d6423SLionel Sambuc 
39433d6423SLionel Sambuc 	if (setsid() == cpid) {
40433d6423SLionel Sambuc 		return 0;
41433d6423SLionel Sambuc 	} else {
42433d6423SLionel Sambuc 		return -1;
43433d6423SLionel Sambuc 	}
44433d6423SLionel Sambuc }
45