Factorize the function to validate env
Reviewed by: antoine Differential Revision: https://reviews.freebsd.org/D2966