summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-07-20 12:02:14 +0200
committerLennart Poettering <lennart@poettering.net>2018-07-23 13:38:18 +0200
commit0c462ea4ef6029b7974a052e44b6d1359a79953f (patch)
tree052160ef5889947498a7c87a773612f347ecb640 /src/basic
parentef8becfac5f1d8e0cfce69afd3aadffb330efb70 (diff)
downloadsystemd-0c462ea4ef6029b7974a052e44b6d1359a79953f.tar.gz
systemd-0c462ea4ef6029b7974a052e44b6d1359a79953f.tar.bz2
systemd-0c462ea4ef6029b7974a052e44b6d1359a79953f.zip
tree-wide: port various bits over to open_parent()
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/fileio.c20
-rw-r--r--src/basic/fs-util.c10
-rw-r--r--src/basic/mount-util.c8
3 files changed, 11 insertions, 27 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 9ff9118031..20d3f567c9 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1449,22 +1449,14 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
* which case "ret_path" will be returned as NULL. If not possible a the tempoary path name used is returned in
* "ret_path". Use link_tmpfile() below to rename the result after writing the file in full. */
- {
- _cleanup_free_ char *dn = NULL;
-
- dn = dirname_malloc(target);
- if (!dn)
- return -ENOMEM;
-
- fd = open(dn, O_TMPFILE|flags, 0640);
- if (fd >= 0) {
- *ret_path = NULL;
- return fd;
- }
-
- log_debug_errno(errno, "Failed to use O_TMPFILE on %s: %m", dn);
+ fd = open_parent(target, O_TMPFILE|flags, 0640);
+ if (fd >= 0) {
+ *ret_path = NULL;
+ return fd;
}
+ log_debug_errno(fd, "Failed to use O_TMPFILE for %s: %m", target);
+
r = tempfn_random(target, NULL, &tmp);
if (r < 0)
return r;
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 567f4af1ca..aca9921de7 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -1156,7 +1156,7 @@ int unlinkat_deallocate(int fd, const char *name, int flags) {
}
int fsync_directory_of_file(int fd) {
- _cleanup_free_ char *path = NULL, *dn = NULL;
+ _cleanup_free_ char *path = NULL;
_cleanup_close_ int dfd = -1;
int r;
@@ -1182,13 +1182,9 @@ int fsync_directory_of_file(int fd) {
if (!path_is_absolute(path))
return -EINVAL;
- dn = dirname_malloc(path);
- if (!dn)
- return -ENOMEM;
-
- dfd = open(dn, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+ dfd = open_parent(path, O_CLOEXEC, 0);
if (dfd < 0)
- return -errno;
+ return dfd;
if (fsync(dfd) < 0)
return -errno;
diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c
index ebe41a4c6c..54d911b095 100644
--- a/src/basic/mount-util.c
+++ b/src/basic/mount-util.c
@@ -261,7 +261,7 @@ fallback_fstat:
/* flags can be AT_SYMLINK_FOLLOW or 0 */
int path_is_mount_point(const char *t, const char *root, int flags) {
- _cleanup_free_ char *canonical = NULL, *parent = NULL;
+ _cleanup_free_ char *canonical = NULL;
_cleanup_close_ int fd = -1;
int r;
@@ -283,11 +283,7 @@ int path_is_mount_point(const char *t, const char *root, int flags) {
t = canonical;
}
- parent = dirname_malloc(t);
- if (!parent)
- return -ENOMEM;
-
- fd = openat(AT_FDCWD, parent, O_DIRECTORY|O_CLOEXEC|O_PATH);
+ fd = open_parent(t, O_PATH|O_CLOEXEC, 0);
if (fd < 0)
return -errno;