Skip to content

Commit

Permalink
Update systemd/D-Bus support, add launchd support, add install/uninst…
Browse files Browse the repository at this point in the history
…all of service files.
  • Loading branch information
michaelrsweet committed Nov 4, 2023
1 parent e74d5c2 commit 159a9b5
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/config.status
/configure~
/daemon/cups-locald
/daemon/cups-locald.service
/daemon/cups-locald-dbus.service
/daemon/cups-locald-systemd.service
/daemon/org.openprinting.cups-locald.plist
/Makedefs
1 change: 1 addition & 0 deletions Makedefs.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ sysconfdir = @sysconfdir@
top_srcdir = @top_srcdir@
CUPS_LOCAL_DATADIR = @CUPS_LOCAL_DATADIR@
DBUSDIR = @DBUSDIR@
SYSTEMDDIR = @SYSTEMDDIR@

BUILDROOT = $(DSTROOT)$(RPM_BUILD_ROOT)$(DESTDIR)

Expand Down
73 changes: 62 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ LIBOBJS
CUPS_LOCAL_DATADIR
WARNINGS
CSFLAGS
SYSTEMDDIR
DBUSDIR
PKGCONFIG
INSTALL
Expand Down Expand Up @@ -689,6 +690,7 @@ ac_user_opts='
enable_option_checking
enable_dbus
with_dbusdir
with_systemddir
enable_debug
enable_maintainer
enable_sanitizer
Expand Down Expand Up @@ -1333,6 +1335,7 @@ Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-dbusdir set D-Bus configuration directory
--with-systemddir set systemd configuration directory
--with-ldflags=... Specify additional LDFLAGS
Some influential environment variables:
Expand Down Expand Up @@ -3841,6 +3844,7 @@ fi


DBUSDIR=""
SYSTEMDDIR=""

# Check whether --enable-dbus was given.
if test ${enable_dbus+y}
Expand All @@ -3858,6 +3862,15 @@ then :
fi


# Check whether --with-systemddir was given.
if test ${with_systemddir+y}
then :
withval=$with_systemddir;
SYSTEMDDIR="$withval"

fi



if test "x$enable_dbus" != xno
then :
Expand All @@ -3869,6 +3882,34 @@ then :

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
have_dbus=1

else $as_nop

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
have_dbus=0

fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for systemd" >&5
printf %s "checking for systemd... " >&6; }
if $PKGCONFIG --exists systemd
then :

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
have_systemd=1

else $as_nop

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
have_systemd=0

fi
if test $have_dbus = 1 -a $have_systemd = 1
then :


printf "%s\n" "#define HAVE_DBUS 1" >>confdefs.h

Expand All @@ -3894,27 +3935,35 @@ printf "%s\n" "#define HAVE_DBUS_THREADS_INIT 1" >>confdefs.h

fi

if test -d /etc/dbus-1 -a "x$DBUSDIR" = x
if test "x$DBUSDIR" = x
then :

DBUSDIR="$($PKGCONFIG --variable=datadir dbus-1)/dbus-1"

fi
if test "x$DBUSDIR" = x
then :

DBUSDIR="/etc/dbus-1"
as_fn_error $? "No default D-Bus directory found, use --with-dbusdir option." "$LINENO" 5

elif test -d /usr/local/etc/dbus-1 -a "x$DBUSDIR" = x
fi
if test "x$SYSTEMDDIR" = x
then :

DBUSDIR="/usr/local/etc/dbus-1"
DBUSDIR="$($PKGCONFIG --variable=systemd_util_dir systemd)"

elif test "x$DBUSDIR" = x
fi
if test "x$SYSTEMDDIR" = x
then :

as_fn_error $? "No default D-Bus directory found, use --with-dbus-dir option." "$LINENO" 5
as_fn_error $? "No default systemd directory found, use --with-systemddir option." "$LINENO" 5

fi

else $as_nop
elif test "$xenable_dbus" = xyes
then :

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
as_fn_error $? "Required D-Bus library and systemd are missing." "$LINENO" 5

fi

Expand All @@ -3923,6 +3972,7 @@ fi




# Check whether --enable-debug was given.
if test ${enable_debug+y}
then :
Expand Down Expand Up @@ -4185,7 +4235,7 @@ printf "%s\n" "#define CUPS_LOCAL_DATADIR \"$datadir/cups-local\"" >>confdefs.h



ac_config_files="$ac_config_files Makedefs daemon/cups-locald.service daemon/cups-locald-dbus.service"
ac_config_files="$ac_config_files Makedefs daemon/cups-locald-dbus.service daemon/cups-locald-systemd.service daemon/org.openprinting.cups-locald.plist"

cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
Expand Down Expand Up @@ -4874,8 +4924,9 @@ do
case $ac_config_target in
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
"Makedefs") CONFIG_FILES="$CONFIG_FILES Makedefs" ;;
"daemon/cups-locald.service") CONFIG_FILES="$CONFIG_FILES daemon/cups-locald.service" ;;
"daemon/cups-locald-dbus.service") CONFIG_FILES="$CONFIG_FILES daemon/cups-locald-dbus.service" ;;
"daemon/cups-locald-systemd.service") CONFIG_FILES="$CONFIG_FILES daemon/cups-locald-systemd.service" ;;
"daemon/org.openprinting.cups-locald.plist") CONFIG_FILES="$CONFIG_FILES daemon/org.openprinting.cups-locald.plist" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
Expand Down
43 changes: 34 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,34 @@ AS_IF([$PKGCONFIG --exists pappl --atleast-version=2.0], [

dnl Check for DBUS support
DBUSDIR=""
SYSTEMDDIR=""

AC_ARG_ENABLE([dbus], AS_HELP_STRING([--disable-dbus], [build without D-Bus support]))
AC_ARG_WITH([dbusdir], AS_HELP_STRING([--with-dbusdir], [set D-Bus configuration directory]), [
DBUSDIR="$withval"
])
AC_ARG_WITH([systemddir], AS_HELP_STRING([--with-systemddir], [set systemd configuration directory]), [
SYSTEMDDIR="$withval"
])

AS_IF([test "x$enable_dbus" != xno], [
AC_MSG_CHECKING([for D-Bus])
AS_IF([$PKGCONFIG --exists dbus-1], [
AC_MSG_RESULT([yes])
have_dbus=1
], [
AC_MSG_RESULT([no])
have_dbus=0
])
AC_MSG_CHECKING([for systemd])
AS_IF([$PKGCONFIG --exists systemd], [
AC_MSG_RESULT([yes])
have_systemd=1
], [
AC_MSG_RESULT([no])
have_systemd=0
])
AS_IF([test $have_dbus = 1 -a $have_systemd = 1], [
AC_DEFINE([HAVE_DBUS], [1], [Have dbus library?])
CPPFLAGS="$CPPFLAGS $($PKGCONFIG --cflags dbus-1) -DDBUS_API_SUBJECT_TO_CHANGE"
LIBS="$($PKGCONFIG --libs dbus-1) $LIBS"
Expand All @@ -124,19 +142,25 @@ AS_IF([test "x$enable_dbus" != xno], [
AC_CHECK_FUNC([dbus_threads_init_default], [
AC_DEFINE([HAVE_DBUS_THREADS_INIT], [1], [Have dbus_threads_init_default function?])
])
AS_IF([test -d /etc/dbus-1 -a "x$DBUSDIR" = x], [
DBUSDIR="/etc/dbus-1"
], [test -d /usr/local/etc/dbus-1 -a "x$DBUSDIR" = x], [
DBUSDIR="/usr/local/etc/dbus-1"
], [test "x$DBUSDIR" = x], [
AC_MSG_ERROR([No default D-Bus directory found, use --with-dbus-dir option.])
AS_IF([test "x$DBUSDIR" = x], [
DBUSDIR="$($PKGCONFIG --variable=datadir dbus-1)/dbus-1"
])
], [
AC_MSG_RESULT([no])
AS_IF([test "x$DBUSDIR" = x], [
AC_MSG_ERROR([No default D-Bus directory found, use --with-dbusdir option.])
])
AS_IF([test "x$SYSTEMDDIR" = x], [
DBUSDIR="$($PKGCONFIG --variable=systemd_util_dir systemd)"
])
AS_IF([test "x$SYSTEMDDIR" = x], [
AC_MSG_ERROR([No default systemd directory found, use --with-systemddir option.])
])
], [test "$xenable_dbus" = xyes], [
AC_MSG_ERROR([Required D-Bus library and systemd are missing.])
])
])

AC_SUBST([DBUSDIR])
AC_SUBST([SYSTEMDDIR])


dnl Extra compiler options...
Expand Down Expand Up @@ -272,7 +296,8 @@ AC_SUBST([CUPS_LOCAL_DATADIR])
dnl Generate a bunch of files...
AC_CONFIG_FILES([
Makedefs
daemon/cups-locald.service
daemon/cups-locald-dbus.service
daemon/cups-locald-systemd.service
daemon/org.openprinting.cups-locald.plist
])
AC_OUTPUT
29 changes: 29 additions & 0 deletions daemon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ install:
echo Installing cups-locald to $(BUILDROOT)$(sbindir)
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(sbindir)
$(INSTALL_BIN) cups-locald $(BUILDROOT)$(sbindir)
if test "x$(DBUSDIR)" != x; then \
echo Installing D-Bus files to $(BUILDROOT)$(DBUSDIR); \
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(DBUSDIR)/interfaces; \
$(INSTALL_DATA) org.openprinting.cups-locald.xml $(BUILDROOT)$(DBUSDIR)/interfaces; \
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(DBUSDIR)/services; \
$(INSTALL_DATA) cups-locald-dbus.service $(BUILDROOT)$(DBUSDIR)/services/cups-locald.service; \
fi
if test "x$$(uname)" = xDarwin; then \
echo Installing launchd files to $(BUILDROOT)/Library/LaunchAgents; \
$(INSTALL_DIR) -m 755 $(BUILDROOT)/Library/LaunchAgents; \
$(INSTALL_DATA) org.openprinting.cups-locald.plist $(BUILDROOT)/Library/LaunchAgents; \
elif test "x$(SYSTEMDDIR)" != x; then \
echo Installing systemd files to $(BUILDROOT)$(SYSTEMDDIR); \
$(INSTALL_DIR) -m 755 $(BUILDROOT)$(SYSTEMDDIR)/user; \
$(INSTALL_DATA) cups-locald-systemd.service $(BUILDROOT)$(SYSTEMDDIR)/user/cups-locald.service; \
fi


#
Expand All @@ -66,6 +82,19 @@ install:
uninstall:
$(RM) $(BUILDROOT)$(sbindir)/cups-locald
-$(RMDIR) $(BUILDROOT)$(sbindir)
if test "x$(DBUSDIR)" != x; then \
$(RM) $(BUILDROOT)$(DBUSDIR)/interfaces/org.openprinting.cups-locald.xml; \
$(RMDIR) $(BUILDROOT)$(DBUSDIR)/interfaces; \
$(RM) $(BUILDROOT)$(DBUSDIR)/services/cups-locald.service; \
$(RMDIR) $(BUILDROOT)$(DBUSDIR)/services; \
fi
if test "x$$(uname)" = xDarwin; then \
$(RM) $(BUILDROOT)/Library/LaunchAgents/org.openprinting.cups-locald.plist; \
$(RMDIR) $(BUILDROOT)/Library/LaunchAgents; \
elif test "x$(SYSTEMDDIR)" != x; then \
$(RM) $(BUILDROOT)$(SYSTEMDDIR)/user/cups-locald.service; \
$(RMDIR) $(BUILDROOT)$(SYSTEMDDIR)/user; \
fi


#
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions daemon/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

//
// The D-Bus API is used to start cups-locald and return the proper Unix
// domain socket to use. The interface is "org.openprinting.cups-locald".
// domain socket to use.
//
// Method: GetSocket
//
// Get the Unix domain socket path for the current session. There are no
// arguments. The reply contains a single string containing the socket path.
// node /org/openprinting
// interface org.openprinting.cups-locald
// methods:
// GetSocket(out s socketpath);
//


Expand Down
22 changes: 22 additions & 0 deletions daemon/org.openprinting.cups-locald.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.openprinting.cups-locald</string>
<key>ProgramArguments</key>
<array>
<string>@sbindir@/cups-locald</string>
</array>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<array>
<dict>
<key>SecureSocketWithKey</key>
<string>CUPS_SERVER</string>
</dict>
</array>
</dict>
</dict>
</plist>
8 changes: 8 additions & 0 deletions daemon/org.openprinting.cups-locald.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.openprinting.cups-locald">
<method name="GetSocket">
<arg type="s" direction="out"/>
</method>
</interface>
</node>

0 comments on commit 159a9b5

Please sign in to comment.