From c9924d5b7cbca982f66e01e45f324eb775c0702e Mon Sep 17 00:00:00 2001 From: Thomas Boop Date: Fri, 3 Jan 2020 15:02:47 -0500 Subject: [PATCH] Check if file exists before reading --- src/Runner.Worker/ContainerOperationProvider.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index a476b5464..b7fc5a07a 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -61,11 +61,16 @@ namespace GitHub.Runner.Worker { throw new NotSupportedException("Container feature is not supported when runner is already running inside container."); } -#else - var initProcessCgroup = File.ReadLines("/proc/1/cgroup"); - if (initProcessCgroup.Any(x => x.IndexOf(":/docker/", StringComparison.OrdinalIgnoreCase) >= 0)) +#else + var path = "/proc/1/cgroup"; + // OSX does not have this file, but you cannot run OSX as a base image for docker containers currently. + if (File.Exists(path)) { - throw new NotSupportedException("Container feature is not supported when runner is already running inside container."); + var initProcessCgroup = File.ReadLines(path); + if (initProcessCgroup.Any(x => x.IndexOf(":/docker/", StringComparison.OrdinalIgnoreCase) >= 0)) + { + throw new NotSupportedException("Container feature is not supported when runner is already running inside container."); + } } #endif