Bug#858341: cups-daemon: please usr /run instead of /var/run

2017-03-21 Thread Didier 'OdyX' Raboud
Control: tags -1 +patch +pending

Hi there Russell; thanks for your report!

Le mercredi, 22 mars 2017, 00.30:13 h CET Russell Coker a écrit :
> /run has been around since 2011, I think it's time to stop using the
> /var/run symlink.  Supporting the symlink in SE Linux means supporting both
> names for the contexts used in the initial creation of files and
> directories which I want to remove.  Here's a patch to make cups not use
> /var/run:

Actually, if we are to remove /var/run usages, we might as well want to do it 
everywhere, and for all usages:
* /run/cups/$NAME.pid (in the pidfile.patch, and in the init script)
* /run/cups/printcap (through --with-printcap, managed in the postinst)
* /run/cups/certs (through --with-rundir, handled in the init script and in 
the upstart script)
* /run/cups/cups.sock (through --with-rundir, used in cups.postinst and 
trigger, in the upstart script as well as in the autopkgtest

A patch for that all is attached, and, given that we have experimental, I will 
upload that soon. Thanks for the heads' up!
-- 
OdyXAuthor: Didier Raboud 
Date:   Tue Mar 21 21:15:44 2017 +0100

Use /run instead of /var/run everywhere meaningful:

* /run/cups:
  - in debian/rules; pass --with-rundir=/run/cups
  - update cups.init
* /run/cups/cupsd.pid:
  - update cups.init
  - update pidfile.patch
* /run/cups/printcap:
  - in debian/rules; update --with-printcap
  - update cups-daemon postinst
* /run/cups/cups.sock:
  - update cups postinst and postrm for the lpadmin calls
  - update the autopkgtest for the lpadmin call
  - update the libcups2 example script
  - update the upstart script
* /run/cups/certs:
  - update cups.init
  - update the upstart script

Thanks-To: Russell Coker 
Closes: #858341

diff --git a/debian/client.conf b/debian/client.conf
index 5081adeaf..b8e1c0149 100644
--- a/debian/client.conf
+++ b/debian/client.conf
@@ -34,7 +34,7 @@
 
 #
 # ServerName: the hostname of your server.  By default CUPS will use the
-# domain socket /var/run/cups/cups.sock or the value of the CUPS_SERVER
+# domain socket /run/cups/cups.sock or the value of the CUPS_SERVER
 # environment variable.
 # ONLY ONE SERVER NAME MAY BE SPECIFIED AT A TIME.  To use
 # more than one server you must use a local scheduler with browsing
diff --git a/debian/cups-daemon.cups.init b/debian/cups-daemon.cups.init
index bfb08d0ad..7b6277524 100644
--- a/debian/cups-daemon.cups.init
+++ b/debian/cups-daemon.cups.init
@@ -19,7 +19,7 @@
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/usr/sbin/cupsd
 NAME=cupsd
-PIDFILE=/var/run/cups/$NAME.pid
+PIDFILE=/run/cups/$NAME.pid
 DESC="Common Unix Printing System"
 SCRIPTNAME=/etc/init.d/cups
 
@@ -28,8 +28,8 @@ unset TMPDIR
 # Exit if the package is not installed
 test -x $DAEMON || exit 0
 
-mkdir -p /var/run/cups/certs
-[ -x /sbin/restorecon ] && /sbin/restorecon -R /var/run/cups
+mkdir -p /run/cups/certs
+[ -x /sbin/restorecon ] && /sbin/restorecon -R /run/cups
 
 # Define LSB log_* functions.
 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
diff --git a/debian/cups-daemon.postinst b/debian/cups-daemon.postinst
index cf09db6bc..e485a7526 100644
--- a/debian/cups-daemon.postinst
+++ b/debian/cups-daemon.postinst
@@ -63,7 +63,7 @@ if [ "$1" = configure ]; then
 
 	printcap_file=`egrep '^Printcap ' /etc/cups/cupsd.conf | awk '{print $2}' | tail -n 1`
 	if [ -z "$printcap_file" ]; then
-	printcap_file=/var/run/cups/printcap
+	printcap_file=/run/cups/printcap
 	fi
 	if [ ! -e /etc/printcap -a -e $printcap_file ]; then
 	ln -s $printcap_file /etc/printcap
diff --git a/debian/cups-daemon.postrm b/debian/cups-daemon.postrm
index 42c01b083..25cfca367 100644
--- a/debian/cups-daemon.postrm
+++ b/debian/cups-daemon.postrm
@@ -8,7 +8,7 @@ case "$1" in
 purge)
 	rm -rf /var/lib/cups
 	rm -rf /var/log/cups
-	rm -rf /var/run/cups
+	rm -rf /run/cups
 	rm -rf /var/cache/cups
 	rm -rf /var/spool/cups
 	rm -f /etc/cups/ssl/server.crt
diff --git a/debian/cups.postinst b/debian/cups.postinst
index 143d2d2c4..093fc2220 100644
--- a/debian/cups.postinst
+++ b/debian/cups.postinst
@@ -103,7 +103,7 @@ ppd_updater () {
 	for ppd in *.ppd; do
 	[ -r "$ppd" ] || continue
 	queue=${ppd%.ppd}
-	lpstat -h /var/run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue
+	lpstat -h /run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue
 	nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/$1/g'`
 	lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
 	ppdfound="0"
@@ -112,12 +112,12 @@ ppd_updater () {
 	tempfiles="$tempfiles $tmpfile2"
 	cat $tmpfile1 | perl -p -e "$gennicknameregexp; s/\n*$/\n/s" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
 	whi

Bug#858341: cups-daemon: please usr /run instead of /var/run

2017-03-21 Thread Russell Coker
Package: cups-daemon
Version: 2.2.1-8
Severity: normal
Tags: patch

/run has been around since 2011, I think it's time to stop using the /var/run
symlink.  Supporting the symlink in SE Linux means supporting both names for
the contexts used in the initial creation of files and directories which I
want to remove.  Here's a patch to make cups not use /var/run:

--- /etc/init.d/cups.orig   2017-03-22 00:26:12.166644807 +1100
+++ /etc/init.d/cups2017-03-22 00:26:29.758408141 +1100
@@ -19,7 +19,7 @@
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/usr/sbin/cupsd
 NAME=cupsd
-PIDFILE=/var/run/cups/$NAME.pid
+PIDFILE=/run/cups/$NAME.pid
 DESC="Common Unix Printing System"
 SCRIPTNAME=/etc/init.d/cups
 
@@ -28,8 +28,8 @@
 # Exit if the package is not installed
 test -x $DAEMON || exit 0
 
-mkdir -p /var/run/cups/certs
-[ -x /sbin/restorecon ] && /sbin/restorecon -R /var/run/cups
+mkdir -p /run/cups/certs
+[ -x /sbin/restorecon ] && /sbin/restorecon -R /run/cups
 
 # Define LSB log_* functions.
 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
--- /etc/cups/cupsd.conf.orig   2017-03-22 00:28:32.900624971 +1100
+++ /etc/cups/cupsd.conf2017-03-22 00:28:48.528298483 +1100
@@ -16,7 +16,7 @@
 
 # Only listen for connections from the local machine.
 Listen 127.0.0.1:631
-Listen /var/run/cups/cups.sock
+Listen /run/cups/cups.sock
 
 # Show shared printers on the local network.
 Browsing On
-- System Information:
Debian Release: 9.0
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages cups-daemon depends on:
ii  adduser  3.115
ii  bc   1.06.95-9+b3
ii  dpkg 1.18.23
ii  init-system-helpers  1.47
ii  libavahi-client3 0.6.32-2
ii  libavahi-common3 0.6.32-2
ii  libc62.24-9
ii  libcups2 2.2.1-8
ii  libcupsmime1 2.2.1-8
ii  libdbus-1-3  1.10.16-1
ii  libgssapi-krb5-2 1.15-1
ii  libpam0g 1.1.8-3.5
ii  libpaper11.1.24+nmu5
ii  libsystemd0  232-19
ii  lsb-base 9.20161125
ii  procps   2:3.3.12-3
ii  ssl-cert 1.0.38

Versions of packages cups-daemon recommends:
pn  avahi-daemon  
pn  colord
pn  cups-browsed  

Versions of packages cups-daemon suggests:
ii  cups 2.2.1-8
ii  cups-bsd 2.2.1-8
ii  cups-client  2.2.1-8
ii  cups-common  2.2.1-8
ii  cups-filters [foomatic-filters]  1.11.6-3
pn  cups-pdf 
ii  cups-ppdc2.2.1-8
ii  cups-server-common   2.2.1-8
ii  foomatic-db  20161201-1
ii  ghostscript  9.20~dfsg-2
pn  hplip
ii  poppler-utils0.48.0-2
pn  printer-driver-gutenprint
pn  printer-driver-hpcups
pn  smbclient
ii  udev 232-19

-- Configuration Files:
/etc/init.d/cups changed:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/cupsd
NAME=cupsd
PIDFILE=/run/cups/$NAME.pid
DESC="Common Unix Printing System"
SCRIPTNAME=/etc/init.d/cups
unset TMPDIR
test -x $DAEMON || exit 0
mkdir -p /run/cups/certs
[ -x /sbin/restorecon ] && /sbin/restorecon -R /run/cups
. /lib/lsb/init-functions
if [ -z "$TZ" -a -e /etc/timezone ]; then
TZ=`cat /etc/timezone`
export TZ
fi
coldplug_usb_printers() {
if type udevadm > /dev/null 2>&1 && [ -x /lib/udev/udev-configure-printer 
]; then
for printer in `udevadm trigger --verbose --dry-run 
--subsystem-match=usb \
--attr-match=bInterfaceClass=07 
--attr-match=bInterfaceSubClass=01 2>/dev/null || true; \
udevadm trigger --verbose --dry-run 
--subsystem-match=usb \
--sysname-match='lp[0-9]*' 2>/dev/null || true`; do
/lib/udev/udev-configure-printer add "${printer#/sys}"
done
fi
}
case "$1" in
  start)
log_daemon_msg "Starting $DESC" "$NAME"
mkdir -p `dirname "$PIDFILE"`
start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" --exec 
$DAEMON
status=$?
[ $status = 0 ] && coldplug_usb_printers
log_end_msg $status
;;
  stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE 
--name $NAME
status=$?
log_end_msg $status
;;
  reload|force-reload)
   log_daemon_msg "Reloading $DESC" "$NAME"
   start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME 
--signal 1
   status=$?
   log_end_msg $status
   ;;