commit 69b331372defa1ef5ad455fe36869a2df4657a71
parent f620749ca029e88384b67d240c5a7999840cdc12
Author: ccx <ccx@te2000.cz>
Date: Sun, 14 Apr 2024 00:15:00 +0000
Fix safelink
Diffstat:
9 files changed, 42 insertions(+), 24 deletions(-)
diff --git a/files/safelink.c b/files/safelink.c
@@ -3,6 +3,7 @@
#include <stdbool.h> /* for bool */
#include <skalibs/strerr2.h>
+#include <skalibs/random.h>
#define PROG "safelink"
#define USAGE "safelink oldpath newpath"
@@ -70,14 +71,14 @@ char* opendir_nofollow(char *pathname, int *fd, bool create_dirs)
/* Close the parent directory and replace reference to it with the newly opened one. */
close(fd1);
fd1 = fd2;
- base = s1 + 1;
+ base = s1;
}
}
}
int main (int argc, char const *const *argv)
{
- if (argc != 2) {
+ if (argc != 3) {
strerr_dieusage(100, USAGE);
}
int old_fd, new_fd;
@@ -90,11 +91,28 @@ int main (int argc, char const *const *argv)
if(new_base[0] == 0) {
strerr_dief2x(100, "malformed path: ", argv[2]);
}
- if(linkat(old_fd, old_base, new_fd, new_base, 0) != 0) {
- strerr_diefu1sys(111, "linkat()");
+ if(linkat(old_fd, old_base, new_fd, new_base, 0) == 0) {
+ return 0; /* created hardlink at the correct location */
}
- return 0 ;
+ if(errno != EEXIST) {
+ strerr_diefu1sys(111, "linkat()");
+ }
+ /* file with such name already exists, so try again with different one and atomically replace */
+ char tmp_base[BUFLEN];
+ tmp_base[0] = '.';
+ tmp_base[1] = 't';
+ tmp_base[2] = 'm';
+ tmp_base[3] = 'p';
+ tmp_base[4] = '.';
+ random_name(&tmp_base[5], 58);
+ tmp_base[64] = 0;
+ if(linkat(old_fd, old_base, new_fd, tmp_base, 0) != 0) {
+ strerr_diefu2sys(111, "linkat() to temporary name: ", tmp_base);
+ }
+ if(renameat(new_fd, tmp_base, new_fd, new_base) != 0) {
+ strerr_diefu4sys(111, "renameat() from temporary name: ", tmp_base, " to:", new_base);
+ }
+ return 0;
}
-
/* vim: sw=2 sts=2 et
*/
diff --git a/packages/default.environment b/packages/default.environment
@@ -1,7 +1,7 @@
-#+system-config.0d7709cdb806a2bf93e44a21d9b3fdd0125ca2858ac48dae134c1d1ea9a06712
-#+system-config-rc.9c64236a510b6429edc0a4600bab519f7febcba35ce5e3f1820272aee8cf63d7
+#+system-config.9f0c181322daa13d75a25d8c83dca4d2a2300741ff8a4746a18e3171ae7ee08a
+#+system-config-rc.248385de9652321ea4963b527a2c507b577be2d5dc178d0ff059ba8e6ef3ecf1
#+system-config-scripts.67e57dfdf150bbd6e0b01d5ca3fa89f0547997a8adb2c12f7e4d67602acb161a
-#+system-config-init.65ad7b7612ca6804d834a72520268fe6caf8d27c350c834b31c321d2fe713542
+#+system-config-init.2238626b6956577a3f00b0ab29f02877f1d56007228af2646a3890bc26310638
#+system-config-zsh.7500a7c1af8c349cd87493d5f6e2fe5c31148b42d11103154ecca654e6326ba5
#+busybox.e60885fe93ee85c01831673bb29f0e62a64903f4ce3094e3dc35bc8ec8887ad9
#+gnu-make.782c9e6625fd7420e2cd38b847afed19db3b3844cae8a0426a0dbf73e10d78e5
@@ -27,7 +27,7 @@
#+confz.208d2a701777a5703ca126f9fee4220610a9fb2b5241c5850d66a92bc0e682b2
#+containers.f505d6ed0c843d085f79b90ed638dcb7473fe4602cfcba4f453c2a3f6eaa7421
#+fileset.a274be52a358efbef7f42628a36ff98464608ab67d3bd4382323d60f9b854697
-#+logincaps.2aa5206d6b16cf5d9630c8f74710e42c494ddf1c48b8c3ce3754fed66812e1bd
+#+logincaps.f3f26384f8863b902843817f9eed86bed677d15b0ac2f44099b4add67375f48c
#+snaprep.4f1281cfb76562b94e47b6c021584d870be9c2900bd8d52db40848f58b5f7812
#+curl.b82f818e85570a561ca20ca417adba2f1c3214ef5c3e01626c0a4aa099b90f0c
#+git.1839db7305bbee32d184adc0ece64d40ab58132d3c7749b426c4d680659bd4eb
@@ -40,4 +40,4 @@
#+applyuidgid-caps.25f0135c22be3d3dcd34e06378e41b98cdc5201319131e99da81ae2af1af7767
#+nosuid.0e8db424c6fe3c4f9543a126159dc59afc81fc28df33e5287121d28f71c574b5
#+spawn-pty.e94a519d34a637d5fe414c4ee679553a3d88379220a91fd829a81d4a92e87535
-#+safelink.2d92de9b612ee28903b199a7635db564e24f5ee31a0008bfa0cb16972bd46284-
\ No newline at end of file
+#+safelink.b5608f8fa5323d8da3360249d11c514def4c576fa0c0a625c2ca3ec13bcb66e7+
\ No newline at end of file
diff --git a/packages/logincaps b/packages/logincaps
@@ -4,7 +4,7 @@
#+pthbs-banginstall.0190099d7db974b8ac922bc571bb572989f6a7e1018400f466173a158a98224c
#+execline.c07cc6461a1750bbf91bc8da1bb6c44487b0c2d3e73512fb691f4b5a63160449
#+musl-cross-make.65f98305f5666435bf0c6b9ccedffae2179ff1b3286752756886f760cf7771d2
-#+safelink.2d92de9b612ee28903b199a7635db564e24f5ee31a0008bfa0cb16972bd46284
+#+safelink.b5608f8fa5323d8da3360249d11c514def4c576fa0c0a625c2ca3ec13bcb66e7
#@git:d95bcf921a3a10186fdc1aaf79e86ec29134a8c9:logincaps
: ${JOBS:=1}
@@ -46,7 +46,7 @@ cp -a login "$pkgdir/command/"
safelink_executable=$(command which safelink)
safelink_executable=$(realpath "$safelink_executable")
-sed -i "s|^safelink_executable=.*|'safelink_executable='$safelink_executable'|" "$pkgdir/command/link-to-container-inbox"
+sed -i "s|^safelink_executable=.*|safelink_executable='$safelink_executable'|" "$pkgdir/command/link-to-container-inbox"
cd "$pthbs_destdir/versions/$pthbs_package"
find -type d -o -print | awk -F/ '
diff --git a/packages/safelink b/packages/safelink
@@ -3,7 +3,7 @@
#+gnu-make.782c9e6625fd7420e2cd38b847afed19db3b3844cae8a0426a0dbf73e10d78e5
#+busybox.e60885fe93ee85c01831673bb29f0e62a64903f4ce3094e3dc35bc8ec8887ad9
#+skalibs.b3931b1ec501dfd4603e293b20d0db46cb7644cf99225e6175060852b34f365f
-#@sha256:f82f6eb160d3c155ee393fd8b9ca04fc9c387a3c6776926c92de0b185e840062:safelink.c
+#@sha256:4c8df9ba4d6a4a7e9042ef03e3dbf893636785f42e55391c4e4cefcb632b2467:safelink.c
name=safelink
check_static() {
diff --git a/packages/system-config b/packages/system-config
@@ -13,7 +13,7 @@
#+s6.601377d341f6ee04ca2bdcdaad42df0e04456f07206dd56ba36556bd13956a22
#+zsh.2ff36a2aed3e11c13386bad0938fa166a6824f8b03b238a97b2922bca3678b2c
#+system-config-scripts.67e57dfdf150bbd6e0b01d5ca3fa89f0547997a8adb2c12f7e4d67602acb161a
-#+logincaps.2aa5206d6b16cf5d9630c8f74710e42c494ddf1c48b8c3ce3754fed66812e1bd
+#+logincaps.f3f26384f8863b902843817f9eed86bed677d15b0ac2f44099b4add67375f48c
#@git:4843829dc4242a50d22bb08b7f12764cb5f7c057:system-config
def_prefix() {
diff --git a/packages/system-config-init b/packages/system-config-init
@@ -5,9 +5,9 @@
#+s6-portable-utils.4c31c00a77c0b995e5d5fc4b802707b47e39e5b930a0ca22141802682d9ce592
#+s6-linux-init.3c55d2440534aba76b2ed07fe4b33f82b8eb20372f5f0ebc9f539ebe6ebb8847
#+execline.c07cc6461a1750bbf91bc8da1bb6c44487b0c2d3e73512fb691f4b5a63160449
-#+system-config-rc.9c64236a510b6429edc0a4600bab519f7febcba35ce5e3f1820272aee8cf63d7
+#+system-config-rc.248385de9652321ea4963b527a2c507b577be2d5dc178d0ff059ba8e6ef3ecf1
-s6rcdb=/versions/system-config-rc.9c64236a510b6429edc0a4600bab519f7febcba35ce5e3f1820272aee8cf63d7/config/s6-rc-db
+s6rcdb=/versions/system-config-rc.248385de9652321ea4963b527a2c507b577be2d5dc178d0ff059ba8e6ef3ecf1/config/s6-rc-db
prefix=/versions/$pthbs_package
pkgdir="$pthbs_destdir/$prefix"
diff --git a/packages/system-config-rc b/packages/system-config-rc
@@ -3,7 +3,7 @@
#+busybox-diffutils.4f5a07b29246414b77a7d71b103263af8f1249d75ddcbd9864e00def3d6feded
#+s6-rc.8de8b5eb1d1b72185b4693b874cb5477b49997800e95ab5a3035fb957e588147
#+fileset.a274be52a358efbef7f42628a36ff98464608ab67d3bd4382323d60f9b854697
-#+system-config.0d7709cdb806a2bf93e44a21d9b3fdd0125ca2858ac48dae134c1d1ea9a06712
+#+system-config.9f0c181322daa13d75a25d8c83dca4d2a2300741ff8a4746a18e3171ae7ee08a
def_prefix() {
prefix=/versions/$pthbs_package
@@ -13,7 +13,7 @@ def_dest() {
}
def_dest
-src=/versions/system-config.0d7709cdb806a2bf93e44a21d9b3fdd0125ca2858ac48dae134c1d1ea9a06712/config/s6-rc-source
+src=/versions/system-config.9f0c181322daa13d75a25d8c83dca4d2a2300741ff8a4746a18e3171ae7ee08a/config/s6-rc-source
s6-rc-compile ./s6-rc-db "$src"
mkdir -p "$dest/config"
mv -v s6-rc-db "$dest/config/"
diff --git a/packages/userspace.environment b/packages/userspace.environment
@@ -22,7 +22,7 @@
#+confz.208d2a701777a5703ca126f9fee4220610a9fb2b5241c5850d66a92bc0e682b2
#+containers.f505d6ed0c843d085f79b90ed638dcb7473fe4602cfcba4f453c2a3f6eaa7421
#+fileset.a274be52a358efbef7f42628a36ff98464608ab67d3bd4382323d60f9b854697
-#+logincaps.2aa5206d6b16cf5d9630c8f74710e42c494ddf1c48b8c3ce3754fed66812e1bd
+#+logincaps.f3f26384f8863b902843817f9eed86bed677d15b0ac2f44099b4add67375f48c
#+snaprep.4f1281cfb76562b94e47b6c021584d870be9c2900bd8d52db40848f58b5f7812
#+curl.b82f818e85570a561ca20ca417adba2f1c3214ef5c3e01626c0a4aa099b90f0c
#+git.1839db7305bbee32d184adc0ece64d40ab58132d3c7749b426c4d680659bd4eb
@@ -35,4 +35,4 @@
#+applyuidgid-caps.25f0135c22be3d3dcd34e06378e41b98cdc5201319131e99da81ae2af1af7767
#+nosuid.0e8db424c6fe3c4f9543a126159dc59afc81fc28df33e5287121d28f71c574b5
#+spawn-pty.e94a519d34a637d5fe414c4ee679553a3d88379220a91fd829a81d4a92e87535
-#+safelink.2d92de9b612ee28903b199a7635db564e24f5ee31a0008bfa0cb16972bd46284-
\ No newline at end of file
+#+safelink.b5608f8fa5323d8da3360249d11c514def4c576fa0c0a625c2ca3ec13bcb66e7+
\ No newline at end of file
diff --git a/templates/pkg/logincaps b/templates/pkg/logincaps
@@ -23,7 +23,7 @@ cp -a login "$pkgdir/command/"
safelink_executable=$(command which safelink)
safelink_executable=$(realpath "$safelink_executable")
-sed -i "s|^safelink_executable=.*|'safelink_executable='$safelink_executable'|" "$pkgdir/command/link-to-container-inbox"
+sed -i "s|^safelink_executable=.*|safelink_executable='$safelink_executable'|" "$pkgdir/command/link-to-container-inbox"
{%- endblock %}
{% block genlinks_begin %}