]> Zhao Yanbai Git Server - minix.git/commitdiff
Stub for setpgid
authorLionel Sambuc <lionel@minix3.org>
Thu, 24 Apr 2014 11:39:50 +0000 (13:39 +0200)
committerLionel Sambuc <lionel@minix3.org>
Mon, 28 Jul 2014 15:05:24 +0000 (17:05 +0200)
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
lib/libc/compat-43/Makefile.inc
lib/libc/sys-minix/Makefile.inc
lib/libc/sys-minix/setpgid.c [new file with mode: 0644]

index 6ab39eb5690884ec9ce3d09c47b19cc133540e0a..9d13199f6c8aa73f05ed8e98f68452ada7fe328c 100644 (file)
@@ -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) */
index 1b3ff5c238ef2537142a872a39b285382ef3f995..00e0e8160e2b78b52d48609325e2867c0aca7e7b 100644 (file)
@@ -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
index 7805a9e68111f0615df8d6e290ab36bb8ac52301..4d3e0253ffefc8cb5693888046af8c6f556b5396 100644 (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 \
        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 (file)
index 0000000..b007ba5
--- /dev/null
@@ -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;
+       }
+}