chdir(2): unspaghettify a bit...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2025-10-31 13:56:45 -04:00
commit 4e9654c2bb

View file

@ -558,26 +558,19 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
struct path path; struct path path;
int error; int error;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
struct filename *name = getname(filename); CLASS(filename, name)(filename);
retry: retry:
error = filename_lookup(AT_FDCWD, name, lookup_flags, &path, NULL); error = filename_lookup(AT_FDCWD, name, lookup_flags, &path, NULL);
if (error) if (!error) {
goto out; error = path_permission(&path, MAY_EXEC | MAY_CHDIR);
if (!error)
error = path_permission(&path, MAY_EXEC | MAY_CHDIR); set_fs_pwd(current->fs, &path);
if (error) path_put(&path);
goto dput_and_out; if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
set_fs_pwd(current->fs, &path); goto retry;
}
dput_and_out:
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
} }
out:
putname(name);
return error; return error;
} }