-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Check for SIG_IGN and SIG_DFL before calling previous signal handler #132900
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # The test is valid only on macOS. | ||
| if (CLR_CMAKE_TARGET_OSX) | ||
| include_directories(${INC_PLATFORM_DIR}) | ||
|
|
||
| add_library(nativetest132581 ${TEST_LIB_TYPE} nativetest132581.cpp) | ||
|
|
||
| install(TARGETS nativetest132581 DESTINATION bin) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #include <platformdefines.h> | ||
|
|
||
| #include <errno.h> | ||
| #include <signal.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/wait.h> | ||
| #include <unistd.h> | ||
|
|
||
| static void SignalHandler(int, siginfo_t*, void*) | ||
| { | ||
| } | ||
|
|
||
| extern "C" DLL_EXPORT int InstallSignalHandlerAndExec(const char* executable, const char* managedAssembly) | ||
| { | ||
| struct sigaction action; | ||
| memset(&action, 0, sizeof(action)); | ||
| action.sa_sigaction = SignalHandler; | ||
| action.sa_flags = SA_SIGINFO | SA_RESTART; | ||
| sigemptyset(&action.sa_mask); | ||
|
|
||
| if (sigaction(SIGUSR1, &action, nullptr) != 0) | ||
| { | ||
| return errno; | ||
| } | ||
|
|
||
| if (setenv("DOTNET_TEST_132581_CHILD", "1", 1) != 0) | ||
| { | ||
| return errno; | ||
| } | ||
|
|
||
| char* arguments[4]; | ||
| int index = 0; | ||
| arguments[index++] = const_cast<char*>(executable); | ||
| if (managedAssembly[0] != '\0') | ||
| { | ||
| arguments[index++] = const_cast<char*>(managedAssembly); | ||
| } | ||
| arguments[index++] = const_cast<char*>("--child"); | ||
| arguments[index] = nullptr; | ||
|
|
||
| execv(executable, arguments); | ||
| return errno; | ||
| } | ||
|
|
||
| extern "C" DLL_EXPORT int SendSignalFromChildProcess() | ||
| { | ||
| pid_t child = fork(); | ||
| if (child == -1) | ||
| { | ||
| return errno; | ||
| } | ||
|
|
||
| if (child == 0) | ||
| { | ||
| int result = kill(getppid(), SIGUSR1); | ||
| _exit(result == 0 ? 0 : 1); | ||
| } | ||
|
|
||
| int status; | ||
| pid_t result; | ||
| do | ||
| { | ||
| result = waitpid(child, &status, 0); | ||
| } | ||
| while ((result == -1) && (errno == EINTR)); | ||
|
|
||
| return (result == child) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) ? 0 : -1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
|
|
||
| public class Program | ||
| { | ||
| private const string ChildEnvironmentVariable = "DOTNET_TEST_132581_CHILD"; | ||
|
|
||
| [DllImport("nativetest132581")] | ||
| private static extern int InstallSignalHandlerAndExec(string executable, string managedAssembly); | ||
|
|
||
| [DllImport("nativetest132581")] | ||
| private static extern int SendSignalFromChildProcess(); | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| if (Environment.GetEnvironmentVariable(ChildEnvironmentVariable) is null) | ||
| { | ||
| string executable = Environment.ProcessPath ?? throw new InvalidOperationException("The process path is unavailable."); | ||
| string command = Environment.GetCommandLineArgs()[0]; | ||
| string managedAssembly = string.Equals(executable, command, StringComparison.Ordinal) ? string.Empty : command; | ||
|
|
||
| int error = InstallSignalHandlerAndExec(executable, managedAssembly); | ||
| throw new InvalidOperationException($"execv failed with error {error}."); | ||
| } | ||
|
|
||
| Assert.Equal(0, SendSignalFromChildProcess()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||||
| <PropertyGroup> | ||||||
| <!-- Needed for CLRTestTargetUnsupported and CMakeProjectReference --> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This test actually has a reason outside of infra limitations for why it is marked RPI. Let's put that here so later tooling doesn't try to force this in-proc with other tests. |
||||||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||||||
| <CLRTestTargetUnsupported Condition="'$(TargetsOSX)' != 'true'">true</CLRTestTargetUnsupported> | ||||||
| <CLRTestPriority>1</CLRTestPriority> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is pri 1, do we want to kick of an explicit outerloop run (or whatever will run this in coreclr and native AOT)? |
||||||
| </PropertyGroup> | ||||||
| <ItemGroup> | ||||||
| <Compile Include="test132581.cs" /> | ||||||
| </ItemGroup> | ||||||
| <ItemGroup> | ||||||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||||||
| </ItemGroup> | ||||||
| <ItemGroup> | ||||||
| <CMakeProjectReference Include="CMakeLists.txt" /> | ||||||
| </ItemGroup> | ||||||
| </Project> | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the regression tests by issue number a lot harder to understand if I need to go back to them. Thoughts on naming by the scenario - something like
ActivationSignalChainingclass andExec_InheritedFlagsmethod?