Description: do check for utmp checking at the right time
 We were doing the check for whether we need to watch utmp from a
 thread cloned from that which will actually do the utmp watching.
 Move the check to the parent thread.
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Forwarded: yes
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/948623

Index: lxc-0.8.0~rc1/src/lxc/start.c
===================================================================
--- lxc-0.8.0~rc1.orig/src/lxc/start.c	2012-04-23 23:09:42.871940384 -0500
+++ lxc-0.8.0~rc1/src/lxc/start.c	2012-04-23 23:09:47.843940298 -0500
@@ -503,16 +503,12 @@
 	if (lxc_sync_barrier_parent(handler, LXC_SYNC_CONFIGURE))
 		return -1;
 
-	if (must_drop_cap_sys_boot()) {
+	if (handler->conf->need_utmp_watch) {
 		if (prctl(PR_CAPBSET_DROP, CAP_SYS_BOOT, 0, 0, 0)) {
 			SYSERROR("failed to remove CAP_SYS_BOOT capability");
 			return -1;
 		}
-		handler->conf->need_utmp_watch = 1;
 		DEBUG("Dropped cap_sys_boot\n");
-	} else {
-		DEBUG("Not dropping cap_sys_boot or watching utmp\n");
-		handler->conf->need_utmp_watch = 0;
 	}
 
 	/* Setup the container, ip, names, utsname, ... */
@@ -651,6 +647,14 @@
 	handler->ops = ops;
 	handler->data = data;
 
+	if (must_drop_cap_sys_boot()) {
+		handler->conf->need_utmp_watch = 1;
+		DEBUG("Dropping cap_sys_boot and watching utmp\n");
+	} else {
+		DEBUG("Not dropping cap_sys_boot or watching utmp\n");
+		handler->conf->need_utmp_watch = 0;
+	}
+
 	err = lxc_spawn(handler);
 	if (err) {
 		ERROR("failed to spawn '%s'", name);
