--- vzctl-3.0.22.org/src/lib/env.c	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/src/lib/env.c	2008-03-13 11:29:17.000000000 +0100
@@ -307,9 +307,10 @@
 	int fd, ret;
 	vps_res *res;
 	char *argv[] = {"init", "-z", "      ", NULL};
-	char *envp[] = {"HOME=/", "TERM=linux", NULL};
+	char *envp[] = {"HOME=/", "TERM=linux", NULL, NULL};
 
 	res = (vps_res *) data;
+
 	memset(&create_param, 0, sizeof(create_param));
 	create_param.iptables_mask = get_ipt_mask(res->env.ipt_mask);
 	logger(3, 0, "Set iptables mask %#10.8x", create_param.iptables_mask);
@@ -394,12 +395,37 @@
 	*/
 	if (read(wait_p, &ret, sizeof(ret)) != 0)
 		return 0;
-	if ((fd = open("/dev/null", O_RDWR)) != -1) {
-		dup2(fd, 0);
-		dup2(fd, 1);
-		dup2(fd, 2);
-	}
+
 	logger(10, 0, "Starting init");
+
+	if (((fd = open("/dev/null", O_RDWR)) != -1) && (fd == STDIN_FILENO)) {
+
+		dup2(fd, 1); // STDOUT = /dev/null
+		dup2(fd, 2); // STDERR = /dev/null
+	  
+		if (res->misc.initlog == 1) {
+			if ((mkfifo("/var/log/init.fifo", 0600) == 0) || 
+			    (errno == EEXIST)) {
+				envp[2] = "CONSOLE=/var/log/init.fifo";
+	    
+				if (!fork()) { // fork logging process
+					close(wait_p); close(err_p);
+					execl("/sbin/init-logger", NULL);
+					logger(-1, errno, "unable to exec logger");
+					exit(-1);
+				}
+				// redirect STDOUT/STDERR to fifo
+				close(STDOUT_FILENO); 
+				open("/var/log/init.fifo", O_WRONLY);
+				
+				close(STDERR_FILENO); 
+				dup2(STDOUT_FILENO, STDERR_FILENO);
+			} else {
+				logger(-1, errno, "unable to create init fifo");
+			}
+		}
+	}
+
 	execve("/sbin/init", argv, envp);
 	execve("/etc/init", argv, envp);
 	execve("/bin/init", argv, envp);
@@ -415,6 +441,16 @@
 {
 	int ret, pid;
 
+	char ildest[4096];
+
+	*ildest = 0;
+	strcat (ildest, res->fs.root);
+	strcat (ildest, "/sbin/init-logger");
+	if (cp_file (ildest, "/usr/lib/vzctl/scripts/init-logger") != 0) {
+		logger(-1, 0, "Unable to copy init-logger");
+		return VZ_RESOURCE_ERROR;
+	}
+
 	if ((ret = vz_chroot(res->fs.root)))
 		return ret;
 	if ((ret = vz_setluid(veid)))
--- vzctl-3.0.22.org/src/lib/config.c	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/src/lib/config.c	2008-03-13 11:08:47.000000000 +0100
@@ -56,6 +56,7 @@
 {"LOG_LEVEL",	NULL, PARAM_LOGLEVEL},
 {"LOGFILE",	NULL, PARAM_LOGFILE},
 {"VERBOSE",	NULL, PARAM_VERBOSE},
+{"INITLOG",	NULL, PARAM_INITLOG},
 
 {"IPTABLES",	NULL, PARAM_IPTABLES},
 /*	UB	*/
@@ -190,6 +191,8 @@
 {"cpuweight",	required_argument, NULL, PARAM_CPUWEIGHT},
 {"cpulimit",	required_argument, NULL, PARAM_CPULIMIT},
 {"cpus",	required_argument, NULL, PARAM_VCPUS},
+/*      misc param     */
+{"initlog",	required_argument, NULL, PARAM_INITLOG},
 /*	create param	*/
 {"onboot",	required_argument, NULL, PARAM_ONBOOT},
 {"setmode",	required_argument, NULL, PARAM_SETMODE},
@@ -1203,6 +1206,9 @@
 
 	ret = 0;
 	switch (conf->id) {
+	case PARAM_INITLOG:
+		ret = conf_store_yesno(conf_h, conf->name, misc->initlog);
+		break;
 	case PARAM_ONBOOT:
 		ret = conf_store_yesno(conf_h, conf->name, vps_p->opt.onboot);
 		break;
@@ -1797,6 +1803,9 @@
 	case PARAM_LOGGING:
 		ret = conf_parse_yesno(&vps_p->log.enable, val, 1);
 		break;
+	case PARAM_INITLOG:
+		ret = conf_parse_yesno(&vps_p->res.misc.initlog, val, 1);
+		break;
 	case PARAM_LOGLEVEL:
 		if (parse_int(val, &int_id))
 			break;
@@ -2616,6 +2625,7 @@
 	MERGE_LIST(userpw)
 	MERGE_STR(hostname)
 	MERGE_INT(wait);
+	MERGE_INT(initlog);
 }
 
 static void merge_dq(dq_param *dst, dq_param *src)
--- vzctl-3.0.22.org/scripts/Makefile.am	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/scripts/Makefile.am	2008-03-13 09:35:27.000000000 +0100
@@ -18,6 +18,7 @@
 include $(top_srcdir)/pathsubst.am
 
 vzlib_SCRIPTS = \
+	init-logger \
 	vps-create \
 	vps-functions \
 	vps-net_add \
--- vzctl-3.0.22.org/scripts/init-logger	1970-01-01 01:00:00.000000000 +0100
+++ vzctl-3.0.22/scripts/init-logger	2008-03-13 11:45:40.000000000 +0100
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# this file is copied from the openvz host system
+# do not change tis file - changes will be lost during the 
+# next container start
+
+logfile="/var/log/init.log";
+logfifo="/var/log/init.fifo";
+
+terminate=0
+
+trap "terminate=1" TERM
+
+trap "" PIPE INT QUIT HUP
+
+cd /
+
+echo "starting init logger" > $logfile
+
+while [ 1 ]; do
+
+    cat <$logfifo >>$logfile
+
+    if [ $terminate -eq 1 ]; then
+	break
+    fi
+
+    # EOF - try again
+    sleep 1
+
+done
+
+
+# make sure we have a LF
+echo >> $logfile
+
+exit 0
--- vzctl-3.0.22.org/etc/vz.conf	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/etc/vz.conf	2008-03-13 11:43:09.000000000 +0100
@@ -10,6 +10,9 @@
 LOG_LEVEL=0
 VERBOSE=0
 
+## log output of init process to $VE_ROOT/var/log/init.log
+INITLOG=no
+
 ## Disk quota parameters
 DISK_QUOTA=yes
 VZFASTBOOT=no
--- vzctl-3.0.22.org/include/res.h	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/include/res.h	2008-03-13 10:54:26.000000000 +0100
@@ -52,6 +52,7 @@
 	list_head_t searchdomain;
 	char *hostname;
 	int wait;
+	int initlog;
 } misc_param;
 
 struct mod_action;
--- vzctl-3.0.22.org/include/vzctl_param.h	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/include/vzctl_param.h	2008-03-13 10:57:48.000000000 +0100
@@ -131,6 +131,7 @@
 #define PARAM_NETIF_HOST_IFNAME	357
 #define PARAM_VERBOSE		358
 #define PARAM_IOPRIO		359
+#define PARAM_INITLOG		360
 
 #define PARAM_LINE		"e:p:f:t:i:l:k:a:b:n:x:h"
 #endif
--- vzctl-3.0.22.org/vzctl.spec	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/vzctl.spec	2008-03-13 11:48:10.000000000 +0100
@@ -184,6 +184,7 @@
 %attr(755,root,root) %{_pkglibdir}/scripts/vps-net_add
 %attr(755,root,root) %{_pkglibdir}/scripts/vps-net_del
 %attr(755,root,root) %{_pkglibdir}/scripts/vps-create
+%attr(755,root,root) %{_pkglibdir}/scripts/init-logger
 
 %changelog
 * Wed Jun 13 2007 Andy Shevchenko <andriy@asplinux.com.ua> - 3.0.17-1
--- vzctl-3.0.22.org/man/vps.conf.5	2008-03-13 09:35:27.000000000 +0100
+++ vzctl-3.0.22/man/vps.conf.5	2008-03-13 12:03:02.000000000 +0100
@@ -28,6 +28,11 @@
 Default is \fBno\fR, meaning the container will not be started
 if \fBONBOOT\fR parameter is omitted.
 Corresponds to the \fB--onboot\fR option.
+.IP \fBINITLOG\fR="\fByes\fR|\fBno\fR"
+If enabled init output is logged to /var/log/init.log. This is done by 
+starting init with CONSOLE=/var/log/init.fifo. An additional process started 
+inside the container (init-logger) reads the fifo and write results to /var/log/init.log.
+Corresponds to the \fB--initlog\fR option.
 .IP \fBOSTEMPLATE\fR="\fItmpl_name\fR"
 Corresponds to the \fB--ostemplate\fR option.
 .IP \fBVE_ROOT\fR="\fIdirectory\fR"
