1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-13 17:18:18 +03:00

fs-util: add mknodat_atomic()

This commit is contained in:
Lennart Poettering 2022-09-16 12:45:02 +01:00
parent 4f477796f3
commit 497ca785aa
2 changed files with 12 additions and 6 deletions

View File

@ -463,7 +463,7 @@ int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_
return 0;
}
int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
int mknodat_atomic(int atfd, const char *path, mode_t mode, dev_t dev) {
_cleanup_free_ char *t = NULL;
int r;
@ -473,12 +473,13 @@ int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
if (r < 0)
return r;
if (mknod(t, mode, dev) < 0)
if (mknodat(atfd, t, mode, dev) < 0)
return -errno;
if (rename(t, path) < 0) {
unlink_noerrno(t);
return -errno;
r = RET_NERRNO(renameat(atfd, t, atfd, path));
if (r < 0) {
(void) unlinkat(atfd, t, 0);
return r;
}
return 0;

View File

@ -62,7 +62,12 @@ int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_
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 mknodat_atomic(int atfd, const char *path, mode_t mode, dev_t dev);
static inline int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
return mknodat_atomic(AT_FDCWD, path, mode, dev);
}
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);