Merge pull request #1834 from filbranden/testexecute2

test-execute: Fix systemd escaping and shell issues (v2)
This commit is contained in:
Lennart Poettering 2015-11-10 19:49:51 +01:00
commit b95292a152
37 changed files with 52 additions and 35 deletions

View file

@ -2,5 +2,6 @@
Description=Test for CapabilityBoundingSet Description=Test for CapabilityBoundingSet
[Service] [Service]
ExecStart=/bin/sh -c 'c=$(capsh --print | grep "Bounding set " | grep "cap_chown"); echo $c; exit $(test -z $c)' ExecStart=/bin/sh -x -c 'c=$$(capsh --print | grep "^Bounding set .*cap_chown"); test -z "$$c"'
Type=oneshot
CapabilityBoundingSet=~CAP_CHOWN CapabilityBoundingSet=~CAP_CHOWN

View file

@ -2,6 +2,7 @@
Description=Test for CapabilityBoundingSet Description=Test for CapabilityBoundingSet
[Service] [Service]
ExecStart=/bin/sh -c 'c=$(capsh --print | grep "Bounding set " | cut -f 2 -d "="); echo $c; exit $(test $c = "cap_chown,cap_fowner,cap_kill")' ExecStart=/bin/sh -x -c 'c=$$(capsh --print | grep "Bounding set "); test "$$c" = "Bounding set =cap_chown,cap_fowner,cap_kill"'
Type=oneshot
CapabilityBoundingSet=CAP_FOWNER CapabilityBoundingSet=CAP_FOWNER
CapabilityBoundingSet=CAP_KILL CAP_CHOWN CapabilityBoundingSet=CAP_KILL CAP_CHOWN

View file

@ -2,6 +2,7 @@
Description=Test for CapabilityBoundingSet Description=Test for CapabilityBoundingSet
[Service] [Service]
ExecStart=/bin/sh -c 'c=$(capsh --print | grep "Bounding set " | cut -f 2 -d "="); echo $c; exit $(test -z $c)' ExecStart=/bin/sh -x -c 'c=$$(capsh --print | grep "Bounding set "); test "$$c" = "Bounding set ="'
Type=oneshot
CapabilityBoundingSet=CAP_FOWNER CAP_KILL CapabilityBoundingSet=CAP_FOWNER CAP_KILL
CapabilityBoundingSet= CapabilityBoundingSet=

View file

@ -2,5 +2,6 @@
Description=Test for CapabilityBoundingSet Description=Test for CapabilityBoundingSet
[Service] [Service]
ExecStart=/bin/sh -c 'c=$(capsh --print | grep "Bounding set " | cut -f 2 -d "="); echo $c; exit $(test $c = "cap_fowner,cap_kill")' ExecStart=/bin/sh -x -c 'c=$$(capsh --print | grep "Bounding set "); test "$$c" = "Bounding set =cap_fowner,cap_kill"'
Type=oneshot
CapabilityBoundingSet=CAP_FOWNER CAP_KILL CapabilityBoundingSet=CAP_FOWNER CAP_KILL

View file

@ -2,6 +2,7 @@
Description=Test for Environment Description=Test for Environment
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test ! "$VAR1" = "word1 word2") && $(test ! "$VAR2" = word3) && $(test ! "$VAR3" = \'$word 5 6\')' ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset"'
Type=oneshot
Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6" Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
Environment= Environment=

View file

@ -2,6 +2,7 @@
Description=Test for Environment Description=Test for Environment
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test "$VAR1" = "word1 word2") && $(test "$VAR2" = word3) && $(test "$VAR3" = foobar)' ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = foobar'
Type=oneshot
Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6" Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
Environment="VAR3=foobar" Environment="VAR3=foobar"

View file

@ -2,5 +2,6 @@
Description=Test for Environment Description=Test for Environment
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test "$VAR1" = "word1 word2") && $(test "$VAR2" = word3) && $(test "$VAR3" = \'$word 5 6\')' ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
Type=oneshot
Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6" Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"

View file

@ -2,6 +2,6 @@
Description=Test for EnvironmentFile Description=Test for EnvironmentFile
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test "$VAR1" = "word1 word2") && $(test "$VAR2" = word3) && $(test "$VAR3" = \'$word 5 6\')' ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
Type=oneshot Type=oneshot
EnvironmentFile=/tmp/test-exec_environmentfile.conf EnvironmentFile=/tmp/test-exec_environmentfile.conf

View file

@ -2,5 +2,6 @@
Description=Test for Group Description=Test for Group
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test $(id -n -g) = nobody)' ExecStart=/bin/sh -x -c 'test "$$(id -n -g)" = "nobody"'
Type=oneshot
Group=nobody Group=nobody

View file

@ -2,6 +2,6 @@
Description=Test for IgnoreSIGPIPE=no Description=Test for IgnoreSIGPIPE=no
[Service] [Service]
ExecStart=/bin/sh -c 'kill -PIPE 0' ExecStart=/bin/sh -x -c 'kill -PIPE 0'
Type=oneshot Type=oneshot
IgnoreSIGPIPE=no IgnoreSIGPIPE=no

View file

@ -2,6 +2,6 @@
Description=Test for IgnoreSIGPIPE=yes Description=Test for IgnoreSIGPIPE=yes
[Service] [Service]
ExecStart=/bin/sh -c 'kill -PIPE 0' ExecStart=/bin/sh -x -c 'kill -PIPE 0'
Type=oneshot Type=oneshot
IgnoreSIGPIPE=yes IgnoreSIGPIPE=yes

View file

@ -2,6 +2,6 @@
Description=Test for IOSchedulingClass=best-effort Description=Test for IOSchedulingClass=best-effort
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == best-effort* ]]' ExecStart=/bin/sh -x -c 'c=$$(LC_ALL=C ionice); test "$${c%%:*}" = "best-effort"'
Type=oneshot Type=oneshot
IOSchedulingClass=best-effort IOSchedulingClass=best-effort

View file

@ -2,6 +2,6 @@
Description=Test for IOSchedulingClass=idle Description=Test for IOSchedulingClass=idle
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == idle* ]]' ExecStart=/bin/sh -x -c 'c=$$(LC_ALL=C ionice); test "$${c%%:*}" = "idle"'
Type=oneshot Type=oneshot
IOSchedulingClass=idle IOSchedulingClass=idle

View file

@ -2,6 +2,6 @@
Description=Test for IOSchedulingClass=none Description=Test for IOSchedulingClass=none
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == none* ]]' ExecStart=/bin/sh -x -c 'c=$$(LC_ALL=C ionice); test "$${c%%:*}" = "none"'
Type=oneshot Type=oneshot
IOSchedulingClass=none IOSchedulingClass=none

View file

@ -2,6 +2,6 @@
Description=Test for IOSchedulingClass=realtime Description=Test for IOSchedulingClass=realtime
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(ionice); echo $c; [[ "$c" == realtime* ]]' ExecStart=/bin/sh -x -c 'c=$$(LC_ALL=C ionice); test "$${c%%:*}" = "realtime"'
Type=oneshot Type=oneshot
IOSchedulingClass=realtime IOSchedulingClass=realtime

View file

@ -2,6 +2,6 @@
Description=Test for OOMScoreAdjust Description=Test for OOMScoreAdjust
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(cat /proc/self/oom_score_adj); echo $c; exit $(test $c -eq -100)' ExecStart=/bin/sh -x -c 'c=$$(cat /proc/self/oom_score_adj); test "$$c" -eq -100'
OOMScoreAdjust=-100
Type=oneshot Type=oneshot
OOMScoreAdjust=-100

View file

@ -2,6 +2,6 @@
Description=Test for OOMScoreAdjust Description=Test for OOMScoreAdjust
[Service] [Service]
ExecStart=/bin/bash -c 'c=$(cat /proc/self/oom_score_adj); echo $c; exit $(test $c -eq 100)' ExecStart=/bin/sh -x -c 'c=$$(cat /proc/self/oom_score_adj); test "$$c" -eq 100'
OOMScoreAdjust=100
Type=oneshot Type=oneshot
OOMScoreAdjust=100

View file

@ -2,6 +2,6 @@
Description=Test for Personality=s390 Description=Test for Personality=s390
[Service] [Service]
ExecStart=/bin/sh -c 'echo $(uname -m); exit $(test $(uname -m) = "s390")' ExecStart=/bin/sh -x -c 'c=$$(uname -m); test "$$c" = "s390"'
Type=oneshot Type=oneshot
Personality=s390 Personality=s390

View file

@ -2,6 +2,6 @@
Description=Test for Personality=x86-64 Description=Test for Personality=x86-64
[Service] [Service]
ExecStart=/bin/sh -c 'echo $(uname -m); exit $(test $(uname -m) = "x86_64")' ExecStart=/bin/sh -x -c 'c=$$(uname -m); test "$$c" = "x86_64"'
Type=oneshot Type=oneshot
Personality=x86-64 Personality=x86-64

View file

@ -2,6 +2,6 @@
Description=Test for Personality=x86 Description=Test for Personality=x86
[Service] [Service]
ExecStart=/bin/sh -c 'echo $(uname -m); exit $(test $(uname -m) = "i686")' ExecStart=/bin/sh -x -c 'c=$$(uname -m); test "$$c" = "i686"'
Type=oneshot Type=oneshot
Personality=x86 Personality=x86

View file

@ -2,6 +2,6 @@
Description=Test for PrivateDev=no Description=Test for PrivateDev=no
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test -c /dev/mem)' ExecStart=/bin/sh -x -c 'test -c /dev/mem'
Type=oneshot Type=oneshot
PrivateDevices=no PrivateDevices=no

View file

@ -2,6 +2,6 @@
Description=Test for PrivateDev=yes Description=Test for PrivateDev=yes
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test ! -c /dev/mem)' ExecStart=/bin/sh -c 'test ! -c /dev/mem'
Type=oneshot Type=oneshot
PrivateDevices=yes PrivateDevices=yes

View file

@ -2,5 +2,6 @@
Description=Test for PrivateNetwork Description=Test for PrivateNetwork
[Service] [Service]
ExecStart=/bin/sh -c 'i=$(ip link | grep ": " | grep -v lo); echo $i; exit $(test -z $i)' ExecStart=/bin/sh -x -c 'i=$$(ip link | grep ": " | grep -v ": lo:"); test -z "$$i"'
Type=oneshot
PrivateNetwork=yes PrivateNetwork=yes

View file

@ -2,6 +2,6 @@
Description=Test for PrivateTmp=no Description=Test for PrivateTmp=no
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test -f /tmp/test-exec_privatetmp)' ExecStart=/bin/sh -x -c 'test -f /tmp/test-exec_privatetmp'
Type=oneshot Type=oneshot
PrivateTmp=no PrivateTmp=no

View file

@ -2,6 +2,6 @@
Description=Test for PrivateTmp=yes Description=Test for PrivateTmp=yes
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test ! -f /tmp/test-exec_privatetmp)' ExecStart=/bin/sh -x -c 'test ! -f /tmp/test-exec_privatetmp'
Type=oneshot Type=oneshot
PrivateTmp=yes PrivateTmp=yes

View file

@ -2,7 +2,7 @@
Description=Test for RuntimeDirectoryMode Description=Test for RuntimeDirectoryMode
[Service] [Service]
ExecStart=/bin/sh -c 's=$(stat -c %a /tmp/test-exec_runtimedirectory-mode); echo $s; exit $(test $s = "750")' ExecStart=/bin/sh -x -c 'mode=$$(stat -c %%a /tmp/test-exec_runtimedirectory-mode); test "$$mode" = "750"'
Type=oneshot Type=oneshot
RuntimeDirectory=test-exec_runtimedirectory-mode RuntimeDirectory=test-exec_runtimedirectory-mode
RuntimeDirectoryMode=0750 RuntimeDirectoryMode=0750

View file

@ -2,7 +2,7 @@
Description=Test for RuntimeDirectory owner (must not be the default group of the user if Group is set) Description=Test for RuntimeDirectory owner (must not be the default group of the user if Group is set)
[Service] [Service]
ExecStart=/bin/sh -c 'f=/tmp/test-exec_runtimedirectory-owner;g=$(stat -c %G $f); echo "$g"; exit $(test $g = "nobody")' ExecStart=/bin/sh -x -c 'group=$$(stat -c %%G /tmp/test-exec_runtimedirectory-owner); test "$$group" = "nobody"'
Type=oneshot Type=oneshot
Group=nobody Group=nobody
User=root User=root

View file

@ -2,6 +2,6 @@
Description=Test for RuntimeDirectory Description=Test for RuntimeDirectory
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test -d /tmp/test-exec_runtimedirectory)' ExecStart=/bin/sh -x -c 'test -d /tmp/test-exec_runtimedirectory'
Type=oneshot Type=oneshot
RuntimeDirectory=test-exec_runtimedirectory RuntimeDirectory=test-exec_runtimedirectory

View file

@ -2,6 +2,7 @@
Description=Test for SystemCallErrorNumber Description=Test for SystemCallErrorNumber
[Service] [Service]
ExecStart=/bin/sh -c 'uname -a' ExecStart=/bin/sh -x -c 'uname -a'
Type=oneshot
SystemCallFilter=~uname SystemCallFilter=~uname
SystemCallErrorNumber=EACCES SystemCallErrorNumber=EACCES

View file

@ -3,6 +3,7 @@ Description=Test for SystemCallFilter
[Service] [Service]
ExecStart=/bin/echo "This should not be seen" ExecStart=/bin/echo "This should not be seen"
Type=oneshot
SystemCallFilter=ioperm SystemCallFilter=ioperm
SystemCallFilter=~ioperm SystemCallFilter=~ioperm
SystemCallFilter=ioperm SystemCallFilter=ioperm

View file

@ -3,4 +3,5 @@ Description=Test for SystemCallFilter
[Service] [Service]
ExecStart=/bin/echo "This should not be seen" ExecStart=/bin/echo "This should not be seen"
Type=oneshot
SystemCallFilter=~write open execve exit_group close mmap munmap fstat DONOTEXIST SystemCallFilter=~write open execve exit_group close mmap munmap fstat DONOTEXIST

View file

@ -3,6 +3,7 @@ Description=Test for SystemCallFilter
[Service] [Service]
ExecStart=/bin/echo "Foo bar" ExecStart=/bin/echo "Foo bar"
Type=oneshot
SystemCallFilter=~read write open execve ioperm SystemCallFilter=~read write open execve ioperm
SystemCallFilter=ioctl SystemCallFilter=ioctl
SystemCallFilter=read write open execve SystemCallFilter=read write open execve

View file

@ -3,4 +3,5 @@ Description=Test for SystemCallFilter
[Service] [Service]
ExecStart=/bin/echo "Foo bar" ExecStart=/bin/echo "Foo bar"
Type=oneshot
SystemCallFilter= SystemCallFilter=

View file

@ -2,6 +2,7 @@
Description=Test for UMask Description=Test for UMask
[Service] [Service]
ExecStart=/bin/sh -c 'touch /tmp/test-exec-umask; s=$(stat -c %a /tmp/test-exec-umask); echo $s; exit $(test $s = "600")' ExecStart=/bin/sh -x -c 'touch /tmp/test-exec-umask; mode=$$(stat -c %%a /tmp/test-exec-umask); test "$$mode" = "600"'
Type=oneshot
UMask=0177 UMask=0177
PrivateTmp=yes PrivateTmp=yes

View file

@ -2,5 +2,6 @@
Description=Test for UMask default Description=Test for UMask default
[Service] [Service]
ExecStart=/bin/sh -c 'touch /tmp/test-exec-umask; s=$(stat -c %a /tmp/test-exec-umask); echo $s; exit $(test $s = "644")' ExecStart=/bin/sh -x -c 'touch /tmp/test-exec-umask; mode=$$(stat -c %%a /tmp/test-exec-umask); test "$$mode" = "644"'
Type=oneshot
PrivateTmp=yes PrivateTmp=yes

View file

@ -2,5 +2,6 @@
Description=Test for User Description=Test for User
[Service] [Service]
ExecStart=/bin/sh -c 'exit $(test "$USER" = nobody)' ExecStart=/bin/sh -x -c 'test "$$USER" = "nobody"'
Type=oneshot
User=nobody User=nobody

View file

@ -2,6 +2,6 @@
Description=Test for WorkingDirectory Description=Test for WorkingDirectory
[Service] [Service]
ExecStart=/bin/sh -c 'echo $PWD; exit $(test $PWD = "/tmp/test-exec_workingdirectory")' ExecStart=/bin/sh -x -c 'test "$$PWD" = "/tmp/test-exec_workingdirectory"'
Type=oneshot Type=oneshot
WorkingDirectory=/tmp/test-exec_workingdirectory WorkingDirectory=/tmp/test-exec_workingdirectory