XPC Service in C -- Illegal instruction: 4

Folks,

I've a bare bone XPC Service, built with Xcode 12.x.

I can get it work under Xcode interactive debugger. But from command line I get the Illegal instruction.

A similar project with XPC client don't see the problem.

Any help ?

Eventually it would be part of launchctl based daemon

TIA -P

Replies

Eventually it would be part of launchctl based daemon

In that case you should be careful about starting with an XPC Service. It’s fine to use that to play around with XPC (although there is a better way to do that; see below) but there are significant differences between the way you package an XPC Service and a launchd daemon that vends a named XPC listener:

In both cases there are limits to how your run your program:

  • An XPC Service can only be embedded in an app (or appex) and is automatically started by the system when the container app attempts to connect.

  • A launchd daemon must be loaded into launchd, typically by installing a launchd property list file. Once loaded, launchd starts the daemon when a client attempts to connect to one of its services.

I can get it work under Xcode interactive debugger.

Right. Xcode has special sauce that allows it to debug XPC Services. This does not apply to launchd daemons.

But from command line I get the illegal instruction.

Right. You can’t just run an XPC Service from the command line. It has to be launched in response to a connection from its container app.

Similarly, you can’t run a launchd daemon from the command line. Well, you can, but it’ll fail when it tries to check in with launchd.


My advice:

  • If you want to play around with XPC, just to get a feel for how the API works, use a loopback service. See this post for info on that.

  • When you eventually switch to using a launchd daemon, you must load it into launchd. Running it from Xcode isn’t supported.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks much Eskimo, as usual...

Le'me go thru all what U stated, and ref:

Appreciate it much !

-P

BY the way, I'm trying this using C API interface ( no Obj-C tho ).

We will have a launchctl based EP Security client, which we tested and seem to work fine ( note that we don not want any app related stuff, like canvas, delegates etc. ). At the start we will have a communication dylib that is going to field XPC based communication I mentioned here.

This is gong to be C and C++. XPC module could stay as C module.

Hope it does not create more problems !!

-P

Hope it does not create more problems !!

No, that all sounds feasible.

Let me reiterate that I recommend a two-phase bring up process. Do your initial XPC development within a single test process using XPC loopback and then integrate it into your launchd daemon. That lets you split the problem is half. You can debug all the basic XPC issues using loopback, with a single process that you can debug directly from Xcode. Then, once you have that nailed down, you can debug any problems related to the launchd integration.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"