Change dirname to readlink so it will use an absolute path.