• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Patching _ExitToShell for application cleanup: any experience?

cheesestraws

Well-known member
When talking about making sure you don't have any outstanding VBL tasks when a process exits, IM:processes helpfully suggests:

The easiest way to avoid this problem is to patch the Process Manager’s ExitToShell procedure so that it removes all VBL task records installed by your application.

I'm not sure about "easiest", but this procedure sounds both very useful and fraught with danger. Has anyone done it before?
 

atax1a

Member
coincidentally, we just read through the first issue of Develop which has opinions on just this topic:

Suppose, for example, you decide to patch ExitToShell. This may sound like an excellent way for your program to get one last chance at closing files or doing whatever other cleanup is necessary before exiting. Whether ExitToShell is called in response to a user’s Quit command or because of some fatal error condition, your patch would always have a chance to clean up. But rather than having ExitToShells all over your code, you could achieve the same result by calling a single, common exit routine that performed the cleanup and then called ExitToShell.
Hope this helps :)
 

Crutch

Well-known member
I have actually tried this from an INIT and found that, at least in 7.5.5, it seems to be impossible to patch ExitToShell at INIT time because someone (the Process Manager?) installs a patch at some later time (before launching the Finder) that simply wipes out whatever was there. (This does not mean that you couldn’t patch ExitToShell in the application heap, which I have not tried.) I recall the same being true of WaitNextEvent, incidentally.

FWIW though I don’t think that develop article was saying there is anything particularly wrong with patching ExitToShell. Pretty sure it was just the usual “avoid patching generally” screed that was common from Apple, with ExitToShell a random example. (That issue of develop predates System 7, of course.)
 
Top