zone: response with an error if a zone is already up or down
mbox

Message ID 1500988437-3732-1-git-send-email-jonatan.schlag@ipfire.org
State New
Headers show

Message

Jonatan Schlag July 25, 2017, 11:13 p.m. UTC
Fixes: #11368

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.zone | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Michael Tremer July 26, 2017, 8:32 a.m. UTC | #1
Hi,

this patch looks logically fine, but I sometimes use the "up" function to reload
a zone which is no longer possible.

And secondly, I am not sure if "zone_is_active" will return true when systemd
has started the script. In that case, the "up" action would be called and assume
that everything is up already and therefore never bring up the zone.

-Michael

On Tue, 2017-07-25 at 15:13 +0200, Jonatan Schlag wrote:
> Fixes: #11368
> 
> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
> ---
>  src/functions/functions.zone | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/functions/functions.zone b/src/functions/functions.zone
> index 91ce629..eccca3a 100644
> --- a/src/functions/functions.zone
> +++ b/src/functions/functions.zone
> @@ -369,6 +369,12 @@ zone_up() {
>  		return ${EXIT_ERROR}
>  	fi
>  
> +	# Check if the zone is already up
> +	if zone_is_active ${zone}; then
> +		log ERROR "Zone ${zone} is already up"
> +		return ${EXIT_ERROR}
> +	fi
> +
>  	# Check if a zone has got the remove tag.
>  	if zone_has_destroy_tag ${zone}; then
>  		error "Cannot bring up any zone which is to be removed."
> @@ -405,6 +411,13 @@ zone_down() {
>  		return ${EXIT_ERROR}
>  	fi
>  
> +	# Check if the zone is already down
> +	if ! zone_is_active ${zone}; then
> +		log ERROR "Zone ${zone} is already down"
> +		return ${EXIT_ERROR}
> +	fi
> +
> +
>  	local hook="$(zone_get_hook "${zone}")"
>  	if [ -z "${hook}" ]; then
>  		error "Config file did not provide any hook."