afe5cecd7f
This implements a near noop setpgid, unless the use is one equivalent to setsid, in which case it will behave as such. Also activates setpgrp, which is implemented in terms of setpgid. Change-Id: I84411cb1957351aa1d3985623cd9e69bdf6f8d4c
44 lines
711 B
C
44 lines
711 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, sid, 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;
|
|
}
|
|
}
|