From owner-svn-src-head@freebsd.org Mon Feb 10 02:40:24 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C432A228E1F; Mon, 10 Feb 2020 02:40:24 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48G9B04nd3z3LRv; Mon, 10 Feb 2020 02:40:24 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9FA2B182BD; Mon, 10 Feb 2020 02:40:24 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01A2eOwm031574; Mon, 10 Feb 2020 02:40:24 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01A2eNmH031570; Mon, 10 Feb 2020 02:40:23 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202002100240.01A2eNmH031570@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 10 Feb 2020 02:40:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357714 - in head/usr.sbin/cron: cron lib X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in head/usr.sbin/cron: cron lib X-SVN-Commit-Revision: 357714 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Feb 2020 02:40:24 -0000 Author: kevans Date: Mon Feb 10 02:40:23 2020 New Revision: 357714 URL: https://svnweb.freebsd.org/changeset/base/357714 Log: cron(8): convert vfork() usage to fork() vfork() is error-prone, and the usage here definitely grew to not be clearly OK given vfork-semantics; e.g. setusercontext(3) within the child. Rip out vfork() and the rest of the references to it. fork is heavier, but it's unclear that the difference will be all that obvious. Reported by: Andrew Gierth and sigsys@gmail.com Modified: head/usr.sbin/cron/cron/compat.h head/usr.sbin/cron/cron/do_command.c head/usr.sbin/cron/cron/externs.h head/usr.sbin/cron/cron/popen.c head/usr.sbin/cron/lib/compat.c Modified: head/usr.sbin/cron/cron/compat.h ============================================================================== --- head/usr.sbin/cron/cron/compat.h Mon Feb 10 01:34:19 2020 (r357713) +++ head/usr.sbin/cron/cron/compat.h Mon Feb 10 02:40:23 2020 (r357714) @@ -76,10 +76,6 @@ /*****************************************************************/ -#if !defined(BSD) && !defined(HPUX) && !defined(CONVEX) && !defined(__linux) -# define NEED_VFORK -#endif - #if (!defined(BSD) || (BSD < 198902)) && !defined(__linux) && \ !defined(IRIX) && !defined(NeXT) && !defined(HPUX) # define NEED_STRCASECMP Modified: head/usr.sbin/cron/cron/do_command.c ============================================================================== --- head/usr.sbin/cron/cron/do_command.c Mon Feb 10 01:34:19 2020 (r357713) +++ head/usr.sbin/cron/cron/do_command.c Mon Feb 10 02:40:23 2020 (r357714) @@ -58,9 +58,6 @@ do_command(e, u) /* fork to become asynchronous -- parent process is done immediately, * and continues to run the normal cron code, which means return to * tick(). the child and grandchild don't leave this function, alive. - * - * vfork() is unsuitable, since we have much to do, and the parent - * needs to be able to run off and fork other processes. */ switch ((pid = fork())) { case -1: @@ -222,13 +219,13 @@ child_process(e, u) /* fork again, this time so we can exec the user's command. */ - switch (jobpid = vfork()) { + switch (jobpid = fork()) { case -1: - log_it("CRON",getpid(),"error","can't vfork"); + log_it("CRON",getpid(),"error","can't fork"); exit(ERROR_EXIT); /*NOTREACHED*/ case 0: - Debug(DPROC, ("[%d] grandchild process Vfork()'ed\n", + Debug(DPROC, ("[%d] grandchild process fork()'ed\n", getpid())) if (e->uid == ROOT_UID) @@ -315,24 +312,24 @@ child_process(e, u) if (setgid(e->gid) != 0) { log_it(usernm, getpid(), "error", "setgid failed"); - exit(ERROR_EXIT); + _exit(ERROR_EXIT); } # if defined(BSD) if (initgroups(usernm, e->gid) != 0) { log_it(usernm, getpid(), "error", "initgroups failed"); - exit(ERROR_EXIT); + _exit(ERROR_EXIT); } # endif if (setlogin(usernm) != 0) { log_it(usernm, getpid(), "error", "setlogin failed"); - exit(ERROR_EXIT); + _exit(ERROR_EXIT); } if (setuid(e->uid) != 0) { log_it(usernm, getpid(), "error", "setuid failed"); - exit(ERROR_EXIT); + _exit(ERROR_EXIT); } /* we aren't root after this..*/ #if defined(LOGIN_CAP) Modified: head/usr.sbin/cron/cron/externs.h ============================================================================== --- head/usr.sbin/cron/cron/externs.h Mon Feb 10 01:34:19 2020 (r357713) +++ head/usr.sbin/cron/cron/externs.h Mon Feb 10 02:40:23 2020 (r357714) @@ -141,7 +141,3 @@ extern int getdtablesize(void); #ifdef NEED_SETENV extern int setenv(char *, char *, int); #endif - -#ifdef NEED_VFORK -extern PID_T vfork(void); -#endif Modified: head/usr.sbin/cron/cron/popen.c ============================================================================== --- head/usr.sbin/cron/cron/popen.c Mon Feb 10 01:34:19 2020 (r357713) +++ head/usr.sbin/cron/cron/popen.c Mon Feb 10 02:40:23 2020 (r357714) @@ -112,7 +112,7 @@ cron_popen(program, type, e, pidptr) #endif iop = NULL; - switch(pid = vfork()) { + switch(pid = fork()) { case -1: /* error */ (void)close(pdes[0]); (void)close(pdes[1]); Modified: head/usr.sbin/cron/lib/compat.c ============================================================================== --- head/usr.sbin/cron/lib/compat.c Mon Feb 10 01:34:19 2020 (r357713) +++ head/usr.sbin/cron/lib/compat.c Mon Feb 10 02:40:23 2020 (r357714) @@ -35,18 +35,6 @@ static char rcsid[] = "$FreeBSD$"; #include -/* the code does not depend on any of vfork's - * side-effects; it just uses it as a quick - * fork-and-exec. - */ -#ifdef NEED_VFORK -PID_T -vfork() { - return (fork()); -} -#endif - - #ifdef NEED_STRDUP char * strdup(str)