Added optional support in saned for systemd socket activation. This will allow for

using backend debugging using SANE_DEBUG_xxx to be used for saned controlled
scanning when using socket activation. When only the socket is received we
use the existing code path.
merge-requests/1/head
Louis Lagendijk 2013-01-10 20:59:26 +01:00
rodzic d7d4437550
commit 3276babdec
15 zmienionych plików z 124 dodań i 39 usunięć

Wyświetl plik

@ -234,6 +234,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -1619,6 +1619,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

15
configure vendored
Wyświetl plik

@ -657,6 +657,7 @@ SCSI_LIBS
USB_LIBS
LIBUSB_1_0_LIBS
LIBUSB_1_0_CFLAGS
SYSTEMD_LIBS
ALLOCA
LIBOBJS
SOCKET_LIBS
@ -9559,6 +9560,20 @@ else
with_cups="no"
fi
$as_echo_n "Checking for systemd..."
if test -e /usr/include/systemd/sd-daemon.h ; then
$as_echo "#define HAVE_SYSTEMD 1" >>confdefs.h
with_systemd="yes"
SYSTEMD_LIBS=" -lsystemd-daemon"
$as_echo "yes"
else
with_systemd="no"
$as_echo "no"
fi
# Check whether --enable-libusb_1_0 was given.
if test "${enable_libusb_1_0+set}" = set; then :

Wyświetl plik

@ -338,6 +338,19 @@ else
with_cups="no"
fi
dnl added by llagendijk 12/7/2012 to detect systemd for saned
$as_echo_n "Checking for systemd..."
if test -e /usr/include/systemd/sd-daemon.h ; then
AC_DEFINE(HAVE_SYSTEMD, 1, [Is /usr/include/systemd/sd-daemon.h available?])
with_systemd="yes"
SYSTEMD_LIBS=" -lsystemd-daemon"
AC_SUBST(SYSTEMD_LIBS)
$as_echo "yes"
else
with_systemd="no"
$as_echo "no"
fi
dnl ***********
dnl USB Support
dnl ***********

Wyświetl plik

@ -198,6 +198,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -22,7 +22,7 @@ scanimage_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
saned_SOURCES = saned.c
saned_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
../lib/libfelib.la @SYSLOG_LIBS@
../lib/libfelib.la @SYSLOG_LIBS@ @SYSTEMD_LIBS@
test_SOURCES = test.c
test_LDADD = ../lib/liblib.la ../lib/libfelib.la ../backend/libsane.la

Wyświetl plik

@ -196,6 +196,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@
@ -265,7 +266,7 @@ scanimage_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
saned_SOURCES = saned.c
saned_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
../lib/libfelib.la @SYSLOG_LIBS@
../lib/libfelib.la @SYSLOG_LIBS@ @SYSTEMD_LIBS@
test_SOURCES = test.c
test_LDADD = ../lib/liblib.la ../lib/libfelib.la ../backend/libsane.la

Wyświetl plik

@ -82,7 +82,6 @@
#include <pwd.h>
#include <grp.h>
#if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL)
# include <sys/poll.h>
#else
@ -175,6 +174,10 @@ static AvahiSimplePoll *avahi_poll = NULL;
static AvahiEntryGroup *avahi_group = NULL;
#endif /* WITH_AVAHI */
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include "../include/sane/sane.h"
#include "../include/sane/sanei.h"
@ -3171,43 +3174,70 @@ run_standalone (int argc, char **argv)
static void
run_inetd (int argc, char **argv)
{
int fd = 1;
int dave_null;
int fd = -1;
/* Some backends really can't keep their dirty fingers off
* stdin/stdout/stderr; we work around them here so they don't
* mess up the network dialog and crash the remote net backend.
*/
do
#ifdef HAVE_SYSTEMD
int n;
n = sd_listen_fds(0);
if (n > 1)
{
fd = dup (fd);
if (fd == -1)
{
DBG (DBG_ERR, "run_inetd: duplicating fd failed: %s", strerror (errno));
return;
}
}
while (fd < 3);
/* Our good'ole friend Dave Null to the rescue */
dave_null = open ("/dev/null", O_RDWR);
if (dave_null < 0)
{
DBG (DBG_ERR, "run_inetd: could not open /dev/null: %s", strerror (errno));
DBG (DBG_ERR, "run_inetd: Too many file descriptors (sockets) received from systemd!\n");
return;
}
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
if (n == 1)
{
fd = SD_LISTEN_FDS_START + 0;
DBG (DBG_INFO, "run_inetd: Using systemd socket %d!\n", fd);
}
#endif
dup2 (dave_null, STDIN_FILENO);
dup2 (dave_null, STDOUT_FILENO);
dup2 (dave_null, STDERR_FILENO);
if (fd == -1)
{
int dave_null;
close (dave_null);
/* Some backends really can't keep their dirty fingers off
* stdin/stdout/stderr; we work around them here so they don't
* mess up the network dialog and crash the remote net backend
* by messing with the inetd socket.
* For systemd this not an issue as systemd uses fd >= 3 for the
* socket and can even redirect stdout and stderr to syslog.
* We can even use this to get the debug logging
*/
do
{
/* get new fd for the inetd socket */
fd = dup (1);
if (fd == -1)
{
DBG (DBG_ERR, "run_inetd: duplicating fd failed: %s", strerror (errno));
return;
}
}
while (fd < 3);
/* Our good'ole friend Dave Null to the rescue */
dave_null = open ("/dev/null", O_RDWR);
if (dave_null < 0)
{
DBG (DBG_ERR, "run_inetd: could not open /dev/null: %s", strerror (errno));
return;
}
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
dup2 (dave_null, STDIN_FILENO);
dup2 (dave_null, STDOUT_FILENO);
dup2 (dave_null, STDERR_FILENO);
close (dave_null);
}
#ifndef HAVE_OS2_H
/* Unused in this function */
argc = argc;
@ -3232,6 +3262,7 @@ run_inetd (int argc, char **argv)
int
main (int argc, char *argv[])
{
char options[64] = "";
debug = DBG_WARN;
prog_name = strrchr (argv[0], '/');
@ -3276,16 +3307,29 @@ main (int argc, char *argv[])
wire.io.read = read;
wire.io.write = write;
/* define the version string depending on which network code is used */
#ifdef SANED_USES_AF_INDEP
strcat(options, "AF-indep");
# ifdef ENABLE_IPV6
DBG (DBG_WARN, "saned (AF-indep+IPv6) from %s starting up\n", PACKAGE_STRING);
# else
DBG (DBG_WARN, "saned (AF-indep) from %s starting up\n", PACKAGE_STRING);
# endif /* ENABLE_IPV6 */
strcat(options, "+IPv6");
#endif
#else
DBG (DBG_WARN, "saned from %s ready\n", PACKAGE_STRING);
#endif /* SANED_USES_AF_INDEP */
strcat(options, "IPv4 only");
#endif
#ifdef HAVE_SYSTEMD
if (sd_listen_fds(0) > 0)
{
strcat(options, "+systemd");
}
#endif
if (strlen(options) > 0)
{
DBG (DBG_WARN, "saned (%s) from %s starting up\n", options, PACKAGE_STRING);
}
else
{
DBG (DBG_WARN, "saned from %s ready\n", PACKAGE_STRING);
}
if ((run_mode == SANED_RUN_ALONE) || (run_mode == SANED_RUN_DEBUG))
{

Wyświetl plik

@ -182,6 +182,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -330,6 +330,9 @@
/* Define to 1 if you have the `syslog' function. */
#undef HAVE_SYSLOG
/* Is /usr/include/systemd/sd-daemon.h available? */
#undef HAVE_SYSTEMD
/* Define to 1 if you have the <sys/bitypes.h> header file. */
#undef HAVE_SYS_BITYPES_H

Wyświetl plik

@ -205,6 +205,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -181,6 +181,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -158,6 +158,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -196,6 +196,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@

Wyświetl plik

@ -218,6 +218,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
VERSION = @VERSION@