Reputation: 3414
I have a program and I want to ensure that it has been launched only by launchd (as a daemon) & it should terminate if the user launches it directly (double-click on Finder, terminal). Is there a nifty way of accomplishing this?
Upvotes: 0
Views: 49
Reputation: 12055
Assuming you're the one setting up the launchd plist that specifies how to launch your program, you could just add an EnvironmentVariables
entry to that plist with your own key (e.g. "I_CAME_FROM_LAUNCHD"), then have your program check for the presence of that environment variable using getenv
(or NSProcessInfo
, for Objective-C). If the program launches from the Finder, that variable won't be there, and you can terminate your program.
Upvotes: 1