How to handle signals gracefully in the Electron.js application? - c++

I'm trying to implement signal handling in the Electron.js application to call a custom function either in C++ code or JS code (ex. segmentation fault). In one of the node addons, I did it using std::signal method and it works for macOS but on Windows it, unfortunately, doesn't work (although works on a simple node.js environment). I get the following error on the console when the app crashes: the custom handler doesn't work.
[10208:0815/181127.900:ERROR:crashpad_client_win.cc(814)] not connected

Related

Understanding and managing c++ program crash handling in windows

I have a c++ program compiled with MinGW which links to libmicrohttpd to run a webserver. It normally functions correctly, but I am trying to do some robustness testing and for my current test I have tried to disable the network interface. This results in the program crashing with the dialog box: "MyProgram.exe has stopped working - A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
Rather than debug the program and potentially its dependencies, for my purposes, it would be fine if it would just crash silently without making the dialog box (I have another component that is meant to restart it). Is this possible to do via some sort of manifest or Windows API call?
It turns out there is a Windows API function called SetErrorMode. Passing the parameter SEM_NOGPFAULTERRORBOX will prevent the error dialog from being displayed on a crash.
There is also the RegisterApplicationRestart function which can be used to have Windows restart an application in the event of a crash (or other configurable reasons).

Custom signal handlers with OpenCV debug mode

I'm trying to make an application that handles crashes on its own. I was able to find out how to handle SIGSEGV (How to generate a stacktrace when my gcc C++ app crashes) - but it seems like the OpenCV error handler comes into action whenever something goes wrong.
This causes my custom signal handler to never execute. Any hints on how to get this working?
Edit: this solution works on linux only
It is possible to replace an action. But using the signal function won't do the job.
You have to use sigaction to replace the previous signal handler. Take a look:
http://man7.org/linux/man-pages/man2/sigaction.2.html

Netbeans handling of linux C++ signals

I am building an application for Beaglebone Black using Netbeans running on a PC using remote compilation and debug. The debug has been straightforward up to this point, but I am now trying to sort out my serial comms. My serial code uses a signal to indicate data reception, and Netbeans halts my code to inform me of the signal. It offers 3 options: Discard and Continue, Discard and Pause, Forward and Continue. I want none of these! I want no notification of the signal at all, I want it to be handled by my code.
The options in Project Properties/Debug/Signals are to set them to Ignore (the program no longer responds to them) or Catch (pop up an annoying dialog that breaks my comms protocols). Is there is a way to get Netbeans to just carry on running as it ought to?

C++ / C call method from running software

I would like to use C++ / C to call a method of an running application. So it should work the following way:
An application is running, let's say Chrome and another application is running (plugin.exe). The other application should call a Chrome c++ method from the outside. Is that possible?
The method that I would like to call is the method displaying auto suggests. I would like to develop an omnibox with multiple keywords.
Somehow I would like to hook into the application and send / receive events and call methods. I guess event reeving can be done, since it's possible to use the Microsoft debugger with an executable and catch a lot of events.
While researching a bit I found out how to load a dll plugin in Chrome:
https://developer.chrome.com/extensions/npapi
I've done the same in Pepper API as well, but from there I can't reach any further.

Using Win32 API CreateProcess in FireBreath Framework

I'm trying to develop a browser plugin using Firebreath framework. The first thing I would like to achieve is to make the plugin able to do traceroute. For now I'm doing it on Windows7. Currently I chose to use Win32API CreateProcess to call the command shell. By setting dwFlags = STARTF_USESHOWWINDOW , I'm able to hide the command shell window during execution.
PROBLEM : The createProcess is implemented in a method called run() where I called it using JS for testing. When I called plugin().run(), the traceroute is working well, and the output was succesfully written in a textfile as I wanted. However during the execution, the browser become unresponsive and lastly the plugin crashed seconds after the traceroute completed. As I am new to plugin development and only have a little knowledge on c++ , I wonder why this problem arisen. FYI, if I did not hide the commandshell window, the plugin worked wonder - the browser was responsive while the traceroute was executed.
It is very important in any NPAPI plugin (with FireBreath or otherwise) that you don't block the main (the javascript) thread. What you're trying to do could be done in a couple of ways; I'd probably pass in a callback, start a new thread, do the createprocess there, and then fire the js callback when it completes with the result.
See FireBreath Tips: Asynchronous Javascript Calls.
The one thing to watch out for is you need to be able to terminate the thread (and the process) if the plugin is shut down during the call.