--- vzctl-3.0.22.org/src/lib/env.c	2008-03-11 10:34:54.000000000 +0100
+++ vzctl-3.0.22/src/lib/env.c	2008-03-12 13:53:51.000000000 +0100
@@ -307,7 +307,7 @@
 	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));
@@ -394,12 +394,31 @@
 	*/
 	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 ((mkfifo ("/var/log/init.fifo", 0600) == 0) || (errno == EEXIST)) {
+	    envp[2] = "CONSOLE=/var/log/init.fifo";
+	    
+	    if (!fork()) { // for 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 +434,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/scripts/Makefile.am	2008-03-11 10:34:54.000000000 +0100
+++ vzctl-3.0.22/scripts/Makefile.am	2008-03-12 11:51:16.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-12 13:38:03.000000000 +0100
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+use strict;
+use Errno qw (EAGAIN EINTR);
+
+my $terminate = 0;
+
+$SIG{TERM} = sub { $terminate = 1; };
+$SIG{INT} = $SIG{QUIT} = $SIG{PIPE} = 'IGNORE';
+
+$0 = 'init-logger';
+
+open (INIT_LOG, ">/var/log/init.log") ||
+    die "unable to open init log - $!";
+
+sub logdata {
+    my $data = shift;
+    syswrite (INIT_LOG, $data);
+}
+
+if (!open (FIFO, "</var/log/init.fifo")) {
+    logdata ("error: unable to open init fifo\n");
+    exit (-1);
+}
+
+
+while (1) {
+    my $buf;
+    my $len = sysread (FIFO, $buf, 4096);
+
+    # check for signals
+    if ($terminate) { 
+	if ($len > 0) {
+	    logdata ($buf);
+	}
+	last;
+    }
+
+    # read error
+    if (!defined ($len)) {
+	next if $! == EAGAIN || $! == EINTR;
+	log ("error: unable to read fifo - $!\n");
+	last;
+    }
+
+    # EOF - try later
+    if (!$len) {
+	sleep (1);
+	next;
+    }
+
+    logdata ($buf);
+}
+
+# make sure we have a LF
+logdata ("\n");
+
+close INIT_LOG;
+close FIFO;
+
+exit (0);
