Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CakeExecuteScript access denied errors on mono/mac #1247

Closed
Redth opened this issue Sep 23, 2016 · 5 comments
Closed

CakeExecuteScript access denied errors on mono/mac #1247

Redth opened this issue Sep 23, 2016 · 5 comments
Assignees
Labels
Milestone

Comments

@Redth
Copy link
Contributor

Redth commented Sep 23, 2016

What You Are Seeing?

Getting an access denied error

Error: ApplicationName='/Users/redth/Desktop/breakcake/tools/Cake/Cake.exe', CommandLine='"/Users/redth/Desktop/breakcake/two.cake"', CurrentDirectory='/Users/redth/Desktop/breakcake', Native error= Access denied

What is Expected?

No errors, secondary script should execute successfully

What version of Cake are you using?

0.16

Are you running on a 32 or 64 bit system?

x64

What environment are you running on? Windows? Linux? Mac?

Mac 10.11, Mac 10.12

Are you running on a CI Server? If so, which one?

N/A

How Did You Get This To Happen? (Steps to Reproduce)

build.cake:

Information ("Running: {0}", "build.cake");

// Run the script from the subfolder
CakeExecuteScript ("two.cake");

two.cake:

Information ("Running: {0}", "two.cake");

Output Log

Redth:breakcake redth$ cake --verbosity=diagnostic
Module directory does not exist.
Analyzing build script...
Analyzing /Users/redth/Desktop/breakcake/build.cake...
Processing build script...
Creating script session...
Adding reference to System.Data.dll...
Adding reference to System.Xml.dll...
Adding reference to System.Xml.Linq.dll...
Adding reference to Cake.Core.dll...
Adding reference to Cake.Common.dll...
Adding reference to Cake.exe...
Importing namespace Cake.Common...
Importing namespace Cake.Common.Build...
Importing namespace Cake.Common.Build.AppVeyor...
Importing namespace Cake.Common.Build.AppVeyor.Data...
Importing namespace Cake.Common.Build.BitbucketPipelines...
Importing namespace Cake.Common.Build.BitbucketPipelines.Data...
Importing namespace Cake.Common.Build.Bitrise...
Importing namespace Cake.Common.Build.Bitrise.Data...
Importing namespace Cake.Common.Build.ContinuaCI...
Importing namespace Cake.Common.Build.ContinuaCI.Data...
Importing namespace Cake.Common.Build.Jenkins...
Importing namespace Cake.Common.Build.Jenkins.Data...
Importing namespace Cake.Common.Build.TravisCI...
Importing namespace Cake.Common.Build.TravisCI.Data...
Importing namespace Cake.Common.Diagnostics...
Importing namespace Cake.Common.IO...
Importing namespace Cake.Common.IO.Paths...
Importing namespace Cake.Common.Net...
Importing namespace Cake.Common.Security...
Importing namespace Cake.Common.Solution...
Importing namespace Cake.Common.Solution.Project...
Importing namespace Cake.Common.Solution.Project.Properties...
Importing namespace Cake.Common.Solution.Project.XmlDoc...
Importing namespace Cake.Common.Text...
Importing namespace Cake.Common.Tools...
Importing namespace Cake.Common.Tools.Cake...
Importing namespace Cake.Common.Tools.Chocolatey...
Importing namespace Cake.Common.Tools.Chocolatey.ApiKey...
Importing namespace Cake.Common.Tools.Chocolatey.Config...
Importing namespace Cake.Common.Tools.Chocolatey.Features...
Importing namespace Cake.Common.Tools.Chocolatey.Install...
Importing namespace Cake.Common.Tools.Chocolatey.Pack...
Importing namespace Cake.Common.Tools.Chocolatey.Pin...
Importing namespace Cake.Common.Tools.Chocolatey.Push...
Importing namespace Cake.Common.Tools.Chocolatey.Sources...
Importing namespace Cake.Common.Tools.Chocolatey.Upgrade...
Importing namespace Cake.Common.Tools.DNU...
Importing namespace Cake.Common.Tools.DNU.Build...
Importing namespace Cake.Common.Tools.DNU.Pack...
Importing namespace Cake.Common.Tools.DNU.Restore...
Importing namespace Cake.Common.Tools.DotCover...
Importing namespace Cake.Common.Tools.DotCover.Analyse...
Importing namespace Cake.Common.Tools.DotCover.Cover...
Importing namespace Cake.Common.Tools.DotNetCore...
Importing namespace Cake.Common.Tools.DotNetCore.Build...
Importing namespace Cake.Common.Tools.DotNetCore.Execute...
Importing namespace Cake.Common.Tools.DotNetCore.Pack...
Importing namespace Cake.Common.Tools.DotNetCore.Publish...
Importing namespace Cake.Common.Tools.DotNetCore.Restore...
Importing namespace Cake.Common.Tools.DotNetCore.Run...
Importing namespace Cake.Common.Tools.DotNetCore.Test...
Importing namespace Cake.Common.Tools.DupFinder...
Importing namespace Cake.Common.Tools.Fixie...
Importing namespace Cake.Common.Tools.GitLink...
Importing namespace Cake.Common.Tools.GitReleaseManager...
Importing namespace Cake.Common.Tools.GitReleaseManager.AddAssets...
Importing namespace Cake.Common.Tools.GitReleaseManager.Close...
Importing namespace Cake.Common.Tools.GitReleaseManager.Create...
Importing namespace Cake.Common.Tools.GitReleaseManager.Export...
Importing namespace Cake.Common.Tools.GitReleaseManager.Publish...
Importing namespace Cake.Common.Tools.GitReleaseNotes...
Importing namespace Cake.Common.Tools.GitVersion...
Importing namespace Cake.Common.Tools.ILMerge...
Importing namespace Cake.Common.Tools.ILRepack...
Importing namespace Cake.Common.Tools.InspectCode...
Importing namespace Cake.Common.Tools.MSBuild...
Importing namespace Cake.Common.Tools.MSTest...
Importing namespace Cake.Common.Tools.NSIS...
Importing namespace Cake.Common.Tools.NuGet...
Importing namespace Cake.Common.Tools.NuGet.Install...
Importing namespace Cake.Common.Tools.NuGet.Pack...
Importing namespace Cake.Common.Tools.NuGet.Push...
Importing namespace Cake.Common.Tools.NuGet.Restore...
Importing namespace Cake.Common.Tools.NuGet.SetApiKey...
Importing namespace Cake.Common.Tools.NuGet.SetProxy...
Importing namespace Cake.Common.Tools.NuGet.Sources...
Importing namespace Cake.Common.Tools.NuGet.Update...
Importing namespace Cake.Common.Tools.NUnit...
Importing namespace Cake.Common.Tools.OctopusDeploy...
Importing namespace Cake.Common.Tools.OpenCover...
Importing namespace Cake.Common.Tools.ReportGenerator...
Importing namespace Cake.Common.Tools.ReportUnit...
Importing namespace Cake.Common.Tools.Roundhouse...
Importing namespace Cake.Common.Tools.SignTool...
Importing namespace Cake.Common.Tools.SpecFlow...
Importing namespace Cake.Common.Tools.SpecFlow.StepDefinitionReport...
Importing namespace Cake.Common.Tools.SpecFlow.TestExecutionReport...
Importing namespace Cake.Common.Tools.TextTransform...
Importing namespace Cake.Common.Tools.VSTest...
Importing namespace Cake.Common.Tools.WiX...
Importing namespace Cake.Common.Tools.WiX.Heat...
Importing namespace Cake.Common.Tools.XBuild...
Importing namespace Cake.Common.Tools.XUnit...
Importing namespace Cake.Common.Xml...
Importing namespace Cake.Core...
Importing namespace Cake.Core.Diagnostics...
Importing namespace Cake.Core.IO...
Importing namespace Cake.Core.Scripting...
Importing namespace System...
Importing namespace System.Collections.Generic...
Importing namespace System.IO...
Importing namespace System.Linq...
Importing namespace System.Text...
Importing namespace System.Threading.Tasks...
Compiling build script...
Running: build.cake
Executing: /Users/redth/Desktop/breakcake/tools/Cake/Cake.exe "/Users/redth/Desktop/breakcake/two.cake"
Error: System.ComponentModel.Win32Exception (0x80004005): ApplicationName='/Users/redth/Desktop/breakcake/tools/Cake/Cake.exe', CommandLine='"/Users/redth/Desktop/breakcake/two.cake"', CurrentDirectory='/Users/redth/Desktop/breakcake', Native error= Access denied
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x001ee] in <affe4060066c42de8cdd6027cdb92b56>:0
@devlead
Copy link
Member

devlead commented Sep 23, 2016

Regression seems to be in the 4.5 Cake.xe assembly created by .NET Core and that Mono can't auto identify these as .NET/Mono assemblies. Mono has no issue executing said assembly when frame

A workaround is to specify the runtime to use for execution

public static CakeSettings GetCakeSettings(ICakeContext context, IDictionary<string, string> arguments = null)
{
    var settings = new CakeSettings { Arguments = arguments };
    if (context.Environment.Runtime.IsCoreClr)
    {
        settings.ToolPath = FindToolInPath(context, context.IsRunningOnUnix() ? "dotnet" : "dotnet.exe");
        settings.ArgumentCustomization = args => "./tools/Cake.CoreCLR/Cake.dll " + args.Render();

    }
    else if (context.IsRunningOnUnix())
    {
        settings.ToolPath = FindToolInPath(context, "mono");
        settings.ArgumentCustomization = args => "./tools/Cake/Cake.exe " + args.Render();
    }
    return settings;
}

public static FilePath FindToolInPath(ICakeContext context, string tool)
{
    var pathEnv = context.EnvironmentVariable("PATH");
    if (string.IsNullOrEmpty(pathEnv)||string.IsNullOrEmpty(tool))
    {
        return tool;
    }
    var paths = pathEnv.Split(new []{context.IsRunningOnUnix() ? ':' : ';'},  StringSplitOptions.RemoveEmptyEntries);
    return paths.Select(
            path=>new DirectoryPath(path).CombineWithFilePath(tool)
        ).FirstOrDefault(filePath=>System.IO.File.Exists(filePath.FullPath));
}

But this would only solve that tool, potentially as more .NET tools start to utilize .NET the more tools will start to fail on Mono.
.NET Core doesn't have auto magic but requires runtime to be specified.

We could introduce some magic in Tool / ToolSettings base, feels like a real potential rabbit hole though.

What we could do is somekind of runtime / framework option on the base settings class which perhaps could have Native as default and i.e. .NET Core / Mono / Java as alternatives Or just a FrameworkToolPath.

Perhaps we could add something to the tool registration to infer/let user specify runtime.

Tool aliases could potentially be aware of supported runtimes got it's specific tool an register that.

But this needs some thought, regardless ability to specify a tool runtime would be a good addition, if we make it "easy" for us it could be an "RuntimeToolPath" if not null used as process.

@Redth
Copy link
Contributor Author

Redth commented Oct 5, 2016

Here's a bit more information gathered...

There’s a bug i filed about this: https://bugzilla.xamarin.com/show_bug.cgi?id=44937

Essentially the trouble area is: https://github.com/mono/mono/blob/master/mono/io-layer/processes.c#L500

In that if statement, first_word and second_word are == 0 so it returns true and exits.

Now, the question: is mono’s interpretation of what’s managed or not incorrect, or is dotnetcore emitting an assembly with an incorrect CLR header?

@devlead
Copy link
Member

devlead commented Oct 10, 2016

@Redth found a workaround, will PR shortly.

devlead added a commit to devlead/cake that referenced this issue Oct 10, 2016
This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified
devlead added a commit to devlead/cake that referenced this issue Oct 10, 2016
This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified
devlead added a commit to devlead/cake that referenced this issue Oct 10, 2016
This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified
devlead added a commit to devlead/cake that referenced this issue Oct 10, 2016
This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified
akoeplinger added a commit to akoeplinger/mono that referenced this issue Oct 10, 2016
… process

We weren't checking whether a PE file is in PE32 or PE32+ format,
causing us to use the PE32 offsets on the newer format as well.

This means that using Process.Start() on a managed assembly didn't
always work when a PE32+ file was in play. Such a file is created
when targeting x64 e.g. via the -platform:x64 csc.exe/mcs option.

The reason why we probably didn't notice until now is that in an
assembly produced by mcs there happens to be some data at the PE32
CLR header offset even in a PE32+ file, causing the check to "work".

This doesn't apply to csc.exe/roslyn though and so we couldn't
execute those assemblies via Process.Start() even though they're
perfectly managed. Since the .NET Core project.json toolchain
produces x64-targeted assemblies by default more people ran into
the issue trying to run those on Mono: cake-build/cake#1247

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44937

PE/COFF spec at https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx
@devlead devlead self-assigned this Oct 11, 2016
@devlead devlead added this to the v0.16.2 milestone Oct 11, 2016
@devlead
Copy link
Member

devlead commented Oct 11, 2016

Fixed by #1266

@devlead devlead closed this as completed Oct 11, 2016
@devlead devlead added the Bug label Oct 11, 2016
@devlead
Copy link
Member

devlead commented Oct 11, 2016

@Redth v0.16.2 is now available on nuget which addresses this issue. Big thanks to you for finding this and @akoeplinger who helped us sort this.

akoeplinger added a commit to mono/mono that referenced this issue Oct 11, 2016
… process

We weren't checking whether a PE file is in PE32 or PE32+ format,
causing us to use the PE32 offsets on the newer format as well.

This means that using Process.Start() on a managed assembly didn't
always work when a PE32+ file was in play. Such a file is created
when targeting x64 e.g. via the -platform:x64 csc.exe/mcs option.

The reason why we probably didn't notice until now is that in an
assembly produced by mcs there happens to be some data at the PE32
CLR header offset even in a PE32+ file, causing the check to "work".

This doesn't apply to csc.exe/roslyn though and so we couldn't
execute those assemblies via Process.Start() even though they're
perfectly managed. Since the .NET Core project.json toolchain
produces x64-targeted assemblies by default more people ran into
the issue trying to run those on Mono: cake-build/cake#1247

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44937

PE/COFF spec at https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx

(cherry picked from commit 68bcbb4)
vip32 added a commit to vip32/cake that referenced this issue Oct 14, 2016
octo channel tests added + some more octo.exe settings to start a deployment after creating the release.
http://docs.octopusdeploy.com/display/OD/Creating+releases

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

comment fix

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

Change to use AnyCPU to address mono issue

This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151
vip32 added a commit to vip32/cake that referenced this issue Oct 14, 2016
octo channel tests added + some more octo.exe settings to start a deployment after creating the release.
http://docs.octopusdeploy.com/display/OD/Creating+releases

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

comment fix

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

Change to use AnyCPU to address mono issue

This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151
vip32 added a commit to vip32/cake that referenced this issue Oct 14, 2016
octo channel tests added + some more octo.exe settings to start a deployment after creating the release.
http://docs.octopusdeploy.com/display/OD/Creating+releases

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

comment fix

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

Change to use AnyCPU to address mono issue

This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151

comment fix

octo channel tests added + some more octo.exe settings to start a deployment after creating the release.
http://docs.octopusdeploy.com/display/OD/Creating+releases

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

comment fix

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

Change to use AnyCPU to address mono issue

This fixes cake-build#1247, because issue in .NET Core tooling AnyCPU needs to be specified

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151

Waiting for AppVeyor process to exit

* aslo validates exit code
* added sample code
* fixes cake-build#1241

another channel comment fix

settings again

Corrects the grammar "do/does" in exception messages and tests

Removed unused integration test code

(build) Updated version and release notes

Fixed unquoted VSTest settings file, now using AppendSwitch*

Removed erroneous apostrophes

Added % to alphanumeric chars allowed in glob

Adds /LogFile parameter to DotCoverSettings
Solves cake-build#1151
picenka21 pushed a commit to picenka21/runtime that referenced this issue Feb 18, 2022
… process

We weren't checking whether a PE file is in PE32 or PE32+ format,
causing us to use the PE32 offsets on the newer format as well.

This means that using Process.Start() on a managed assembly didn't
always work when a PE32+ file was in play. Such a file is created
when targeting x64 e.g. via the -platform:x64 csc.exe/mcs option.

The reason why we probably didn't notice until now is that in an
assembly produced by mcs there happens to be some data at the PE32
CLR header offset even in a PE32+ file, causing the check to "work".

This doesn't apply to csc.exe/roslyn though and so we couldn't
execute those assemblies via Process.Start() even though they're
perfectly managed. Since the .NET Core project.json toolchain
produces x64-targeted assemblies by default more people ran into
the issue trying to run those on Mono: cake-build/cake#1247

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44937

PE/COFF spec at https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx


Commit migrated from mono/mono@68bcbb4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants