Trigger "application quit unexpectedly" popup when OS X deamon crashes - macos

I'm working on a new OS-X Daemon process (run from launchd) and would like to get popup window every time it crashes with all relevant information (pid, path to crash file, etc...). This will sure help my debugging effort in this early stage of the development.
Basically, i want to have the same behavior as a UI application. For example :
I've made some research and found out about the CrashReporter, but i don't know how to register my app to this service. But it seem like there's no way to trigger popup windows from this service, since crashes are system level events and apps have zero interaction with those.
Maybe there's a way to do so by setting up some parameters in app bundle or via Info.plist ?
EDIT: looking at the crash report manual, it looks like the unexpected dialog works only on GUI user mode, and not on daemon that runs from launchd. perhaps i'm missing something ?
In addition, if the program that crashed is running as a logged in GUI user, CrashReporter will present the user with a dialog asking them whether they want to submit a bug report to Apple (see Figure 1). If the user clicks the Report button, CrashReporter displays another dialog that shows the details of the report (see Figure 2) and allows them to comment it before submission.
I've read that Developer option enable in addition to application crashes, crashes are also displayed for background and system processes. but unfortunately i doesn't work for me.
thanks

Seems like the problem occurs since my background process runs under root privilege, and root privilage process (not just daemons) cannot initiate any UI widget on the screen.
I guess that the only way to deal with it, is by catching the signal that trigger the crash, and send details for a proxy process that run on non-root mode and can initiate the UI dialog box with crash details.
I would be happy to hear for better proposals.

Since CrashReporterPrefs, which allowed you to enable this behavior for daemons, no longer comes with developer tools, you can change the behavior to show the dialog for daemons by running this command in the Terminal:
defaults write com.apple.CrashReporter DialogType Developer

Related

Why don't some programs appear on the task manager startup tab?

Many applications start at startup, however, some of them do not appear on the task manager startup tab. What is that due to?
Is there any way to do this with a program, for example, spotify?
What do I need to do in order for a program to start at startup, but not showing in the startup applications tab?
Setting it in HKCU/Microsoft/Windows/CurrentVersion/Run doesn't seem to work, as it starts, but still shows on the mentioned tab.
Thank you in advance.
Its mostly a factor of how the program itself is written. If its written to run as a service, or as a System Tray application, or otherwise.
I know there are wrappers for running any exe as a service NSSM being the main one I have experience with (but this is mostly for when there is going to be NO user interaction)
I do not know if there is anything that can allow an application to run in the system tray only, not in the taskbar, if it doesn't support it.
But since Spotify does support running minimized to the tray, it does seem like there are some ways to "start spotify minimized", Spotify or other applications might have command line options or other settings to tell them to start "hidden"

CGEventTap mouse event position overwrite only possible when running app as root user?

I am developing a macOS app which takes control of the cursor. I am using a CGEvent Tap and I am adding some arithmetic to the CGEvents in order to offset the final mouse position. Although the app is in principle working as expected, in some cases - more specifically: when running the app with certain popular illustration software and using a stylus pen - the app is producing some flickering 'ghost' positions for the mouse at its original location. The good thing is, this problem can be resolved when running the app while being logged in as root user. I have read quite some SO posts but this particular post addresses the issue best:
https://stackoverflow.com/a/9899901/5066660
As described in this post the issue is probably:
Unfortunately, the CGEventTapCreate() doc says:
Only processes running as the root user may locate an event tap at the point where HID events enter the window server; for other users, this function returns NULL.
Well the function is definitely not returning null because the tap is in effect. Also I tried all possible combinations of arguments for that function, but they all act the same. Further down in that post it is proposed to tackle the problem as follows:
Perhaps you can spin this functionality off into a separate process that has super-user permissions, leaving the rest of your app in normal user mode? I believe there's also a way to request root permissions for just a specific action taken by your program.
Now if this is a possible solution I would love to implement it! So my question is: how? I've stumbled upon running scripts with elevated permissions, but not just CoreGraphics code as for example an CGEventTap. Is this possible? Could anybody give me an example of how this could be accomplished, or any other solution to the problem?
All help is welcome, thank you very very much.
From Apple documentation:
Event taps receive key up and key down events if one of the following conditions is true:
- The current process is running as the root user.
- Access for assistive devices is enabled. In OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.
So giving the the application Accessibility rights solved it for me (no need to run as admin). This can be achieved System Preferences -> Security & Privacy -> Accessibility and add you program there.

Word COM in scheduled task on Windows Server

I have an application that uses COM to automate Word. It needs to run even when a user is not logged in. I achieved this on Windows 7 by making it run as a scheduled task which runs at startup and doesn't require a user to be logged on. I also had to use the 'hack' where you add a 'Desktop' folder in 'C:/Windows/SysWow64/config/systemprofile'.
I tried this same method in Windows Server 2012, but it doesn't work. I can see in the task scheduler that the application is starting an instance of Word. However, it then appears to 'hang' and nothing happens. I think perhaps the invisible instance of Word is showing an error message which causes the whole thing to hang, as I cannot dismiss the message.
Has anyone else had trouble getting COM to work on windows server? Is there any way of showing hidden instances of Word to see if an error dialog is showing? Or any other way of diagnosing what the problem is?
I know ideally we would have an app that created the word documents without using COM, but this is not an option at the moment.
Does your app work when run as a logged-in user?
In the past I've run into what sound like similar problems, when running programs that try to use COM interfaces; some tasks work, but others simply don't function unless run as a logged-in user with an interactive desktop.
For me the simplest solution was to set up the machine to log in as a user at boot (which you can set up in the control panel - or I think there might also be a sysinternals tool that supports configuring that nowadays), then make sure that task scheduler/Jenkins/whatever you use launches the app as the logged-in user.

How to find out more about Application Hang event?

If a VB6 app is causing an Application Hang event to appear in the Event Viewer, how can I find out more about why the application is hanging?
Does an Application Hang event mean that the app has frozen and crashed, or just that it temporarily hangs?
All I get in the event log for this event is:
Hanging application [MyAppName].exe, version [MyAppVersionNo], hang module hungapp, version 0.0.0.0, hang address 0x00000000.
That is not enough and I want to be able to find out more about why it is hanging. What code changes or other steps need to be taken to cause the app to provide more details in the event log?
I recommend using the Windows Performance Toolkit. The best version to use is in the Windows Assessment & Deployment Kit, http://www.microsoft.com/download/en/details.aspx?id=28997
Once it's installed, what you do is start up Windows Performance Recorder (WPR) and click the Start button to begin recording. Next, reproduce the problem with your app. Then go back to WPR and press the Save button. Next, load up Windows Performance Analyzer and open that *.ETL file that was generated. Then you want to go to System Activity section in the Graph Explorer, expand it, and find the UI Delays graph (or it might be the first graph parked on System Activity). Double click on it to get the detailed version in an Analysis tab.
Once you find the UI delay you're interested in, you can add another graph such as CPU Usage (Sampled) from the Processing node in Graph Explorer. When the two graphs are in the same Analysis tab, their scrolling and selection will be synchronized. So you can click on the UI delay event and it will also highlight the corresponding range in CPU Usage.
The Application Hang event means that Windows has decided that the application is unresponsive. Since the event is generated by the operating system and not the application, your options for getting additional information in the event are extremely limited.
This is what seems to be available on an Application Hang event:
Message: Hanging application %1, version %2, hang module %3, version %4, hang address 0x%5.
From:
http://www.microsoft.com/technet/support/ee/transform.aspx?ProdName=Windows+Operating+System&ProdVer=5.2&EvtID=1002&EvtSrc=Application+Hang&LCID=1033
If you believe the cause of the event is something that your application does (as opposed to something in the environment where the application is running), then instead of trying to pass info to the hang event, you should raise the level of log info to debug mode and look in your application's log file to see what it is doing just prior to becoming unresponsive.
If you lack logging information, or a logging framework in your application, then that is where you should be focusing your efforts. The upside is that you will benefit from better logging in the future as well. Use a logging framework however, so you can disable debug level logging in a production environment, when everything is running smoothly.
I would approach this by reviewing the code in the module that Windows has determined has hung, the name of which was written to the event log. Attempting to get more detail in the hang event will not be possible because when Windows has determined the app is unresponsive, it is too late.
Into the module that is hanging I would add multiple calls to DoEvents as well as logging status messages directly into the EventLog. Adding a logging framework at this point would introduce complexity and involve either a database or file access in which to store the logs.
Windows thinks the app has hung because it has stopped responding to messages. Unfortunately, implementing a second thread in your VB6 app is not trivial, unlike .NET. Never-the-less, adding another thread would keep the app responsive, but then you would likely still be left with answering the question, "why is the code taking so long to execute?"
Getting information from windows event perspective will not help. Try to have tracing in your application which helps you to get the exact cause.

Drag and drop on Win7 machine to my app

I have a user that is currently running my Winforms app on Win7. My app allows users to select rows from an open Excel spreadsheet and drag-n-drop them onto the app. However, this user cannot do the drag-n-drop. The cursor changes to the "no" cursor (little circle with line through it) and the operation won't complete.
I was researching drag-n-drop and Win7 and everything I found points to UAC and/or UIPI. I was looking for some solutions and am not sure if any of the below would work:
If the user logs in as admin (and as a result runs my app as admin) would that allow drag-n-drop to work?
Does the user need to turn off or change the settings of UAC/UIPI in order to be able to drag-n-drop?
I am not sure what the issue is. My app usually runs from C:/Documents and Settings/... (C:/Users/... on Win7). Does where it is running from matter? Does drag-n-drop not work because the user is not running my app with enough permissions? Are his Excel and my app on different permission levels? If so, what can be done about that? Note that even though my app allows users to just drag the file directly, that doesn't work either.
Also, is there any way I can have the user reproduce this issue with other apps? Are there apps that come with Win7 that he can see the same problem with. For example, can this be reproduced using Notepad?
Thanks.
Explaining this problem away by UIPI is a very long stretch. It doesn't have anything to do with whether or not the user is logged-in as an admin, that doesn't affect UAC and your program will be running with that same account anyway. The only way UIPI could kick in to stop a D+D is when your program is elevated and Excel is not.
To get yourself elevated requires work and doesn't happen by accident. You'd have to include a manifest so that the user gets the UAC prompt, you'd know about that. Or the user would have to change the desktop shortcut and tick the "Run this program as an administrator" option, she's know about that. While UIPI can be bypassed for Windows messages (ChangeWindowMessageFilter), it cannot for Drag and Drop so if any elevation is going on then your stuck. The ultimate test is to simply ask the user to put the UAC slider all the way down.
The much more likely scenario is that your DragEnter event handler simply isn't happy with the data it sees and therefore doesn't assign the e.Effect property. If you can't get a debugger on-site then write a little test program that logs the values of e.Data.GetFormats() plus whatever else you use to check if the drop is acceptable. And don't forget the obvious: the user simply fumbling the drag somehow.

Resources