From d3adf7d773b8a9c498c73c7defc337d9a62dcc52 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 12 Jul 2021 01:05:24 +0300 Subject: [PATCH] kiss: fix installation of files causing processes to die. This modifies pkg_install_files() to do atomic mv on each of the files. This prevents processes from crashing when the underlying shared library changes (but the inode stays the same). Closes #226 --- kiss | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kiss b/kiss index 2a72a4b..3487834 100755 --- a/kiss +++ b/kiss @@ -1085,7 +1085,23 @@ pkg_install_files() { # Skip directories as they're likely symlinks in this case. # Pure directories in manifests have a suffix of '/'. [ -d "$_file" ] || test "$1" "$_file" || { - cp -fP "$2/${file#/}" "$_file" + _file_tmp=$2/${file#/} + + # Copy the file to a temporary location so that later + # verification (after pkg_remove_files()) is possible. + # + # This duplication only occurs during the first + # invocation of pkg_install_files() - the second call + # will simply do the 'mv' call. + case $1 in -z) + cp -fP "$2/${file#/}" "$2/__f-$pid" + _file_tmp=$2/__f-$pid + esac + + # Atomically move the temporary file to the root + # filesystem. The running processes will either get + # the old file or the new one. + mv -f "$_file_tmp" "$_file" # Skip changing permissions of symlinks. This prevents # errors when the symlink exists prior to the target.