Lines 26-31
Link Here
|
26 |
* launchd_checkin() - Check-in with launchd and collect the listening |
26 |
* launchd_checkin() - Check-in with launchd and collect the listening |
27 |
* fds. |
27 |
* fds. |
28 |
* launchd_checkout() - Update the launchd KeepAlive file as needed. |
28 |
* launchd_checkout() - Update the launchd KeepAlive file as needed. |
|
|
29 |
* systemd_checkin() - Check-in with systemd and collect the |
30 |
* listening fds. |
29 |
* parent_handler() - Catch USR1/CHLD signals... |
31 |
* parent_handler() - Catch USR1/CHLD signals... |
30 |
* process_children() - Process all dead children... |
32 |
* process_children() - Process all dead children... |
31 |
* select_timeout() - Calculate the select timeout value. |
33 |
* select_timeout() - Calculate the select timeout value. |
Lines 62-67
Link Here
|
62 |
# endif /* !LAUNCH_JOBKEY_SERVICEIPC */ |
64 |
# endif /* !LAUNCH_JOBKEY_SERVICEIPC */ |
63 |
#endif /* HAVE_LAUNCH_H */ |
65 |
#endif /* HAVE_LAUNCH_H */ |
64 |
|
66 |
|
|
|
67 |
#ifdef HAVE_SYSTEMD |
68 |
#include <systemd/sd-daemon.h> |
69 |
#endif /* HAVE_SYSTEMD */ |
70 |
|
65 |
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO) |
71 |
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO) |
66 |
# include <malloc.h> |
72 |
# include <malloc.h> |
67 |
#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */ |
73 |
#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */ |
Lines 78-83
Link Here
|
78 |
static void launchd_checkin(void); |
84 |
static void launchd_checkin(void); |
79 |
static void launchd_checkout(void); |
85 |
static void launchd_checkout(void); |
80 |
#endif /* HAVE_LAUNCHD */ |
86 |
#endif /* HAVE_LAUNCHD */ |
|
|
87 |
#ifdef HAVE_SYSTEMD |
88 |
static void systemd_checkin(void); |
89 |
#endif /* HAVE_SYSTEMD */ |
81 |
static void parent_handler(int sig); |
90 |
static void parent_handler(int sig); |
82 |
static void process_children(void); |
91 |
static void process_children(void); |
83 |
static void sigchld_handler(int sig); |
92 |
static void sigchld_handler(int sig); |
Lines 537-542
main(int argc, /* I - Number of comm
Link Here
|
537 |
} |
546 |
} |
538 |
#endif /* HAVE_LAUNCHD */ |
547 |
#endif /* HAVE_LAUNCHD */ |
539 |
|
548 |
|
|
|
549 |
#ifdef HAVE_SYSTEMD |
550 |
/* |
551 |
* If we were started by systemd get the listen sockets file descriptors... |
552 |
*/ |
553 |
systemd_checkin(); |
554 |
#endif /* HAVE_SYSTEMD */ |
555 |
|
540 |
/* |
556 |
/* |
541 |
* Startup the server... |
557 |
* Startup the server... |
542 |
*/ |
558 |
*/ |
Lines 759-764
main(int argc, /* I - Number of comm
Link Here
|
759 |
} |
775 |
} |
760 |
#endif /* HAVE_LAUNCHD */ |
776 |
#endif /* HAVE_LAUNCHD */ |
761 |
|
777 |
|
|
|
778 |
#ifdef HAVE_SYSTEMD |
779 |
/* |
780 |
* If we were started by systemd get the listen sockets file |
781 |
* descriptors... |
782 |
*/ |
783 |
|
784 |
systemd_checkin(); |
785 |
#endif /* HAVE_SYSTEMD */ |
786 |
|
762 |
/* |
787 |
/* |
763 |
* Startup the server... |
788 |
* Startup the server... |
764 |
*/ |
789 |
*/ |
Lines 1584-1589
launchd_checkout(void)
Link Here
|
1584 |
} |
1609 |
} |
1585 |
#endif /* HAVE_LAUNCHD */ |
1610 |
#endif /* HAVE_LAUNCHD */ |
1586 |
|
1611 |
|
|
|
1612 |
#ifdef HAVE_SYSTEMD |
1613 |
static void |
1614 |
systemd_checkin(void) |
1615 |
{ |
1616 |
int n, fd; |
1617 |
|
1618 |
n = sd_listen_fds(0); |
1619 |
if (n < 0) |
1620 |
{ |
1621 |
cupsdLogMessage(CUPSD_LOG_ERROR, |
1622 |
"systemd_checkin: Failed to acquire sockets from systemd - %s", |
1623 |
strerror(-n)); |
1624 |
exit(EXIT_FAILURE); |
1625 |
return; |
1626 |
} |
1627 |
|
1628 |
if (n == 0) |
1629 |
return; |
1630 |
|
1631 |
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++) |
1632 |
{ |
1633 |
http_addr_t addr; |
1634 |
socklen_t addrlen = sizeof (addr); |
1635 |
int r; |
1636 |
cupsd_listener_t *lis; |
1637 |
char s[256]; |
1638 |
|
1639 |
r = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1); |
1640 |
if (r < 0) { |
1641 |
cupsdLogMessage(CUPSD_LOG_ERROR, |
1642 |
"systemd_checkin: Unable to verify socket type - %s", |
1643 |
strerror(-r)); |
1644 |
continue; |
1645 |
} |
1646 |
|
1647 |
if (!r) { |
1648 |
cupsdLogMessage(CUPSD_LOG_ERROR, |
1649 |
"systemd_checkin: Socket not of the right type"); |
1650 |
continue; |
1651 |
} |
1652 |
|
1653 |
if (getsockname(fd, (struct sockaddr*) &addr, &addrlen)) |
1654 |
{ |
1655 |
cupsdLogMessage(CUPSD_LOG_ERROR, |
1656 |
"systemd_checkin: Unable to get local address - %s", |
1657 |
strerror(errno)); |
1658 |
continue; |
1659 |
} |
1660 |
|
1661 |
/* |
1662 |
* Try to match the systemd socket address to one of the listeners... |
1663 |
*/ |
1664 |
|
1665 |
for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); |
1666 |
lis; |
1667 |
lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) |
1668 |
if (httpAddrEqual(&lis->address, &addr)) |
1669 |
break; |
1670 |
|
1671 |
if (lis) |
1672 |
{ |
1673 |
cupsdLogMessage(CUPSD_LOG_DEBUG, |
1674 |
"systemd_checkin: Matched existing listener %s with fd %d...", |
1675 |
httpAddrString(&(lis->address), s, sizeof(s)), fd); |
1676 |
} |
1677 |
else |
1678 |
{ |
1679 |
cupsdLogMessage(CUPSD_LOG_DEBUG, |
1680 |
"systemd_checkin: Adding new listener %s with fd %d...", |
1681 |
httpAddrString(&addr, s, sizeof(s)), fd); |
1682 |
|
1683 |
if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL) |
1684 |
{ |
1685 |
cupsdLogMessage(CUPSD_LOG_ERROR, |
1686 |
"systemd_checkin: Unable to allocate listener - " |
1687 |
"%s.", strerror(errno)); |
1688 |
exit(EXIT_FAILURE); |
1689 |
} |
1690 |
|
1691 |
cupsArrayAdd(Listeners, lis); |
1692 |
|
1693 |
memcpy(&lis->address, &addr, sizeof(lis->address)); |
1694 |
} |
1695 |
|
1696 |
lis->fd = fd; |
1697 |
lis->is_systemd = 1; |
1698 |
|
1699 |
# ifdef HAVE_SSL |
1700 |
if (_httpAddrPort(&(lis->address)) == 443) |
1701 |
lis->encryption = HTTP_ENCRYPT_ALWAYS; |
1702 |
# endif /* HAVE_SSL */ |
1703 |
} |
1704 |
} |
1705 |
#endif /* HAVE_SYSTEMD */ |
1587 |
|
1706 |
|
1588 |
/* |
1707 |
/* |
1589 |
* 'parent_handler()' - Catch USR1/CHLD signals... |
1708 |
* 'parent_handler()' - Catch USR1/CHLD signals... |