move setpgid() from libminijail to minijail0

Setting the process group is useful for minijail0, since it makes killing
minijail and its subprocesses easier. Move this functionality to minijail0,
which allows clients of libminijail to keep the child in their own process
group.

BUG=chromium:775367
TEST=`vm_launcher run` no longer gets SIGTTOU

Change-Id: I2b6b7fe59f50abc452d74e517d196c750d17453b
diff --git a/libminijail.c b/libminijail.c
index 9ae1c87..b6e2b1b 100644
--- a/libminijail.c
+++ b/libminijail.c
@@ -2434,23 +2434,6 @@
 		}
 	}
 
-	/*
-	 * Make the process group ID of this process equal to its PID.
-	 * In the non-interactive case (e.g. when the parent process is started
-	 * from init) this ensures the parent process and the jailed process
-	 * can be killed together.
-	 * When the parent process is started from the console this ensures
-	 * the call to setsid(2) in the jailed process succeeds.
-	 *
-	 * Don't fail on EPERM, since setpgid(0, 0) can only EPERM when
-	 * the process is already a process group leader.
-	 */
-	if (setpgid(0 /* use calling PID */, 0 /* make PGID = PID */)) {
-		if (errno != EPERM) {
-			pdie("setpgid(0, 0) failed");
-		}
-	}
-
 	if (use_preload) {
 		/*
 		 * Before we fork(2) and execve(2) the child process, we need
@@ -2727,6 +2710,9 @@
 	 * This prevents the jailed process from using the TIOCSTI ioctl
 	 * to push characters into the parent process terminal's input buffer,
 	 * therefore escaping the jail.
+	 *
+	 * Since it has just forked, the child will not be a process group
+	 * leader, and this call to setsid() should always succeed.
 	 */
 	if (isatty(STDIN_FILENO) || isatty(STDOUT_FILENO) ||
 	    isatty(STDERR_FILENO)) {