[systemd-devel] [PATCH 1/3] util: add symlink_atomic()
Shawn Landden
shawnlandden at gmail.com
Sat Aug 11 15:22:45 PDT 2012
From: Shawn Landen <shawnlandden at gmail.com>
unlike symlink_or_copy_atomic(), this function creates a symlink even if the
oldname and newname (from and to) are on differn't devices. (stat.st_dev)
---
src/shared/util.c | 19 +++++++++++++++++--
src/shared/util.h | 1 +
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index 946b7d5..876eb62 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4851,7 +4851,7 @@ finish:
return r;
}
-int symlink_or_copy_atomic(const char *from, const char *to) {
+static int symlink_atomic_raw(const char *from, const char *to, bool allow_copy) {
char *t, *x;
const char *fn;
size_t k;
@@ -4880,7 +4880,14 @@ int symlink_or_copy_atomic(const char *from, const char *to) {
*x = 0;
- r = symlink_or_copy(from, t);
+ if (allow_copy)
+ r = symlink_or_copy(from, t);
+ else {
+ r = symlink(from, t);
+ if (r < 0)
+ r = -errno;
+ }
+
if (r < 0) {
unlink(t);
free(t);
@@ -4898,6 +4905,14 @@ int symlink_or_copy_atomic(const char *from, const char *to) {
return r;
}
+int symlink_or_copy_atomic(const char *from, const char *to) {
+ return symlink_atomic_raw(from, to, true);
+}
+
+int symlink_atomic(const char *from, const char *to) {
+ return symlink_atomic_raw(from, to, false);
+}
+
bool display_is_local(const char *display) {
assert(display);
diff --git a/src/shared/util.h b/src/shared/util.h
index d5a48eb..24fa240 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -436,6 +436,7 @@ int vt_disallocate(const char *name);
int copy_file(const char *from, const char *to);
int symlink_or_copy(const char *from, const char *to);
int symlink_or_copy_atomic(const char *from, const char *to);
+int symlink_atomic(const char *from, const char *to);
int fchmod_umask(int fd, mode_t mode);
--
1.7.9.5
More information about the systemd-devel
mailing list