Launchd alternatives

1

I am writing an application that uses a library that will not work when the application is run as a launchd daemon. There is a bug in the library where it will throw a bus error when used from a daemon. (See my stack overflow post: https://stackoverflow.com/questions/20599283/signal-10-sigbus-in-c-library-when-running-application-as-launchd-daemon)

Everything works fine however, when I run the application normally. I am wondering if there are any alternatives to launchd I should consider. The application needs to start on boot and run even when no users are logged in. It would also be preferable that the application is relaunched if it crashes, but I can live without that if I have to.

I've done some research on startup items, but since they are deprecated, I am wary that Apple will just remove the functionality some day.

Eric Milas

Posted 2013-12-19T18:15:31.687

Reputation: 113

Answers

2

No. You'll very probably hit the exact same problem with any alternative as you are getting here.

Without going into too much detail of what's obvious from the stack trace, which is StackOverflow territory:

The problem is almost certainly down to the different process state that a daemon has, compared to a program that you run from a desktop or a shell. Environment variables, the current directory, resource limits, open file handles, controlling terminals, root directory, and even supplementary groups can be — and for most of those are — different in a dæmon process run from a dæmon supervisor from a process invoked in a login session.

Your problem could be down to any difference between the twain. (My educated guess is environment variables, because of what's in the stack trace.) But these differences are inherent in dæmon supervisors. Executing dæmons with fixed, determinable, process states is part of their design. If you substitute another dæmon supervisor, you'll still get a controlled process state that doesn't match that of processes run in your login session.

You shouldn't be considering alternatives to launchd. You should be looking at your plist and adjusting it to set up the right stuff (probably environment variables, as I said) that your ODBC driver expects to have available to it. And you should be reading whatever 4D doco there is. ☺

JdeBP

Posted 2013-12-19T18:15:31.687

Reputation: 23 855

JdeBP was actually able to solve the original problem, you can see the answer here

– Eric Milas – 2013-12-20T00:43:12.823