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

Apply crash function to Windows Console via SetConsoleCtrlHandler #141

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from

Conversation

Kodikuu
Copy link

@Kodikuu Kodikuu commented Oct 10, 2024

Needs some testing, but this should make application quits more graceful when running with an open console on Windows.

Closing the console or Ctrl+C-ing it will be treated the same as a forced termination via Task Manager
Ctrl+Break acts like a crash, because that's useful to have (Ctrl+C and Ctrl+Break events are when inputting to the console)

Shutdown will plainly exit the application since it shouldn't remain running, while logoff events will leave things down to Windows

@Kodikuu Kodikuu added the 2. Review requested You have coded your code, and can now be reviewed. label Oct 10, 2024
@Kodikuu Kodikuu self-assigned this Oct 10, 2024
Copy link
Member

@dvijayak dvijayak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my note.

Comment on lines +235 to +240
// Console close == SIGTERM, Ctrl+C == SIGINT
if (SYSTEM_CRASH_FUNC)
SYSTEM_CRASH_FUNC(dwCtrlType == CTRL_CLOSE_EVENT || dwCtrlType == CTRL_C_EVENT, SYSTEM_OPAQUE);

// Prevent secondary calls to the SYSTEM_CRASH_FUNC
SYSTEM_CRASH_FUNC = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you need to protect against multi-threaded scenarios, but perhaps you should do an atomic exchange of the crash func pointer into a local variable while setting the static variable to NULL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. Review requested You have coded your code, and can now be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants