Skip to content

Commit

Permalink
Update to support launchd on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Nov 6, 2023
1 parent 785f46b commit 32c0096
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define CUPS_LOCAL_MAIN_C
#include "cups-locald.h"
#include <cups/thread.h>
#ifdef __APPLE__
# include <launch.h>
#endif // __APPLE__


//
Expand Down Expand Up @@ -214,8 +217,38 @@ main(int argc, // I - Number of command-line arguments
papplSystemSetSaveCallback(system, (pappl_save_cb_t)papplSystemSaveState, (void *)LocalStateFile);

// Setup domain socket and loopback listeners
#ifdef __APPLE__
if (!strcmp(LocalSocket, "launchd"))
{
// Support sockets from launchd...
int error; // Check-in error, if any
size_t i, // Looping var
ld_count; // Number of listeners
int *ld_sockets; // Listener sockets

if ((error = launch_activate_socket("Listeners", &ld_sockets, &ld_count)) != 0)
{
cupsLangPrintf(stderr, _("cups-locald: Unable to get listener sockets: %s"), strerror(error));
return (1);
}

for (i = 0; i < ld_count; i ++)
{
http_addr_t addr; // Socket address
socklen_t addrlen; // Length of socket address

papplSystemAddListenerFd(system, ld_sockets[i]);

addrlen = sizeof(addr);
if (!getsockname(ld_sockets[i], (struct sockaddr *)&addr, &addrlen) && addr.addr.sa_family == AF_LOCAL)
httpAddrGetString(&addr, LocalSocket, sizeof(LocalSocket));
}
}
else
#endif // __APPLE__
papplSystemAddListeners(system, LocalSocket);
papplSystemAddListeners(system, "localhsot");

papplSystemAddListeners(system, "localhost");

// Setup the generic drivers...
papplSystemSetPrinterDrivers(system, sizeof(LocalDrivers) / sizeof(LocalDrivers[0]), LocalDrivers, LocalDriverAutoAdd, /* create_cb */NULL, LocalDriverCallback, NULL);
Expand Down
2 changes: 2 additions & 0 deletions daemon/org.openprinting.cups-locald.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<key>ProgramArguments</key>
<array>
<string>@sbindir@/cups-locald</string>
<string>-S</string>
<string>launchd</string>
</array>
<key>Sockets</key>
<dict>
Expand Down

0 comments on commit 32c0096

Please sign in to comment.