summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-20 18:44:21 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-25 18:38:00 +0900
commit797f6cc514b86097f0a51286b9f3ce568c03bf76 (patch)
tree232a760f3c6474700a7370af97bd7163215c6fc3 /src/basic
parent3d008416d610b0aaeaa5fb5a8a012f6dfc78a83e (diff)
downloadsystemd-797f6cc514b86097f0a51286b9f3ce568c03bf76.tar.gz
fs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/'
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/fs-util.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 3722eb638b..f8cd93800d 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -1000,7 +1000,7 @@ int parse_cifs_service(
int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) {
_cleanup_close_ int fd = -EBADF, parent_fd = -EBADF;
- _cleanup_free_ char *fname = NULL;
+ _cleanup_free_ char *fname = NULL, *parent = NULL;
int r;
/* Creates a directory with mkdirat() and then opens it, in the "most atomic" fashion we can
@@ -1015,19 +1015,13 @@ int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) {
/* Note that O_DIRECTORY|O_NOFOLLOW is implied, but we allow specifying it anyway. The following
* flags actually make sense to specify: O_CLOEXEC, O_EXCL, O_NOATIME, O_PATH */
- if (isempty(path))
- return -EINVAL;
-
- if (!filename_is_valid(path)) {
- _cleanup_free_ char *parent = NULL;
-
- /* If this is not a valid filename, it's a path. Let's open the parent directory then, so
- * that we can pin it, and operate below it. */
-
- r = path_extract_directory(path, &parent);
- if (r < 0)
+ /* If this is not a valid filename, it's a path. Let's open the parent directory then, so
+ * that we can pin it, and operate below it. */
+ r = path_extract_directory(path, &parent);
+ if (r < 0) {
+ if (!IN_SET(r, -EDESTADDRREQ, -EADDRNOTAVAIL))
return r;
-
+ } else {
r = path_extract_filename(path, &fname);
if (r < 0)
return r;