Commit b403426
committed
Fix race condition - envsubst $file | tee $file
When running `envsubst $file` and pipe to `tee $file` there is a race
causing the targe file to be wiped.
The following script can be used to reproduce the race condition:
```
#!/bin/sh
echo -e "foo\nbar\nbaz" > /tmp/test_file
count=0
while [ -s /tmp/test_file ]; do
envsubst < /tmp/test_file | tee /tmp/test_file > /dev/null
((count+=1))
done
if [ ! -s /tmp/test_file ]; then
echo "File was wiped after $count run's of: envsubst < \$file | tee \$file"
fi
```
```
$ sh test.sh
File was wiped after 16 run's of: envsubst < $file | tee $file
$ sh test.sh
File was wiped after 42 run's of: envsubst < $file | tee $file
$ sh test.sh
File was wiped after 37 run's of: envsubst < $file | tee $file
$ sh test.sh
File was wiped after 73 run's of: envsubst < $file | tee $file
$ sh test.sh
File was wiped after 4 run's of: envsubst < $file | tee $file
```
Jira: OSPRH-17012
Jira: OSPCIX-8701 parent 4d0ee77 commit b403426
1 file changed
+11
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
0 commit comments