@@ -181,44 +181,40 @@ int main(int argc, char *argv[]) {
181181 add_path(m.src, m.dest, rootdir);
182182 }
183183
184− char path_buf[PATH_MAX];
185− snprintf(path_buf, sizeof(path_buf), "%s/tmp", rootdir);
186− mkdir(path_buf, ~0);
187− snprintf(path_buf, sizeof(path_buf), "%s/var", rootdir);
188−
189− // make sure nixdir exists
190− struct stat statbuf2;
191− if (stat(nixdir, &statbuf2) < 0) {
192− err_exit("stat(%s)", nixdir);
193− }
184+ // make sure nixdir exists
185+ struct stat statbuf2;
186+ if (stat(nixdir, &statbuf2) < 0) {
187+ err_exit("stat(%s)", nixdir);
188+ }
194189
195− // mount /nix to new namespace
196− snprintf(path_buf, sizeof(path_buf), "%s/nix", rootdir);
197− mkdir(path_buf, statbuf2.st_mode & ~S_IFMT);
198− if (mount(nixdir, path_buf, "none", MS_BIND | MS_REC, NULL) < 0) {
199− err_exit("mount(%s, %s)", nixdir, path_buf);
200− }
190+ char path_buf[PATH_MAX];
191+ // mount /nix to new namespace
192+ snprintf(path_buf, sizeof(path_buf), "%s/nix", rootdir);
193+ mkdir(path_buf, statbuf2.st_mode & ~S_IFMT);
194+ if (mount(nixdir, path_buf, "none", MS_BIND | MS_REC, NULL) < 0) {
195+ err_exit("mount(%s, %s)", nixdir, path_buf);
196+ }
201197
202− // fixes issue #1 where writing to /proc/self/gid_map fails
203− // see user_namespaces(7) for more documentation
204− int fd_setgroups = open("/proc/self/setgroups", O_WRONLY);
205− if (fd_setgroups > 0) {
206− write(fd_setgroups, "deny", 4);
207− }
198+ // fixes issue #1 where writing to /proc/self/gid_map fails
199+ // see user_namespaces(7) for more documentation
200+ int fd_setgroups = open("/proc/self/setgroups", O_WRONLY);
201+ if (fd_setgroups > 0) {
202+ write(fd_setgroups, "deny", 4);
203+ }
208204
209− // map the original uid/gid in the new ns
210− char map_buf[1024];
211− snprintf(map_buf, sizeof(map_buf), "%d %d 1", uid, uid);
212− update_map(map_buf, "/proc/self/uid_map");
213− snprintf(map_buf, sizeof(map_buf), "%d %d 1", gid, gid);
214− update_map(map_buf, "/proc/self/gid_map");
205+ // map the original uid/gid in the new ns
206+ char map_buf[1024];
207+ snprintf(map_buf, sizeof(map_buf), "%d %d 1", uid, uid);
208+ update_map(map_buf, "/proc/self/uid_map");
209+ snprintf(map_buf, sizeof(map_buf), "%d %d 1", gid, gid);
210+ update_map(map_buf, "/proc/self/gid_map");
215211
216− // chroot to rootdir
217− if (chroot(rootdir) < 0) {
218− err_exit("chroot(%s)", rootdir);
219− }
212+ // chroot to rootdir
213+ if (chroot(rootdir) < 0) {
214+ err_exit("chroot(%s)", rootdir);
215+ }
220216
221− chdir("/");
217+ chdir("/");
222218
223219 if (clear_env) clearenv();
224220 setenv("NIX_PATH", NIX_PATH, 1);
@@ -226,7 +222,7 @@ int main(int argc, char *argv[]) {
226222 setenv("PATH", ENV_PATH, 1);
227223
228224 for (list<struct SetEnv>::iterator it = envMappings.begin();
229− it != envMappings.end(); ++it) {
225+ it != envMappings.end(); ++it) {
230226 struct SetEnv e = *it;
231227 setenv(e.key.c_str(), e.value.c_str(), 1);
232228 }