p910nd: Add p910nd lightweight printserver
PATCH v2 1/1 p910nd: Add p910nd lightweight printserver
Changes since V1:
-p910nd.mk : Fixed source/site, removed need for patch, decrufted. -S55p910nd initscript: Reworked for start-stop-daemon usage,
added some basic sanity checks for config-file, lock-dir & run-dir, cleaned up structure and readability, removed cruft, changed do_stop so that it scans run-dir for pid-files instead of looking at the config file, reworked do_start to ensure that each instance of p910nd has its correct/unique process-name and pid-file, and added a restart option.
-p910nd.conf : Added clarifying documentation RE format of args/options -RETESTED: with a fresh rootfs build, with different daemon instances
(e.g. p9102d), on various devices (e.g. /dev/usb/lp3) - all successful
--- package/Config.in | 1 + package/p910nd/Config.in | 8 +++++ package/p910nd/S55p910nd | 76 ++++++++++++++++++++++++++++++++++++++++++++ package/p910nd/p910nd.conf | 20 +++++++++++ package/p910nd/p910nd.mk | 21 ++++++++++++ 5 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 package/p910nd/Config.in create mode 100644 package/p910nd/S55p910nd create mode 100644 package/p910nd/p910nd.conf create mode 100644 package/p910nd/p910nd.mk
package/Config.in +1 -0
@@ -570,6 +570,7 @@ source "package/openntpd/Config.in" source "package/openssh/Config.in" source "package/openswan/Config.in" source "package/openvpn/Config.in" +source "package/p910nd/Config.in" source "package/portmap/Config.in" source "package/pppd/Config.in" source "package/pptp-linux/Config.in"
package/p910nd/Config.in new file +8 -0
@@ -0,0 +1,8 @@ +config BR2_PACKAGE_P910ND + bool "p910nd" + help + p910nd is a small printer daemon intended for diskless + workstations. Using ports 9100-9102, it accepts + print jobs and passes them directly to a USB printer. + + http://p910nd.sourceforge.net/
package/p910nd/S55p910nd new file +76 -0
76 lines not on this page · raw message
package/p910nd/p910nd.conf new file +20 -0
@@ -0,0 +1,20 @@ +# p910nd Version 0.95 Copyright (c) 2010 Ken Yap, GPLv2 +# For additional daemon arguments, see man 8 p910nd +# +# description of config line format for /etc/p910nd.conf +# each configuration line must have form +# N [-b] -f <printer_device> +# +# where: +# N is the port number [0|1|2], +# -b enables (optional) bidirectional traffic, and +# -f specifies a printer device +# +# examples: + 0 -b -f /dev/usb/lp0 +# (listen on port 9100, bidirectional traffic, use /dev/usb/lp0, pid-file p9100d) +# +# 2 -f /dev/usb/lp3 +# (listen on port 9102, use /dev/usb/lp3, pid-file p9102d.pid) + +
package/p910nd/p910nd.mk new file +21 -0
@@ -0,0 +1,21 @@ +############################################################# +# +# p910nd +# +############################################################# + +P910ND_VERSION = 0.95 +P910ND_SITE = http://$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/p910nd/$(P910ND_VERSION) +P910ND_SOURCE = p910nd-$(P910ND_VERSION).tar.bz2 + +define P910ND_BUILD_CMDS + $(MAKE) $(TARGET_CONFIGURE_OPTS) $(P910ND_MAKE_OPTS) -C $(@D) +endef + +define P910ND_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/p910nd $(TARGET_DIR)/usr/sbin/p910nd + $(INSTALL) -m 0644 -D package/p910nd/p910nd.conf $(TARGET_DIR)/etc/p910nd.conf + $(INSTALL) -m 0755 -D package/p910nd/S55p910nd $(TARGET_DIR)/etc/init.d/S55p910nd +endef + +$(eval $(call GENTARGETS))
Signature · 1 line
1.7.0.4
PATCH v2 1/1 p910nd: Add p910nd lightweight printserver
Quoted 4 lines · Dave Purdy
Changes since V1:
-p910nd.mk : Fixed source/site, removed need for patch, decrufted. -S55p910nd initscript: Reworked for start-stop-daemon usage,
added some basic sanity checks for config-file, lock-dir& run-dir,
Quoted 8 lines
cleaned up structure and readability, removed cruft, changed
do_stopso that it scans run-dir for pid-files instead of looking at the config file, reworkeddo_startto ensure that each instance of p910nd has its correct/unique process-name and pid-file, and added a restart option.
-p910nd.conf : Added clarifying documentation RE format of args/options -RETESTED: with a fresh rootfs build, with different daemon instances
(e.g. p9102d), on various devices (e.g./dev/usb/lp3) - all successful
Patch changelog is normally put after the Signed-off-by, separated by --- (like
the diffstat). This way, it is not included when the patch is committed to git.
Quoted 3 lines
Signed-off-by Dave Purdy<[email protected]>
[snip]
package/p910nd/S55p910nd line 10
Quoted 13 lines
package/p910nd/S55p910nd new file +10
-0@@ -0,0 +1,76 @@ +#!/bin/sh +# +# /etc/init.d/[S55]p910nd +# initscript to start p910nd printer daemon, with match pid-files and process-names + + +CONFIG=/etc/p910nd.conf +RUN_D=/var/run +P910ND=/usr/sbin/p910nd +SUBSYS=/var/lock/subsys
I guess this means that the -DLOCKFILE_DIR=... in CFLAGS didn't work?
That's a pity, because I don't really like adding a /tmp/subsys directory... BTW, the variable is better called LOCK_D similar to RUN_D.
package/p910nd/S55p910nd line 13
Quoted 3 lines
package/p910nd/S55p910nd new file +3
-0+ +# check if /etc/p910nd.conf exists, print message& exit if it doesn't +[ ! -f $CONFIG ]&& ( echo "The config file /etc/p910nd.conf is missing... exiting now."&& exit 0 )
I would remove this test. stop is still relevant if the config file is missing,
and the test is anyway repeated in do_start.
Quoted 6 lines
package/p910nd/S55p910nd new file +6
-0+ +# description of config line format for /etc/p910nd.conf +# each configuration line must have form +# N [-b] -f<printer_device> , where N is the port number [0|1|2], -b enables bidirectional traffic, +# and -f specifies a printer device +#
package/p910nd/S55p910nd
Quoted 10 lines
package/p910nd/S55p910nd new file +10
-0+# examples: +# 0 -b -f /dev/usb/lp0 +# (listen on port 9100, with bidirectional traffic, use /dev/usb/lp0, pid-file p9100d.pid) +# +# 2 -f /dev/usb/lp3 +# (listen on port 9102, use /dev/usb/lp3, pid-file p9102d.pid) + + +# check if /var/run exists, create it if not +[ ! -d $RUN_D ]&& mkdir -p $RUN_D
Not really needed; /var/run is in the skeleton (and a symlink to /tmp instead of directory).
Other init scripts (e.g. S01logging) don't have this check.
Quoted 4 lines
package/p910nd/S55p910nd new file +4
-0+ +# check if /var/lock/subsys exists, create it if not +[ ! -d $SUBSYS ]&& mkdir -p $SUBSYS +
package/p910nd/S55p910nd line 43
Quoted 10 lines
package/p910nd/S55p910nd new file +10
-0+do_start() { + [ -f $CONFIG ]&& ( while read PORT OPTIONS; do + case "$PORT" in + ""|\#*) + continue; + esac + P910XD_PID="p910"$PORT"d.pid" # create the correct pid-filename, e.g. p9102d.pid + P910ND_ARGS=" $OPTIONS $PORT" + start-stop-daemon -m -p $RUN_D/$P910XD_PID -S -x $P910ND -- $P910ND_ARGS + echo "starting p910nd with options" $OPTIONS "on port" $PORT "with pid-file" $P910XD_PID
You don't have to stop the quotes around the variables:
echo "starting p910nd with options $OPTIONS on port $PORT with pid-file $P910XD_PID"
package/p910nd/S55p910nd
Quoted 12 lines
package/p910nd/S55p910nd new file +12
-0+ if [ $? -ne 0 ]; then + exit 1 + fi + done + )< $CONFIG + exit 0 +} + +do_stop() { + for PID_F in $RUN_D/p910?d.pid; do + start-stop-daemon -q -K -p $PID_F + rm $PID_F&& echo "stopping p910nd instance with pid-file" $PID_F
I would do the echo before sending the kill. Also it shouldn't depend on
the success of the rm. BTW, doesn't start-stop-daemon remove the pid file?
Quoted 2 lines
package/p910nd/S55p910nd new file +2
-0+ done +}
[snip]
package/p910nd/S55p910nd
Quoted 3 lines
package/p910nd/S55p910nd new file +3
-0+define P910ND_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/p910nd $(TARGET_DIR)/usr/sbin/p910nd + $(INSTALL) -m 0644 -D package/p910nd/p910nd.conf $(TARGET_DIR)/etc/p910nd.conf
Installation of the configuration file should not be done if it already exists. In all
likelihood, the user will override the default configuration file with another one that comes from a custom skeleton, a configuration package, or a post-build script. In the first two cases, a rebuild of the p910nd package would remove the user's configuration file.
Also, it would be nicer if the order of -D and -m was the same in all install lines.
-m 0644 -D is the order that is usually used.
Quoted 4 lines
package/p910nd/S55p910nd new file +4
-0+ $(INSTALL) -m 0755 -D package/p910nd/S55p910nd $(TARGET_DIR)/etc/init.d/S55p910nd +endef + +$(eval $(call GENTARGETS))
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286540 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F