Stub for setpgid

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
This commit is contained in:
Lionel Sambuc 2014-04-24 13:39:50 +02:00
parent ac5b3e53d8
commit afe5cecd7f
4 changed files with 47 additions and 5 deletions

View file

@ -133,9 +133,7 @@ ssize_t read(int, void *, size_t);
#endif #endif
int rmdir(const char *); int rmdir(const char *);
int setgid(gid_t); int setgid(gid_t);
#if !defined(__minix)
int setpgid(pid_t, pid_t); int setpgid(pid_t, pid_t);
#endif /* !defined(__minix) */
pid_t setsid(void); pid_t setsid(void);
int setuid(uid_t); int setuid(uid_t);
unsigned int sleep(unsigned int); unsigned int sleep(unsigned int);
@ -270,9 +268,9 @@ int lockf(int, int, off_t);
ssize_t readlink(const char * __restrict, char * __restrict, size_t); ssize_t readlink(const char * __restrict, char * __restrict, size_t);
#endif #endif
void *sbrk(intptr_t); void *sbrk(intptr_t);
#if !defined(__minix)
/* XXX prototype wrong! */ /* XXX prototype wrong! */
int setpgrp(pid_t, pid_t); /* obsoleted by setpgid() */ int setpgrp(pid_t, pid_t); /* obsoleted by setpgid() */
#if !defined(__minix)
int setregid(gid_t, gid_t); int setregid(gid_t, gid_t);
int setreuid(uid_t, uid_t); int setreuid(uid_t, uid_t);
#endif /* !defined(__minix) */ #endif /* !defined(__minix) */

View file

@ -10,7 +10,7 @@
.PATH: ${ARCHDIR}/compat-43 ${.CURDIR}/compat-43 .PATH: ${ARCHDIR}/compat-43 ${.CURDIR}/compat-43
SRCS+= creat.c getdtablesize.c \ SRCS+= creat.c getdtablesize.c \
killpg.c \ killpg.c setpgrp.c \
.if !defined(AUDIT) .if !defined(AUDIT)
SRCS+= getwd.c SRCS+= getwd.c

View file

@ -22,7 +22,7 @@ SRCS+= accept.c access.c adjtime.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \
sync.c syscall.c sysuname.c truncate.c umask.c unlink.c write.c \ sync.c syscall.c sysuname.c truncate.c umask.c unlink.c write.c \
utimensat.c utimes.c futimes.c lutimes.c futimens.c \ utimensat.c utimes.c futimes.c lutimes.c futimens.c \
_exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c init.c \ _exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c init.c \
getrusage.c setrlimit.c getrusage.c setrlimit.c setpgid.c
# Minix specific syscalls / utils. # Minix specific syscalls / utils.
SRCS+= cprofile.c sprofile.c stack_utils.c _mcontext.c SRCS+= cprofile.c sprofile.c stack_utils.c _mcontext.c

View file

@ -0,0 +1,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, 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;
}
}