phunix/minix/lib/libc/sys/setpgid.c
David van Moolenbroek 5dd8da10c5 libc: resolve minix clang warnings
Change-Id: If6c42f7346cc1b00b387ae8d3b4f0df3ffb0244f
2014-09-30 20:35:56 +00:00

45 lines
706 B
C

#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;
}
}