From: Frantisek Sumsal Date: Tue, 26 May 2020 10:57:29 +0000 (+0200) Subject: test: make the systemd-run calls synchronous X-Git-Tag: v246-rc1~277 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8441ff688636dba5e458fb5e95fef1e817f79349;p=thirdparty%2Fsystemd.git test: make the systemd-run calls synchronous Otherwise we might be checking results of such calls before they even finish, causing nasty races like: ``` [ 15.656530] testsuite-43.sh[303]: + su testuser -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh systemd-run --user --unit=test-unprotected-home -P touch /home/testuser/works.txt ... [ 15.757744] testsuite-43.sh[324]: Running as unit: test-unprotected-home.service [ 15.775611] systemd[296]: Started /usr/bin/touch /home/testuser/works.txt. [ 15.783597] testsuite-43.sh[303]: + test -e /home/testuser/works.txt [ 15.787542] systemd[296]: test-unprotected-home.service: Succeeded. ... [ 15.787684] systemd[1]: Received SIGCHLD from PID 303 (bash). [ 15.787790] systemd[1]: Child 303 (bash) died (code=exited, status=1/FAILURE) [ 15.787881] systemd[1]: testsuite-43.service: Child 303 belongs to testsuite-43.service. [ 15.788040] systemd[1]: testsuite-43.service: Main process exited, code=exited, status=1/FAILURE [ 15.788224] systemd[1]: testsuite-43.service: Failed with result 'exit-code'. [ 15.788333] systemd[1]: testsuite-43.service: Service will not restart (restart setting) [ 15.788421] systemd[1]: testsuite-43.service: Changed start -> failed [ 15.788790] systemd[1]: testsuite-43.service: Job 160 testsuite-43.service/start finished, result=failed [ 15.788995] systemd[1]: Failed to start testsuite-43.service. ``` --- diff --git a/test/units/testsuite-43.sh b/test/units/testsuite-43.sh index ff94ad4d818..ec84868a212 100755 --- a/test/units/testsuite-43.sh +++ b/test/units/testsuite-43.sh @@ -10,10 +10,10 @@ runas() { su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@" } -runas testuser systemd-run --user --unit=test-private-users \ +runas testuser systemd-run --wait --user --unit=test-private-users \ -p PrivateUsers=yes -P echo hello -runas testuser systemd-run --user --unit=test-private-tmp-innerfile \ +runas testuser systemd-run --wait --user --unit=test-private-tmp-innerfile \ -p PrivateUsers=yes -p PrivateTmp=yes \ -P touch /tmp/innerfile.txt # File should not exist outside the job's tmp directory. @@ -21,17 +21,17 @@ test ! -e /tmp/innerfile.txt touch /tmp/outerfile.txt # File should not appear in unit's private tmp. -runas testuser systemd-run --user --unit=test-private-tmp-outerfile \ +runas testuser systemd-run --wait --user --unit=test-private-tmp-outerfile \ -p PrivateUsers=yes -p PrivateTmp=yes \ -P test ! -e /tmp/outerfile.txt # Confirm that creating a file in home works -runas testuser systemd-run --user --unit=test-unprotected-home \ +runas testuser systemd-run --wait --user --unit=test-unprotected-home \ -P touch /home/testuser/works.txt test -e /home/testuser/works.txt # Confirm that creating a file in home is blocked under read-only -runas testuser systemd-run --user --unit=test-protect-home-read-only \ +runas testuser systemd-run --wait --user --unit=test-protect-home-read-only \ -p PrivateUsers=yes -p ProtectHome=read-only \ -P bash -c ' test -e /home/testuser/works.txt @@ -40,12 +40,12 @@ runas testuser systemd-run --user --unit=test-protect-home-read-only \ test ! -e /home/testuser/blocked.txt # Check that tmpfs hides the whole directory -runas testuser systemd-run --user --unit=test-protect-home-tmpfs \ +runas testuser systemd-run --wait --user --unit=test-protect-home-tmpfs \ -p PrivateUsers=yes -p ProtectHome=tmpfs \ -P test ! -e /home/testuser # Confirm that home, /root, and /run/user are inaccessible under "yes" -runas testuser systemd-run --user --unit=test-protect-home-yes \ +runas testuser systemd-run --wait --user --unit=test-protect-home-yes \ -p PrivateUsers=yes -p ProtectHome=yes \ -P bash -c ' test "$(stat -c %a /home)" = "0" @@ -57,7 +57,7 @@ runas testuser systemd-run --user --unit=test-protect-home-yes \ # namespace (no CAP_SETGID in the parent namespace to write the additional # mapping of the user supplied group and thus cannot change groups to an # unmapped group ID) -! runas testuser systemd-run --user --unit=test-group-fail \ +! runas testuser systemd-run --wait --user --unit=test-group-fail \ -p PrivateUsers=yes -p Group=daemon \ -P true