Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Feb 2020 03:13:40 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r358255 - in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/lib 12/usr.sbin/cron/cron 12/usr.sbin/cron/lib
Message-ID:  <202002230313.01N3Dex8071796@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sun Feb 23 03:13:38 2020
New Revision: 358255
URL: https://svnweb.freebsd.org/changeset/base/358255

Log:
  MFC r357714-r357715: cron(8): rip out some legacy bits
  
  r357714: 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
  
  r357715: cron(8): rip out do_univ
  
  This was an old Dynix hack, the function is a NOP on FreeBSD. We have no
  need to retain this; Dynix was discontinued long ago.

Modified:
  stable/12/usr.sbin/cron/cron/compat.h
  stable/12/usr.sbin/cron/cron/do_command.c
  stable/12/usr.sbin/cron/cron/externs.h
  stable/12/usr.sbin/cron/cron/popen.c
  stable/12/usr.sbin/cron/lib/compat.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/usr.sbin/cron/cron/compat.h
  stable/11/usr.sbin/cron/cron/do_command.c
  stable/11/usr.sbin/cron/cron/externs.h
  stable/11/usr.sbin/cron/cron/popen.c
  stable/11/usr.sbin/cron/lib/compat.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/usr.sbin/cron/cron/compat.h
==============================================================================
--- stable/12/usr.sbin/cron/cron/compat.h	Sat Feb 22 23:36:10 2020	(r358254)
+++ stable/12/usr.sbin/cron/cron/compat.h	Sun Feb 23 03:13:38 2020	(r358255)
@@ -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: stable/12/usr.sbin/cron/cron/do_command.c
==============================================================================
--- stable/12/usr.sbin/cron/cron/do_command.c	Sat Feb 22 23:36:10 2020	(r358254)
+++ stable/12/usr.sbin/cron/cron/do_command.c	Sun Feb 23 03:13:38 2020	(r358255)
@@ -38,8 +38,7 @@ static const char rcsid[] =
 #endif
 
 
-static void		child_process(entry *, user *),
-			do_univ(user *);
+static void		child_process(entry *, user *);
 
 static WAIT_T		wait_on_child(PID_T, const char *);
 
@@ -56,9 +55,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:
@@ -220,13 +216,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)
@@ -279,12 +275,6 @@ child_process(e, u)
 		close(stdin_pipe[READ_PIPE]);
 		close(stdout_pipe[WRITE_PIPE]);
 
-		/* set our login universe.  Do this in the grandchild
-		 * so that the child can invoke /usr/lib/sendmail
-		 * without surprises.
-		 */
-		do_univ(u);
-
 # if defined(LOGIN_CAP)
 		/* Set user's entire context, but skip the environment
 		 * as cron provides a separate interface for this
@@ -311,24 +301,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)
@@ -626,42 +616,4 @@ wait_on_child(PID_T childpid, const char *name) {
 	Debug(DPROC, ("\n"))
 
 	return waiter;
-}
-
-
-static void
-do_univ(u)
-	user	*u;
-{
-#if defined(sequent)
-/* Dynix (Sequent) hack to put the user associated with
- * the passed user structure into the ATT universe if
- * necessary.  We have to dig the gecos info out of
- * the user's password entry to see if the magic
- * "universe(att)" string is present.
- */
-
-	struct	passwd	*p;
-	char	*s;
-	int	i;
-
-	p = getpwuid(u->uid);
-	(void) endpwent();
-
-	if (p == NULL)
-		return;
-
-	s = p->pw_gecos;
-
-	for (i = 0; i < 4; i++)
-	{
-		if ((s = strchr(s, ',')) == NULL)
-			return;
-		s++;
-	}
-	if (strcmp(s, "universe(att)"))
-		return;
-
-	(void) universe(U_ATT);
-#endif
 }

Modified: stable/12/usr.sbin/cron/cron/externs.h
==============================================================================
--- stable/12/usr.sbin/cron/cron/externs.h	Sat Feb 22 23:36:10 2020	(r358254)
+++ stable/12/usr.sbin/cron/cron/externs.h	Sun Feb 23 03:13:38 2020	(r358255)
@@ -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: stable/12/usr.sbin/cron/cron/popen.c
==============================================================================
--- stable/12/usr.sbin/cron/cron/popen.c	Sat Feb 22 23:36:10 2020	(r358254)
+++ stable/12/usr.sbin/cron/cron/popen.c	Sun Feb 23 03:13:38 2020	(r358255)
@@ -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: stable/12/usr.sbin/cron/lib/compat.c
==============================================================================
--- stable/12/usr.sbin/cron/lib/compat.c	Sat Feb 22 23:36:10 2020	(r358254)
+++ stable/12/usr.sbin/cron/lib/compat.c	Sun Feb 23 03:13:38 2020	(r358255)
@@ -35,18 +35,6 @@ static char rcsid[] = "$FreeBSD$";
 #include <paths.h>
 
 
-/* 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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002230313.01N3Dex8071796>