From 564d54be76a052ca55bdb551fe1cf329214b8095 Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Thu, 2 Dec 2021 17:01:37 +0100 Subject: [PATCH] Allow and default to relative paths for binaries executed --- CMakeLists.txt | 24 ++++++++++------- default-rsync.lua | 2 +- default-rsyncssh.lua | 2 +- flake.nix | 28 ++++++++++--------- lsyncd.c | 2 +- tests/setup.lua | 9 +++++++ tests/teardown.lua | 8 ++++++ tests/testlib.lua | 64 ++++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 113 insertions(+), 26 deletions(-) create mode 100644 tests/setup.lua create mode 100644 tests/teardown.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index 055af67..cece12b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,20 +86,26 @@ add_custom_target( manpage DEPENDS doc/manpage/lsyncd.1.txt ) +# create_symlink( ${CMAKE_SOURCE_DIR}/tests tests) +ADD_CUSTOM_TARGET(add_tests ALL + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/tests tests) + add_custom_target( tests COMMAND echo "Running the tests" COMMAND echo "Note you are expected to:" COMMAND echo " * have lua-posix installed" - COMMAND echo " * have a passwordless ssh access to localhost" - COMMAND ${LUA_EXECUTABLE} tests/schedule.lua - COMMAND ${LUA_EXECUTABLE} tests/l4rsyncdata.lua - COMMAND ${LUA_EXECUTABLE} tests/filter-rsync.lua - COMMAND ${LUA_EXECUTABLE} tests/exclude-rsync.lua - COMMAND ${LUA_EXECUTABLE} tests/exclude-rsyncssh.lua - COMMAND ${LUA_EXECUTABLE} tests/churn-rsync.lua - COMMAND ${LUA_EXECUTABLE} tests/churn-rsyncssh.lua - COMMAND ${LUA_EXECUTABLE} tests/churn-direct.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/setup.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/schedule.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/l4rsyncdata.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/filter-rsync.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/exclude-rsync.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/exclude-rsyncssh.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-rsync.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-rsyncssh.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-direct.lua + COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/teardown.lua COMMAND echo "Finished all successfull!" + DEPENDS add_tests ) # compiling and linking it all together diff --git a/default-rsync.lua b/default-rsync.lua index 106c58d..0b1c7df 100644 --- a/default-rsync.lua +++ b/default-rsync.lua @@ -682,7 +682,7 @@ rsync.exitcodes = default.rsyncExitCodes rsync.rsync = { -- The rsync binary to be called. - binary = '/usr/bin/rsync', + binary = 'rsync', links = true, times = true, protect_args = true diff --git a/default-rsyncssh.lua b/default-rsyncssh.lua index a82fec6..57f52dd 100644 --- a/default-rsyncssh.lua +++ b/default-rsyncssh.lua @@ -608,7 +608,7 @@ rsyncssh.ssh = { -- -- the binary called -- - binary = '/usr/bin/ssh', + binary = 'ssh', -- -- if set adds this key to ssh diff --git a/flake.nix b/flake.nix index 1dd4ad5..178de8f 100644 --- a/flake.nix +++ b/flake.nix @@ -13,39 +13,43 @@ gcc cmake glib + rsync + openssh ]; version = builtins.elemAt (builtins.match ''.*set\(.LSYNCD_VERSION ([0-9\.]*).*'' (builtins.substring 0 500 (builtins.readFile ./CMakeLists.txt))) 0; - # buildTypes = { - # lua5_2 = pkgs.lua5_2; - # lua5_3 = pkgs.lua5_3; - # }; + buildTypes = { + lua5_1 = [pkgs.lua5_1 pkgs.lua51Packages.luaposix pkgs.lua51Packages.penlight]; + lua5_2 = [pkgs.lua5_2 pkgs.lua52Packages.luaposix pkgs.lua52Packages.penlight]; + lua5_3 = [pkgs.lua5_3 pkgs.lua53Packages.luaposix pkgs.lua53Packages.penlight]; + lua5_4 = [pkgs.lua5_4 pkgs.lua54Packages.luaposix pkgs.lua54Packages.penlight]; + }; in let - mkLsync = luaPackage: pkgs.stdenv.mkDerivation ({ + mkLsync = luaPackages: pkgs.stdenv.mkDerivation ({ inherit version; name = "lsyncd"; src = ./.; # nativeBuildInputs = [ pkgs.qt5.wrapQtAppsHook ]; - buildInputs = defaultDeps ++ [luaPackage]; + buildInputs = defaultDeps ++ luaPackages; }); in { packages = { - lsyncd = mkLsync pkgs.lua5_3; - lsyncd_lua5_1 = mkLsync pkgs.lua5_1; - lsyncd_lua5_2 = mkLsync pkgs.lua5_2; - lsyncd_lua5_3 = mkLsync pkgs.lua5_3; - lsyncd_lua5_4 = mkLsync pkgs.lua5_4; + lsyncd = mkLsync buildTypes.lua5_3; + lsyncd_lua5_1 = mkLsync buildTypes.lua5_1; + lsyncd_lua5_2 = mkLsync buildTypes.lua5_2; + lsyncd_lua5_3 = mkLsync buildTypes.lua5_3; + lsyncd_lua5_4 = mkLsync buildTypes.lua5_4; }; defaultPackage = self.packages.${system}.lsyncd; devShell = pkgs.mkShell { - buildInputs = defaultDeps; + buildInputs = defaultDeps ++ buildTypes.lua5_3; }; } ); diff --git a/lsyncd.c b/lsyncd.c index 5ab21fd..7ca6ce8 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1278,7 +1278,7 @@ l_exec( lua_State *L ) } } - execv( binary, ( char ** ) argv ); + execvp( binary, ( char ** ) argv ); // in a sane world execv does not return! printlogf( diff --git a/tests/setup.lua b/tests/setup.lua new file mode 100644 index 0000000..e1b2c41 --- /dev/null +++ b/tests/setup.lua @@ -0,0 +1,9 @@ +-- a heavy duty test. +-- makes thousends of random changes to the source tree + +require( 'posix' ) + +dofile( 'tests/testlib.lua' ) +cwriteln( ' Start Testsuite ' ) + +startSshd() diff --git a/tests/teardown.lua b/tests/teardown.lua new file mode 100644 index 0000000..4dbc2e7 --- /dev/null +++ b/tests/teardown.lua @@ -0,0 +1,8 @@ +-- a heavy duty test. +-- makes thousends of random changes to the source tree + +require( 'posix' ) + +dofile( 'tests/testlib.lua' ) + +stopSshd() diff --git a/tests/testlib.lua b/tests/testlib.lua index 1b386e2..6255e03 100644 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -1,5 +1,8 @@ -- common testing environment posix = require( 'posix' ) +string = require( 'string' ) +path = require( 'pl.path' ) +stringx = require( 'pl.stringx' ) -- escape codes to colorize output on terminal local c1='\027[47;34m' @@ -90,13 +93,70 @@ function writefile return true end +function script_path() + -- local str = debug.getinfo(2, "S").source:sub(2) + -- return str:match("(.*/)") + return path.dirname(path.abspath(debug.getinfo(1).short_src)) + end + +-- +-- Starts test ssh server +-- +function startSshd() + -- local f = io.open(script_path() .. "ssh/sshd.pid", 'r') + + -- if f + -- then + -- return false + -- end + + cwriteln(arg[0]) + cwriteln(script_path() .. "ssh/sshd_config") + + local sshdPath = script_path() .. "/ssh/" + local f = io.open( sshdPath .. "sshd_config", 'w') + f:write([[ + Port 2468 + HostKey ]] .. sshdPath .. [[ssh_host_rsa_key + HostKey ]] .. sshdPath .. [[ssh_host_dsa_key + AuthorizedKeysFile ]] .. sshdPath .. [[authorized_keys + ChallengeResponseAuthentication no + UsePAM no + #Subsystem sftp /usr/lib/ssh/sftp-server + PidFile ]] .. sshdPath .. [[sshd.pid + ]]) + f:close( ) + local which = io.popen("which sshd") + local path = which:read("a") + local exePath = string.sub(path, 0, #path - 1 ) + -- local sshPath = which:read("a*") + + local pid = spawn(exePath, "-f", sshdPath .. "sshd_config") + cwriteln( 'spawned sshd server: ' .. pid) + + return true +end + +-- +-- Stop test ssh server +-- +function stopSshd() + local f = io.open(script_path() .. "/ssh/sshd.pid", 'r') + + if not f + then + return false + end + pid = stringx.strip(f:read("*a")) + posix.kill(tonumber(pid)) +end + -- -- Spawns a subprocess. -- -- Returns the processes pid. -- -function spawn -(...) +function spawn(...) args = { ... } cwriteln( 'spawning: ', table.concat( args, ' ' ) )