Hi,
I found that OpenBSD setpgrp is not POSIX compliant, so I write test and make diff to fix issue. http://pubs.opengroup.org/onlinepubs/009695399/functions/setpgrp.html This change removes obsolete setpgrp, and fix /usr/src where it is used. I can compile userland and it works. Work to do: 1. This is my first diff and I don't know process how to fix man page, can someone advice me? 2. grep -R /usr/src/setpgrp shows that old way is used a few times but skipped by preprocessor directives. can someone advice me with source tree and practices? As some of the code is imported from elsewhere and cleaning those are probably not good idea if we are not forking here. Cleaning process itself is very straightforward. 3. This change break backward compatibility to old BSD code favor to POSIX, so it would be good to inform that fix: setpgrp(pid, pid) -> setpgid(pid, pid) NEW FILE: regress/lib/libc/setpgrp =================================================================== /* * Copyright (c) 2014 Matti Karnaattu <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <unistd.h> /* * POSIX.1 have System V style setpgrp calling convention that differs * what traditionally have been in BSD systems. POSIX.1 setpgrp takes * no arguments and puts the calling process in its on group like * setpgid(0, 0). */ int main(void) { return (int)(setpgrp() != setpgid(0, 0)); } =================================================================== Index: include/unistd.h =================================================================== RCS file: /OpenBSD/src/include/unistd.h,v retrieving revision 1.92 diff -u -p -u -p -r1.92 unistd.h --- include/unistd.h 1 Sep 2014 05:09:52 -0000 1.92 +++ include/unistd.h 16 Sep 2014 21:27:31 -0000 @@ -427,7 +427,6 @@ int nice(int); ssize_t readlink(const char * __restrict, char * __restrict, size_t) __attribute__ ((__bounded__(__string__,2,3))); int setkey(const char *); -int setpgrp(pid_t pid, pid_t pgrp); /* obsoleted by setpgid() */ int setregid(gid_t, gid_t); int setreuid(uid_t, uid_t); void swab(const void *, void *, size_t); @@ -464,6 +463,7 @@ void *sbrk(int); #if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420 int lockf(int, int, off_t); +int setpgrp(void); #endif #if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420 || __BSD_VISIBLE Index: lib/libc/compat-43/setpgrp.c =================================================================== RCS file: /OpenBSD/src/lib/libc/compat-43/setpgrp.c,v retrieving revision 1.6 diff -u -p -u -p -r1.6 setpgrp.c --- lib/libc/compat-43/setpgrp.c 8 Aug 2005 08:05:33 -0000 1.6 +++ lib/libc/compat-43/setpgrp.c 16 Sep 2014 21:27:32 -0000 @@ -32,7 +32,7 @@ #include <unistd.h> int -setpgrp(pid_t pid, pid_t pgid) +setpgrp(void) { - return(setpgid(pid, pgid)); + return(setpgid(0, 0)); } Index: regress/lib/libc/Makefile =================================================================== RCS file: /OpenBSD/src/regress/lib/libc/Makefile,v retrieving revision 1.43 diff -u -p -u -p -r1.43 Makefile --- regress/lib/libc/Makefile 3 Jul 2014 21:12:24 -0000 1.43 +++ regress/lib/libc/Makefile 16 Sep 2014 21:27:35 -0000 @@ -5,7 +5,7 @@ SUBDIR+= atexit basename cephes cxa-atex SUBDIR+= explicit_bzero fmemopen fnmatch fpclassify getcap getopt_long glob SUBDIR+= hsearch longjmp locale malloc mkstemp modf netdb open_memstream SUBDIR+= orientation popen printf -SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf +SUBDIR+= regex setjmp setjmp-signal setpgrp sigreturn sigsetjmp sprintf SUBDIR+= stdio_threading stpncpy strerror strtod strtol strtonum SUBDIR+= telldir time timingsafe vis Index: sbin/iked/proc.c =================================================================== RCS file: /OpenBSD/src/sbin/iked/proc.c,v retrieving revision 1.19 diff -u -p -u -p -r1.19 proc.c --- sbin/iked/proc.c 18 Aug 2014 09:43:02 -0000 1.19 +++ sbin/iked/proc.c 16 Sep 2014 21:27:38 -0000 @@ -352,7 +352,7 @@ proc_run(struct privsep *ps, struct priv fatal("proc_run: cannot fork"); case 0: /* Set the process group of the current process */ - setpgrp(0, getpid()); + setpgid(0, getpid()); break; default: return (pid); Index: usr.sbin/lpr/lpd/printjob.c =================================================================== RCS file: /OpenBSD/src/usr.sbin/lpr/lpd/printjob.c,v retrieving revision 1.52 diff -u -p -u -p -r1.52 printjob.c --- usr.sbin/lpr/lpd/printjob.c 7 Feb 2014 23:06:21 -0000 1.52 +++ usr.sbin/lpr/lpd/printjob.c 16 Sep 2014 21:27:45 -0000 @@ -153,7 +153,7 @@ printjob(void) (void)close(fd); } pid = getpid(); /* for use with lprm */ - setpgrp(0, pid); + setpgid(0, pid); /* we add SIGINT to the mask so abortpr() doesn't kill itself */ memset(&sa, 0, sizeof(sa)); Index: usr.sbin/rarpd/rarpd.c =================================================================== RCS file: /OpenBSD/src/usr.sbin/rarpd/rarpd.c,v retrieving revision 1.53 diff -u -p -u -p -r1.53 rarpd.c --- usr.sbin/rarpd/rarpd.c 6 Apr 2012 18:03:52 -0000 1.53 +++ usr.sbin/rarpd/rarpd.c 16 Sep 2014 21:27:46 -0000 @@ -170,7 +170,7 @@ main(int argc, char *argv[]) (void) close(f); } (void) chdir("/"); - (void) setpgrp(0, getpid()); + (void) setpgid(0, getpid()); devnull = open(_PATH_DEVNULL, O_RDWR); if (devnull >= 0) { (void) dup2(devnull, STDIN_FILENO); Index: usr.sbin/relayd/proc.c =================================================================== RCS file: /OpenBSD/src/usr.sbin/relayd/proc.c,v retrieving revision 1.16 diff -u -p -u -p -r1.16 proc.c --- usr.sbin/relayd/proc.c 18 Aug 2014 12:59:00 -0000 1.16 +++ usr.sbin/relayd/proc.c 16 Sep 2014 21:27:46 -0000 @@ -354,7 +354,7 @@ proc_run(struct privsep *ps, struct priv fatal("proc_run: cannot fork"); case 0: /* Set the process group of the current process */ - setpgrp(0, getpid()); + setpgid(0, getpid()); break; default: return (pid); Index: usr.sbin/snmpd/proc.c =================================================================== RCS file: /OpenBSD/src/usr.sbin/snmpd/proc.c,v retrieving revision 1.11 diff -u -p -u -p -r1.11 proc.c --- usr.sbin/snmpd/proc.c 18 Aug 2014 13:13:42 -0000 1.11 +++ usr.sbin/snmpd/proc.c 16 Sep 2014 21:27:46 -0000 @@ -352,7 +352,7 @@ proc_run(struct privsep *ps, struct priv fatal("proc_run: cannot fork"); case 0: /* Set the process group of the current process */ - setpgrp(0, getpid()); + setpgid(0, getpid()); break; default: return (pid);
