 +		}
 +
 +		if (setuid(0) != 0) {
-+			ERROR("could not set user id: ", strerror(errno));
++			ERROR("could not set user id: %s", strerror(errno));
 +			return -1;
 +		}
 +
 +		if (setgid(0) != 0) {
-+			ERROR("could not set group id: ", strerror(errno));
++			ERROR("could not set group id: %s", strerror(errno));
 +			return -1;
 +		}
 +
 +		if (setgroups(1, groups) != 0) {
-+			ERROR("could not set groups: ", strerror(errno));
++			ERROR("could not set groups: %s", strerror(errno));
 +			return -1;
 +		}
 +
- 		if (curdir && chdir(curdir))
- 			WARN("could not change directory to '%s'", curdir);
- 
++		if (curdir && chdir(curdir))
++			WARN("could not change directory to '%s'", curdir);
++
++		free(curdir);
++
+ 		if (my_args.argc) {
+ 			execvp(my_args.argv[0], my_args.argv);
+ 			SYSERROR("failed to exec '%s'", my_args.argv[0]);

 
 	ret = lxc_caps_init();
 	if (ret)
@@ -231,6 +239,33 @@
 			}
 		}
 
+		if (tty != 0) {
+			if((tty_fd = open(tty, O_RDWR)) == 0) {

Index: koding/temp/lxc-0.9.0~alpha2-0ubuntu1+b1~bzr1087/src/lxc/lxc_attach.c
===================================================================
--- koding.orig/temp/lxc-0.9.0~alpha2-0ubuntu1+b1~bzr1087/src/lxc/lxc_attach.c	2013-01-14 22:03:59.000000000 +0000
+++ koding/temp/lxc-0.9.0~alpha2-0ubuntu1+b1~bzr1087/src/lxc/lxc_attach.c	2013-02-11 00:08:15.000000000 +0000
@@ -29,6 +29,10 @@
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <utmp.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <grp.h>
 
 #include "attach.h"
 #include "commands.h"
@@ -53,6 +57,7 @@
 	{"arch", required_argument, 0, 'a'},
 	{"namespaces", required_argument, 0, 's'},
 	{"remount-sys-proc", no_argument, 0, 'R'},
