mirror of
https://github.com/systemd/systemd.git
synced 2025-02-03 17:47:28 +03:00
chase: Simplify chase_and_open() and chase_and_openat()
xopenat() now calls fd_reopen() if an empty path is specified, so let's make use of that to simplify the chase open helpers.
This commit is contained in:
parent
fedceeba2e
commit
708e88704b
@ -571,14 +571,13 @@ int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, i
|
||||
if (isempty(q))
|
||||
q = ".";
|
||||
|
||||
r = path_extract_filename(q, &fname);
|
||||
if (r < 0 && r != -EADDRNOTAVAIL)
|
||||
return r;
|
||||
if (!FLAGS_SET(chase_flags, CHASE_PARENT)) {
|
||||
r = path_extract_filename(q, &fname);
|
||||
if (r < 0 && r != -EADDRNOTAVAIL)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (FLAGS_SET(chase_flags, CHASE_PARENT) || r == -EADDRNOTAVAIL)
|
||||
r = fd_reopen(path_fd, open_flags);
|
||||
else
|
||||
r = xopenat(path_fd, fname, open_flags|O_NOFOLLOW, mode);
|
||||
r = xopenat(path_fd, strempty(fname), open_flags|O_NOFOLLOW, mode);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -773,14 +772,13 @@ int chase_and_openat(int dir_fd, const char *path, ChaseFlags chase_flags, int o
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = path_extract_filename(p, &fname);
|
||||
if (r < 0 && r != -EADDRNOTAVAIL)
|
||||
return r;
|
||||
if (!FLAGS_SET(chase_flags, CHASE_PARENT)) {
|
||||
r = path_extract_filename(p, &fname);
|
||||
if (r < 0 && r != -EADDRNOTAVAIL)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (FLAGS_SET(chase_flags, CHASE_PARENT) || r == -EADDRNOTAVAIL)
|
||||
r = fd_reopen(path_fd, open_flags);
|
||||
else
|
||||
r = xopenat(path_fd, fname, open_flags|O_NOFOLLOW, mode);
|
||||
r = xopenat(path_fd, strempty(fname), open_flags|O_NOFOLLOW, mode);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user