mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
fs-util: make mkfifo_atomic() just a shortcut for mkfifoat_atomic()
This commit is contained in:
parent
da9dd029a2
commit
4f477796f3
@ -484,47 +484,24 @@ int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mkfifo_atomic(const char *path, mode_t mode) {
|
||||
int mkfifoat_atomic(int atfd, const char *path, mode_t mode) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
|
||||
/* We're only interested in the (random) filename. */
|
||||
r = tempfn_random(path, NULL, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (mkfifo(t, mode) < 0)
|
||||
if (mkfifoat(atfd, t, mode) < 0)
|
||||
return -errno;
|
||||
|
||||
if (rename(t, path) < 0) {
|
||||
unlink_noerrno(t);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
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)
|
||||
r = RET_NERRNO(renameat(atfd, t, atfd, path));
|
||||
if (r < 0) {
|
||||
(void) unlinkat(atfd, t, 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;
|
||||
|
@ -63,8 +63,10 @@ static inline int symlink_atomic(const char *from, const char *to) {
|
||||
return symlinkat_atomic_full(from, AT_FDCWD, to, false);
|
||||
}
|
||||
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
|
||||
int mkfifo_atomic(const char *path, mode_t mode);
|
||||
int mkfifoat_atomic(int dir_fd, const char *path, mode_t mode);
|
||||
static inline int mkfifo_atomic(const char *path, mode_t mode) {
|
||||
return mkfifoat_atomic(AT_FDCWD, path, mode);
|
||||
}
|
||||
|
||||
int get_files_in_directory(const char *path, char ***list);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user