Re:Pipefail: A missing shell option slowed Cloudflare down
by alexforster on Tuesday April 05, 2022 @07:11PM
(#30926332)
Author here – you are correct, I tried to golf a relatively long script down to one line, and I failed :) The post has been updated.
Re:Pipefail: A missing shell option slowed Cloudflare down
by Wallacy on Tuesday April 05, 2022 @08:41PM
(#30927009)
If the update is:
set -e -u -o pipefail
(dos-make-addr-conf | tee config.toml) && dosctr set template_vars config.toml
well....
`tee config.toml` will still produce a empty config.toml
(set -e - u -o pipefail;false | tee config.toml) && cat config.toml
But you can use the '>' operator, that will create the file only if the command runs successful:
dos-make-addr-conf > config.toml && dosctr set template_vars config.toml
Re:Pipefail: A missing shell option slowed Cloudflare down
by faho on Wednesday April 06, 2022 @09:49AM
(#30931913)
> But you can use the '>' operator, that will create the file only if the command runs successful:
It will still create the file.
Run this in bash, zsh or fish:
false > falsefile
It will create an empty file called "falsefile". This is because the shell opens the file before the program runs.What fixes it in your script is the `&&`. That causes the `dosctr` to only be run if the `dos-make-addr-conf` succeeded.
The article says:
> Enabling this option changes the shell’s behavior so that, when any command in a pipeline series fails, the entire pipeline stops processing.
This is not true! The entire pipeline runs to completion just as it normally would. The only thing that is affected is the exit status of the pipeline as seen by the shell.
You can see this by running something like `(set -o pipefail; false | sleep 10)` and see that it still takes 10 seconds to complete even those the `false` command exits with an error immediately.
Even after turning on the pipefail option, running a command like `false | dosctl set template_vars -` will still set template_vars to the empty string.