[CRIU] [RFC PATCH 03/21] zdtm: zdtm.py: remove directories before recreating them in __construct_root(); fix TOCTTOU in clean()

Pavel Emelyanov xemul at virtuozzo.com
Wed Mar 9 02:19:44 PST 2016


On 02/19/2016 05:50 PM, Ivan Shapovalov wrote:

Why do you hit this problem? If there's a trash left from previous
failed run, just clean it with zdtm.py clean nsroot.

> Signed-off-by: Ivan Shapovalov <intelfx at intelfx.name>
> ---
>  test/zdtm.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 3caf227..ef521f4 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -214,6 +214,11 @@ class ns_flavor:
>  
>  	def __construct_root(self):
>  		for dir in self.__root_dirs:
> +			try:
> +			    shutil.rmtree(self.root + dir)
> +			except OSError as e:
> +			    if e.errno != errno.ENOENT:
> +				raise
>  			os.mkdir(self.root + dir)
>  			os.chmod(self.root + dir, 0777)
>  
> @@ -258,8 +263,11 @@ class ns_flavor:
>  		for d in ns_flavor.__root_dirs:
>  			p = './' + d
>  			print 'Remove %s' % p
> -			if os.access(p, os.F_OK):
> -				shutil.rmtree('./' + d)
> +			try:
> +			    shutil.rmtree('./' + d)
> +			except OSError as e:
> +			    if e.errno != errno.ENOENT:
> +				raise
>  
>  		if os.access('./.constructed', os.F_OK):
>  			os.unlink('./.constructed')
> 



More information about the CRIU mailing list