fs-util: replace symlink_atomic_full_label() by a flag to symlinkat_atomic_full()
More porting work to label_ops_pre()/label_ops_post() This also enables labelling of the /etc/localtime symlink in systemd-firstboot, which should address one small facet of #37857
This commit is contained in:
+18
-5
@@ -459,14 +459,14 @@ int symlinkat_idempotent(const char *from, int atfd, const char *to, bool make_r
|
||||
return 0;
|
||||
}
|
||||
|
||||
int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_relative) {
|
||||
_cleanup_free_ char *relpath = NULL, *t = NULL;
|
||||
int symlinkat_atomic_full(const char *from, int atfd, const char *to, SymlinkFlags flags) {
|
||||
int r;
|
||||
|
||||
assert(from);
|
||||
assert(to);
|
||||
|
||||
if (make_relative) {
|
||||
_cleanup_free_ char *relpath = NULL;
|
||||
if (FLAGS_SET(flags, SYMLINK_MAKE_RELATIVE)) {
|
||||
r = path_make_relative_parent(to, from, &relpath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -474,12 +474,25 @@ int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_
|
||||
from = relpath;
|
||||
}
|
||||
|
||||
_cleanup_free_ char *t = NULL;
|
||||
r = tempfn_random(to, NULL, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (symlinkat(from, atfd, t) < 0)
|
||||
return -errno;
|
||||
bool call_label_ops_post = false;
|
||||
if (FLAGS_SET(flags, SYMLINK_LABEL)) {
|
||||
r = label_ops_pre(atfd, to, S_IFLNK);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
call_label_ops_post = true;
|
||||
}
|
||||
|
||||
r = RET_NERRNO(symlinkat(from, atfd, t));
|
||||
if (call_label_ops_post)
|
||||
RET_GATHER(r, label_ops_post(atfd, t, /* created= */ r >= 0));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = RET_NERRNO(renameat(atfd, t, atfd, to));
|
||||
if (r < 0) {
|
||||
|
||||
+7
-2
@@ -48,9 +48,14 @@ static inline int symlink_idempotent(const char *from, const char *to, bool make
|
||||
return symlinkat_idempotent(from, AT_FDCWD, to, make_relative);
|
||||
}
|
||||
|
||||
int symlinkat_atomic_full(const char *from, int atfd, const char *to, bool make_relative);
|
||||
typedef enum SymlinkFlags {
|
||||
SYMLINK_MAKE_RELATIVE = 1 << 0,
|
||||
SYMLINK_LABEL = 1 << 1,
|
||||
} SymlinkFlags;
|
||||
|
||||
int symlinkat_atomic_full(const char *from, int atfd, const char *to, SymlinkFlags flags);
|
||||
static inline int symlink_atomic(const char *from, const char *to) {
|
||||
return symlinkat_atomic_full(from, AT_FDCWD, to, false);
|
||||
return symlinkat_atomic_full(from, AT_FDCWD, to, 0);
|
||||
}
|
||||
|
||||
int mknodat_atomic(int atfd, const char *path, mode_t mode, dev_t dev);
|
||||
|
||||
Reference in New Issue
Block a user