On Tue, Jul 7, 2015 at 9:35 AM, Ludovic Courtès <l...@gnu.org> wrote: > David Thompson <dthomps...@worcester.edu> skribis: > >> From: David Thompson <da...@gnu.org> >> >> * guix/build/syscalls.scm (pivot-root): New procedure. >> * tests/syscalls.scm: Test it. > > [...] > >> +(test-assert "pivot-root" >> + (match (pipe) >> + ((in . out) >> + (match (clone (logior CLONE_NEWUSER CLONE_NEWNS)) >> + (0 >> + (close in) >> + (call-with-temporary-directory >> + (lambda (root) >> + (let ((put-old (string-append root "/real-root"))) >> + (mount "none" root "tmpfs") >> + (mkdir put-old) >> + (call-with-output-file (string-append root "/test") >> + (lambda (port) >> + (display "testing\n" port))) >> + (pivot-root root put-old) >> + ;; The test file should now be located inside the root >> directory. >> + (write (file-exists "/test") out) >> + (close out)))) >> + (primitive-exit 0)) >> + (pid >> + (close out) >> + (read in)))))) > > Shouldn’t it be: > > (file-exists? (string-append put-old "/test"))
No, because put-old contains the current system root directory. I wanted to test that the file I made in the temporary directory is now located in the new root file system. I hope this makes sense. > To be on the safe side, the last line should probably be: > > (eq? #t (read in)) > > Otherwise a return value of *unspecified* works as well. Good call. I had a typo ('file-exists' instead of 'file-exists?') that was making this test pass when it should've failed. That's bad "test driven development" on my part. ;) > Also, ‘waidpid’: > > (pid > (close out) > (let ((result (read in))) > (close in) > (and (zero? (status:exit-val (waitpid pid))) > (eq? #t result)))) > > OK with these changes. Fixed and pushed. Thanks! - Dave