From ba81243db79a879c52916703e67c6a52fc1264d306c172931e302d11f4fd9177 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Wed, 2 Jun 2021 13:25:33 +0000 Subject: [PATCH] avoid allocation OBS-URL: https://build.opensuse.org/package/show/Base:System/compat-usrmerge?expand=0&rev=12 --- convertfs | 8 +------- xmv.c | 11 +++++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/convertfs b/convertfs index 8126a2c..b2a8c27 100644 --- a/convertfs +++ b/convertfs @@ -105,10 +105,4 @@ done set +e echo "Run ldconfig." -ldconfig -r "$ROOT" - -#. $ROOT/etc/selinux/config -#if [ -n "$(command -v setfiles)" ] && [ "$SELINUX" != "disabled" ] && [ -f /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts ]; then -# echo "Fixing SELinux labels" -# setfiles -r $ROOT -p /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts $ROOT/sbin $ROOT/bin $ROOT/lib $ROOT/lib64 $ROOT/usr/lib $ROOT/usr/lib64 $ROOT/etc/ld.so.cache $ROOT/var/cache/ldconfig || : -#fi +ldconfig -r "$ROOT" || : diff --git a/xmv.c b/xmv.c index d29bae5..d3bc20d 100644 --- a/xmv.c +++ b/xmv.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifndef RENAME_EXCHANGE # define RENAME_EXCHANGE (1 << 1) @@ -74,13 +75,16 @@ int main(int argc, char** argv) return 1; } - /* Fallback for systems without renameat2 support */ - char *tmp; - r = asprintf(&tmp, "%s.XXXXXX", target); + // Fallback for systems without renameat2 support + puts("!!! WARNING: rename2 RENAME_EXCHANGE not supported !!!"); + puts("!!! fallback to unsafe rename !!!"); + char tmp[PATH_MAX]; + r = snprintf(tmp, sizeof(tmp), "%s.XXXXXX", target); if (r < 0) { perror("asprintf"); return 1; } + // not intended to be use in /tmp so good enough mktemp(tmp); r = renameat(AT_FDCWD, target, AT_FDCWD, tmp); @@ -88,7 +92,6 @@ int main(int argc, char** argv) r = renameat(AT_FDCWD, source, AT_FDCWD, target); if (!r) r = renameat(AT_FDCWD, tmp, AT_FDCWD, source); - free(tmp); if (r < 0) { perror("renameat");