Invalid handling of root dir

Cannot use dirname() here because kernel.root can contain relative path.