fs-util: introduce mkfifoat_atomic() helper
This commit is contained in:
parent
43231f00c2
commit
4fe3828c58
|
@ -435,6 +435,31 @@ int mkfifo_atomic(const char *path, mode_t mode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) {
|
||||||
|
_cleanup_free_ char *t = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(path);
|
||||||
|
|
||||||
|
if (path_is_absolute(path))
|
||||||
|
return mkfifo_atomic(path, mode);
|
||||||
|
|
||||||
|
/* We're only interested in the (random) filename. */
|
||||||
|
r = tempfn_random_child("", NULL, &t);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (mkfifoat(dirfd, t, mode) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (renameat(dirfd, t, dirfd, path) < 0) {
|
||||||
|
unlink_noerrno(t);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int get_files_in_directory(const char *path, char ***list) {
|
int get_files_in_directory(const char *path, char ***list) {
|
||||||
_cleanup_closedir_ DIR *d = NULL;
|
_cleanup_closedir_ DIR *d = NULL;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
|
|
|
@ -42,6 +42,7 @@ int symlink_idempotent(const char *from, const char *to);
|
||||||
int symlink_atomic(const char *from, const char *to);
|
int symlink_atomic(const char *from, const char *to);
|
||||||
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
|
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
|
||||||
int mkfifo_atomic(const char *path, mode_t mode);
|
int mkfifo_atomic(const char *path, mode_t mode);
|
||||||
|
int mkfifoat_atomic(int dir_fd, const char *path, mode_t mode);
|
||||||
|
|
||||||
int get_files_in_directory(const char *path, char ***list);
|
int get_files_in_directory(const char *path, char ***list);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue