From afe5cecd7fd0860b48122c4898fc7f7e5aff93a0 Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Thu, 24 Apr 2014 13:39:50 +0200 Subject: [PATCH] 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 --- include/unistd.h | 4 +-- lib/libc/compat-43/Makefile.inc | 2 +- lib/libc/sys-minix/Makefile.inc | 2 +- lib/libc/sys-minix/setpgid.c | 44 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 lib/libc/sys-minix/setpgid.c diff --git a/include/unistd.h b/include/unistd.h index 6ab39eb56..9d13199f6 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -133,9 +133,7 @@ ssize_t read(int, void *, size_t); #endif int rmdir(const char *); int setgid(gid_t); -#if !defined(__minix) int setpgid(pid_t, pid_t); -#endif /* !defined(__minix) */ pid_t setsid(void); int setuid(uid_t); 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); #endif void *sbrk(intptr_t); -#if !defined(__minix) /* XXX prototype wrong! */ int setpgrp(pid_t, pid_t); /* obsoleted by setpgid() */ +#if !defined(__minix) int setregid(gid_t, gid_t); int setreuid(uid_t, uid_t); #endif /* !defined(__minix) */ diff --git a/lib/libc/compat-43/Makefile.inc b/lib/libc/compat-43/Makefile.inc index 1b3ff5c23..00e0e8160 100644 --- a/lib/libc/compat-43/Makefile.inc +++ b/lib/libc/compat-43/Makefile.inc @@ -10,7 +10,7 @@ .PATH: ${ARCHDIR}/compat-43 ${.CURDIR}/compat-43 SRCS+= creat.c getdtablesize.c \ - killpg.c \ + killpg.c setpgrp.c \ .if !defined(AUDIT) SRCS+= getwd.c diff --git a/lib/libc/sys-minix/Makefile.inc b/lib/libc/sys-minix/Makefile.inc index 7805a9e68..4d3e0253f 100644 --- a/lib/libc/sys-minix/Makefile.inc +++ b/lib/libc/sys-minix/Makefile.inc @@ -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 \ utimensat.c utimes.c futimes.c lutimes.c futimens.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. SRCS+= cprofile.c sprofile.c stack_utils.c _mcontext.c diff --git a/lib/libc/sys-minix/setpgid.c b/lib/libc/sys-minix/setpgid.c new file mode 100644 index 000000000..b007ba532 --- /dev/null +++ b/lib/libc/sys-minix/setpgid.c @@ -0,0 +1,44 @@ +#include +#include +#include "namespace.h" + +#include + +#include + +/* + * "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; + } +} -- 2.44.0