Package: papercut Version: 0.9.13-4.1 Severity: serious Tags: patch
Hi, In the attachment you will find the patch to repair this bug. -- Juan Angulo Moreno --- System information. --- Architecture: i386 Kernel: Linux 2.6.22-3-686 Debian Release: lenny/sid --- Package information. --- Depends (Version) | Installed =============================-+-=========== adduser | 3.105 python | 2.4.4-6 python-support (>= 0.7.1) | 0.7.6
diff -urNp papercut-0.9.13/debian/changelog papercut-0.9.13_new/debian/changelog --- papercut-0.9.13/debian/changelog 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/changelog 2008-02-21 23:43:53.000000000 -0430 @@ -1,3 +1,15 @@ +papercut (0.9.13-4.1) unstable; urgency=low + + * Non-maintainer upload. + * Added debian/papercut.postinst with user/group creation. (Closes: #462864) + * Fixed debian/papercut.postrm with delete user support. + * Fixed debian/papercut.init (with user daemon support). + * Added debian/pyDaemon.py library. + * Fixed papercut script with pyDaemon.py. + * Fixed .pid file (Its uses the default directory /var/run/papercut). + + -- Juan Angulo Moreno <[EMAIL PROTECTED]> Wed, 20 Feb 2008 03:29:33 -0430 + papercut (0.9.13-4) unstable; urgency=low * Switch to the new Python Policy. (Closes: #380886) diff -urNp papercut-0.9.13/debian/control papercut-0.9.13_new/debian/control --- papercut-0.9.13/debian/control 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/control 2008-02-21 18:50:45.000000000 -0430 @@ -2,14 +2,15 @@ Source: papercut Section: news Priority: optional Maintainer: Jérémy Bobbio <[EMAIL PROTECTED]> -Build-Depends: debhelper (>= 5.0.37.2), python-support (>= 0.3) +Build-Depends: debhelper (>= 5.0.37.2), python-support (>= 0.3), dpatch Build-Depends-Indep: python, xsltproc, docbook-xsl -Standards-Version: 3.7.2 +Standards-Version: 3.7.3 +HomePage: http://pessoal.org/papercut/ XS-Python-Version: current Package: papercut Architecture: all -Depends: ${python:Depends} +Depends: ${python:Depends}, adduser XB-Python-Version: ${python:Versions} Recommends: python-mysqldb, python-pgsql Suggests: phpbb2, mysql-server @@ -32,5 +33,3 @@ Description: simple and extensible NNTP Please note that Papercut is only a NNTP server, not a full-featured news transport system. It does not handle newsfeeding or other usual news software features. - . - Homepage: http://pessoal.org/papercut/ diff -urNp papercut-0.9.13/debian/copyright papercut-0.9.13_new/debian/copyright --- papercut-0.9.13/debian/copyright 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/copyright 2008-02-21 19:20:47.000000000 -0430 @@ -10,25 +10,47 @@ Changes: The docs/ directory and its content was removed: IETF RFCs are non-free in the DFSG sense. +Files: * Copyright: - (c) 2002-2005 Joao Prado Maia <[EMAIL PROTECTED]> - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. + (c) 2002-2005 Joao Prado Maia <[EMAIL PROTECTED]> + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +File: pyDaemon.py +Copyright: + + (C) 2005 Chad J. Schroeder <[EMAIL PROTECTED]> + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -urNp papercut-0.9.13/debian/files papercut-0.9.13_new/debian/files --- papercut-0.9.13/debian/files 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/files 2008-02-21 19:39:25.000000000 -0430 @@ -0,0 +1 @@ +papercut_0.9.13-4.1_all.deb news optional diff -urNp papercut-0.9.13/debian/init.d papercut-0.9.13_new/debian/init.d --- papercut-0.9.13/debian/init.d 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/init.d 2008-02-21 19:38:50.000000000 -0430 @@ -0,0 +1,77 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: papercut +# Required-Start: $local_fs $remote_fs mysql postgresql +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: S 0 1 6 +# Short-Description: Papercut NNTP server +# Description: Papercut is a simple and extensible NNTP server, meant +# to provide news access to existing content, e.g. web based +# bulletin board systems. +### END INIT INFO +# +# Author: Jérémy Bobbio <[EMAIL PROTECTED]>. +# Rewrite by: Juan Angulo Moreno <[EMAIL PROTECTED]> +# + + +NAME=papercut +PATH=/bin:/usr/bin:/sbin:/usr/sbin +DAEMON=/usr/bin/papercut +PIDFILE=/var/run/$NAME/$NAME.pid + + +trap "" 1 +export LANG=C +export PATH + +test -f $DAEMON || exit 0 + + +case "$1" in + start) + echo "Starting papercut detection : $NAME" + start-stop-daemon --start --quiet --pidfile $PIDFILE \ + --exec $DAEMON --chuid papercut || true && + echo "." || + echo " failed!" + ;; + + stop) + echo "Stopping papercut detection : $NAME" + start-stop-daemon --stop --quiet --pidfile $PIDFILE && + rm -f /var/run/papercut/papercut.pid + echo "." || + echo " not running." + ;; + + reload-config) + echo "Reloading $NAME configuration" + start-stop-daemon --stop --signal HUP --exec $DAEMON + ;; + + restart-papercut) + echo "Restarting $NAME" + $0 stop + $0 start + ;; + + restart|force-reload) + $0 restart-papercut + exit $? + ;; + + *) + echo "Usage: /etc/init.d/$NAME {start|stop|reload-config|restart|force-reload}" + exit 1 + ;; +esac + +if [ $? == 0 ]; then + echo . + exit 0 +else + echo failed + exit 1 +fi diff -urNp papercut-0.9.13/debian/papercut.init papercut-0.9.13_new/debian/papercut.init --- papercut-0.9.13/debian/papercut.init 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/papercut.init 2008-02-21 19:39:00.000000000 -0430 @@ -12,57 +12,66 @@ ### END INIT INFO # # Author: Jérémy Bobbio <[EMAIL PROTECTED]>. +# Rewrite by: Juan Angulo Moreno <[EMAIL PROTECTED]> # -set -e -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DESC="Papercut NNTP server" NAME=papercut -DAEMON=/usr/bin/$NAME -PIDFILE=/var/run/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME +PATH=/bin:/usr/bin:/sbin:/usr/sbin +DAEMON=/usr/bin/papercut +PIDFILE=/var/run/$NAME/$NAME.pid -# Gracefully exit if the package has been removed. -test -x $DAEMON || exit 0 -# -# Function that starts the daemon/service. -# -d_start() { - echo -n "Starting $DESC: $NAME" - start-stop-daemon --start --quiet --pidfile $PIDFILE \ - --exec $DAEMON && - echo "." || - echo " failed!" -} +trap "" 1 +export LANG=C +export PATH + +test -f $DAEMON || exit 0 -# -# Function that stops the daemon/service. -# -d_stop() { - echo -n "Stopping $DESC: $NAME" - start-stop-daemon --stop --quiet --pidfile $PIDFILE && - echo "." || - echo " not running." -} case "$1" in start) - d_start - ;; + echo "Starting papercut detection : $NAME" + start-stop-daemon --start --quiet --pidfile $PIDFILE \ + --exec $DAEMON --chuid papercut || true && + echo "." || + echo " failed!" + ;; + stop) - d_stop - ;; + echo "Stopping papercut detection : $NAME" + start-stop-daemon --stop --quiet --pidfile $PIDFILE && + rm -f /var/run/papercut/papercut.pid + echo "." || + echo " not running." + ;; + + reload-config) + echo "Reloading $NAME configuration" + start-stop-daemon --stop --signal HUP --exec $DAEMON + ;; + + restart-papercut) + echo "Restarting $NAME" + $0 stop + $0 start + ;; + restart|force-reload) - d_stop - sleep 1 - d_start - ;; + $0 restart-papercut + exit $? + ;; + *) - echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 - exit 1 - ;; + echo "Usage: /etc/init.d/$NAME {start|stop|reload-config|restart|force-reload}" + exit 1 + ;; esac -exit 0 +if [ $? == 0 ]; then + echo . + exit 0 +else + echo failed + exit 1 +fi diff -urNp papercut-0.9.13/debian/papercut.postinst papercut-0.9.13_new/debian/papercut.postinst --- papercut-0.9.13/debian/papercut.postinst 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/papercut.postinst 2008-02-19 22:38:52.000000000 -0430 @@ -25,6 +25,39 @@ case "$1" in ;; esac + +add_group_if_missing() { + if [ -x /usr/sbin/addgroup ]; then + if ! id -g papercut >/dev/null 2>&1; then + addgroup --force-badname papercut || true + fi + fi +} + +add_user_if_missing() { + if [ -x /usr/sbin/adduser ]; then + if ! id -u papercut > /dev/null 2>&1; then + adduser --system --no-create-home \ + --disabled-password \ + --force-badname papercut \ + --ingroup papercut + fi + fi +} + +create_pid_file(){ + if ! [ -d /var/run/papercut ]; then + mkdir /var/run/papercut + touch /var/run/papercut/papercut.pid + fi + chown papercut:papercut -R /var/run/papercut +} + +add_group_if_missing +add_user_if_missing +create_pid_file + + #DEBHELPER# exit 0 diff -urNp papercut-0.9.13/debian/papercut.postinst.debhelper papercut-0.9.13_new/debian/papercut.postinst.debhelper --- papercut-0.9.13/debian/papercut.postinst.debhelper 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/papercut.postinst.debhelper 2008-02-21 19:39:24.000000000 -0430 @@ -0,0 +1,15 @@ +# Automatically added by dh_pysupport +if which update-python-modules >/dev/null 2>&1; then + update-python-modules papercut.dirs +fi +# End automatically added section +# Automatically added by dh_installinit +if [ -x "/etc/init.d/papercut" ]; then + update-rc.d papercut defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d papercut start || exit $? + else + /etc/init.d/papercut start || exit $? + fi +fi +# End automatically added section diff -urNp papercut-0.9.13/debian/papercut.postrm papercut-0.9.13_new/debian/papercut.postrm --- papercut-0.9.13/debian/papercut.postrm 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/papercut.postrm 2008-02-20 03:56:11.000000000 -0430 @@ -8,6 +8,8 @@ case "$1" in purge) rm -rf /var/cache/papercut + rm -rf /var/run/papercut + userdel papercut || true ;; diff -urNp papercut-0.9.13/debian/papercut.postrm.debhelper papercut-0.9.13_new/debian/papercut.postrm.debhelper --- papercut-0.9.13/debian/papercut.postrm.debhelper 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/papercut.postrm.debhelper 2008-02-21 19:39:24.000000000 -0430 @@ -0,0 +1,5 @@ +# Automatically added by dh_installinit +if [ "$1" = "purge" ] ; then + update-rc.d papercut remove >/dev/null || exit $? +fi +# End automatically added section diff -urNp papercut-0.9.13/debian/papercut.prerm.debhelper papercut-0.9.13_new/debian/papercut.prerm.debhelper --- papercut-0.9.13/debian/papercut.prerm.debhelper 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/papercut.prerm.debhelper 2008-02-21 19:39:24.000000000 -0430 @@ -0,0 +1,14 @@ +# Automatically added by dh_pysupport +if which update-python-modules >/dev/null 2>&1; then + update-python-modules -c papercut.dirs +fi +# End automatically added section +# Automatically added by dh_installinit +if [ -x "/etc/init.d/papercut" ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d papercut stop || exit $? + else + /etc/init.d/papercut stop || exit $? + fi +fi +# End automatically added section diff -urNp papercut-0.9.13/debian/papercut.substvars papercut-0.9.13_new/debian/papercut.substvars --- papercut-0.9.13/debian/papercut.substvars 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/papercut.substvars 2008-02-21 19:39:22.000000000 -0430 @@ -0,0 +1 @@ +python:Depends=python, python-support (>= 0.7.1) diff -urNp papercut-0.9.13/debian/patched/01_papercut.py_rewrite_daemon.dpatch papercut-0.9.13_new/debian/patched/01_papercut.py_rewrite_daemon.dpatch --- papercut-0.9.13/debian/patched/01_papercut.py_rewrite_daemon.dpatch 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/patched/01_papercut.py_rewrite_daemon.dpatch 2008-02-21 19:39:18.000000000 -0430 @@ -0,0 +1 @@ +patching file papercut.py diff -urNp papercut-0.9.13/debian/patches/00list papercut-0.9.13_new/debian/patches/00list --- papercut-0.9.13/debian/patches/00list 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/patches/00list 2008-02-21 18:53:51.000000000 -0430 @@ -0,0 +1 @@ +01_papercut.py_rewrite_daemon.dpatch diff -urNp papercut-0.9.13/debian/patches/01_papercut.py_rewrite_daemon.dpatch papercut-0.9.13_new/debian/patches/01_papercut.py_rewrite_daemon.dpatch --- papercut-0.9.13/debian/patches/01_papercut.py_rewrite_daemon.dpatch 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/patches/01_papercut.py_rewrite_daemon.dpatch 2008-02-21 18:55:14.000000000 -0430 @@ -0,0 +1,57 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 01_papercut.py_rewrite_daemon.dpatch by Juan Angulo Moreno <[EMAIL PROTECTED]> +## +## DP: Rewrite funtions papercut daemon + [EMAIL PROTECTED]@ +diff -urNad papercut-0.9.13~/papercut.py papercut-0.9.13/papercut.py +--- papercut-0.9.13~/papercut.py 2008-02-21 18:27:30.000000000 -0430 ++++ papercut-0.9.13/papercut.py 2008-02-21 18:29:20.000000000 -0430 +@@ -19,6 +19,7 @@ + # papercut based modules + import settings + import papercut_cache ++import pyDaemon + + __VERSION__ = '0.9.13' + # set this to 0 (zero) for real world use +@@ -887,7 +888,7 @@ + + def is_process_running(pid): + try: +- os.kill(pid, 0) ++ #os.kill(pid, 0) + return True + except OSError, e: + if e.errno != errno.ESRCH: +@@ -953,27 +954,10 @@ + ip_address = "127.0.0.1" + + if options.background: +- try: +- pid = os.fork() +- if pid > 0: +- # Exit first parent +- sys.exit(0) +- except OSError, e: +- print >>sys.stderr, "fork failed: %d (%s)" % (e.errno, e.strerror) +- sys.exit(1) +- +- # write PID ++ pyDaemon.createDaemon() + write_pid(os.getpid()) +- +- # unlink parent environment +- fp = open('/dev/null', 'rw') +- sys.stdin = sys.__stdin__ = fp +- sys.stdout = sys.__stdout__ = fp +- sys.stderr = sys.__stderr__ = fp +- del fp +- os.chdir('/') +- os.setsid() +- os.umask(0) ++ while 1: ++ time.sleep(5) + + else: # foreground + write_pid(os.getpid()) diff -urNp papercut-0.9.13/debian/pyDaemon.py papercut-0.9.13_new/debian/pyDaemon.py --- papercut-0.9.13/debian/pyDaemon.py 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/debian/pyDaemon.py 2008-02-21 22:10:59.000000000 -0430 @@ -0,0 +1,208 @@ +"""Disk And Execution MONitor (Daemon) +http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 + +Configurable daemon behaviors: + + 1.) The current working directory set to the "/" directory. + 2.) The current file creation mode mask set to 0. + 3.) Close all open files (1024). + 4.) Redirect standard I/O streams to "/dev/null". + +A failed call to fork() now raises an exception. + +References: + 1) Advanced Programming in the Unix Environment: W. Richard Stevens + 2) Unix Programming Frequently Asked Questions: + http://www.erlenstar.demon.co.uk/unix/faq_toc.html +""" + +__author__ = "Chad J. Schroeder" +__copyright__ = "Copyright (C) 2005 Chad J. Schroeder" + +__revision__ = "$Id$" +__version__ = "0.2" + +# Standard Python modules. +import os # Miscellaneous OS interfaces. +import sys # System-specific parameters and functions. + +# Default daemon parameters. +# File mode creation mask of the daemon. +UMASK = 0 + +# Default working directory for the daemon. +WORKDIR = "/" + +# Default maximum for the number of available file descriptors. +MAXFD = 1024 + +# The standard I/O file descriptors are redirected to /dev/null by default. +if (hasattr(os, "devnull")): + REDIRECT_TO = os.devnull +else: + REDIRECT_TO = "/dev/null" + +def createDaemon(): + """Detach a process from the controlling terminal and run it in the + background as a daemon. + """ + + try: + # Fork a child process so the parent can exit. This returns control to + # the command-line or shell. It also guarantees that the child will not + # be a process group leader, since the child receives a new process ID + # and inherits the parent's process group ID. This step is required + # to insure that the next call to os.setsid is successful. + pid = os.fork() + except OSError, e: + raise Exception, "%s [%d]" % (e.strerror, e.errno) + + if (pid == 0): # The first child. + # To become the session leader of this new session and the process group + # leader of the new process group, we call os.setsid(). The process is + # also guaranteed not to have a controlling terminal. + os.setsid() + + # Is ignoring SIGHUP necessary? + # + # It's often suggested that the SIGHUP signal should be ignored before + # the second fork to avoid premature termination of the process. The + # reason is that when the first child terminates, all processes, e.g. + # the second child, in the orphaned group will be sent a SIGHUP. + # + # "However, as part of the session management system, there are exactly + # two cases where SIGHUP is sent on the death of a process: + # + # 1) When the process that dies is the session leader of a session that + # is attached to a terminal device, SIGHUP is sent to all processes + # in the foreground process group of that terminal device. + # 2) When the death of a process causes a process group to become + # orphaned, and one or more processes in the orphaned group are + # stopped, then SIGHUP and SIGCONT are sent to all members of the + # orphaned group." [2] + # + # The first case can be ignored since the child is guaranteed not to have + # a controlling terminal. The second case isn't so easy to dismiss. + # The process group is orphaned when the first child terminates and + # POSIX.1 requires that every STOPPED process in an orphaned process + # group be sent a SIGHUP signal followed by a SIGCONT signal. Since the + # second child is not STOPPED though, we can safely forego ignoring the + # SIGHUP signal. In any case, there are no ill-effects if it is ignored. + # + # import signal # Set handlers for asynchronous events. + # signal.signal(signal.SIGHUP, signal.SIG_IGN) + + try: + # Fork a second child and exit immediately to prevent zombies. This + # causes the second child process to be orphaned, making the init + # process responsible for its cleanup. And, since the first child is + # a session leader without a controlling terminal, it's possible for + # it to acquire one by opening a terminal in the future (System V- + # based systems). This second fork guarantees that the child is no + # longer a session leader, preventing the daemon from ever acquiring + # a controlling terminal. + pid = os.fork() # Fork a second child. + except OSError, e: + raise Exception, "%s [%d]" % (e.strerror, e.errno) + + if (pid == 0): # The second child. + # Since the current working directory may be a mounted filesystem, we + # avoid the issue of not being able to unmount the filesystem at + # shutdown time by changing it to the root directory. + os.chdir(WORKDIR) + # We probably don't want the file mode creation mask inherited from + # the parent, so we give the child complete control over permissions. + os.umask(UMASK) + else: + # exit() or _exit()? See below. + os._exit(0) # Exit parent (the first child) of the second child. + else: + # exit() or _exit()? + # _exit is like exit(), but it doesn't call any functions registered + # with atexit (and on_exit) or any registered signal handlers. It also + # closes any open file descriptors. Using exit() may cause all stdio + # streams to be flushed twice and any temporary files may be unexpectedly + # removed. It's therefore recommended that child branches of a fork() + # and the parent branch(es) of a daemon use _exit(). + os._exit(0) # Exit parent of the first child. + + # Close all open file descriptors. This prevents the child from keeping + # open any file descriptors inherited from the parent. There is a variety + # of methods to accomplish this task. Three are listed below. + # + # Try the system configuration variable, SC_OPEN_MAX, to obtain the maximum + # number of open file descriptors to close. If it doesn't exists, use + # the default value (configurable). + # + # try: + # maxfd = os.sysconf("SC_OPEN_MAX") + # except (AttributeError, ValueError): + # maxfd = MAXFD + # + # OR + # + # if (os.sysconf_names.has_key("SC_OPEN_MAX")): + # maxfd = os.sysconf("SC_OPEN_MAX") + # else: + # maxfd = MAXFD + # + # OR + # + # Use the getrlimit method to retrieve the maximum file descriptor number + # that can be opened by this process. If there is not limit on the + # resource, use the default value. + # + import resource # Resource usage information. + maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] + if (maxfd == resource.RLIM_INFINITY): + maxfd = MAXFD + + # Iterate through and close all file descriptors. + for fd in range(0, maxfd): + try: + os.close(fd) + except OSError: # ERROR, fd wasn't open to begin with (ignored) + pass + + # Redirect the standard I/O file descriptors to the specified file. Since + # the daemon has no controlling terminal, most daemons redirect stdin, + # stdout, and stderr to /dev/null. This is done to prevent side-effects + # from reads and writes to the standard I/O file descriptors. + + # This call to open is guaranteed to return the lowest file descriptor, + # which will be 0 (stdin), since it was closed above. + os.open(REDIRECT_TO, os.O_RDWR) # standard input (0) + + # Duplicate standard input to standard output and standard error. + os.dup2(0, 1) # standard output (1) + os.dup2(0, 2) # standard error (2) + + return(0) + +if __name__ == "__main__": + + retCode = createDaemon() + + # The code, as is, will create a new file in the root directory, when + # executed with superuser privileges. The file will contain the following + # daemon related process parameters: return code, process ID, parent + # process group ID, session ID, user ID, effective user ID, real group ID, + # and the effective group ID. Notice the relationship between the daemon's + # process ID, process group ID, and its parent's process ID. + + procParams = """ + return code = %s + process ID = %s + parent process ID = %s + process group ID = %s + session ID = %s + user ID = %s + effective user ID = %s + real group ID = %s + effective group ID = %s + """ % (retCode, os.getpid(), os.getppid(), os.getpgrp(), os.getsid(0), + os.getuid(), os.geteuid(), os.getgid(), os.getegid()) + + open("createDaemon.log", "w").write(procParams + "\n") + + sys.exit(retCode) diff -urNp papercut-0.9.13/debian/rules papercut-0.9.13_new/debian/rules --- papercut-0.9.13/debian/rules 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/debian/rules 2008-02-21 18:58:21.000000000 -0430 @@ -3,20 +3,33 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 +# This package uses dpatch. +#include /usr/share/dpatch/dpatch.make + DB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl XP=xsltproc -''-nonet papercut.1: debian/papercut.1.xml $(XP) -o $@ $(DB2MAN) $< -clean: +clean: clean-patched unpatch +clean-patched: dh_testdir dh_testroot rm -rf *.py[co] auth/*.py[co] storage/*.py[co] rm -f papercut.1 dh_clean -build: +patch: patch-stamp +patch-stamp: + dpatch apply-all +#dpatch call-all -a=pkg-info >patch-stamp + +unpatch: + dpatch deapply-all + rm -rf patch-stamp debian/patched + +build: patch install: build dh_testdir @@ -35,14 +48,16 @@ install: build $(CURDIR)/debian/papercut/usr/share/papercut/storage install -m 0644 debian/papercut_cfg.py \ $(CURDIR)/debian/papercut/etc/papercut + install -m 0644 debian/pyDaemon.py \ + $(CURDIR)/debian/papercut/usr/share/papercut + sed -i -e 's~/var/run/papercut.pid~/var/run/papercut/papercut.pid~g' \ + $(CURDIR)/debian/papercut/usr/share/papercut/default_settings.py binary-indep: build install papercut.1 dh_testdir dh_testroot dh_pysupport /usr/share/papercut /usr/share/papercut/auth \ /usr/share/papercut/storage - dh_python /usr/share/papercut /usr/share/papercut/auth \ - /usr/share/papercut/storage dh_installchangelogs dh_installdocs dh_installlogrotate diff -urNp papercut-0.9.13/papercut.1 papercut-0.9.13_new/papercut.1 --- papercut-0.9.13/papercut.1 1969-12-31 20:00:00.000000000 -0400 +++ papercut-0.9.13_new/papercut.1 2008-02-21 19:39:21.000000000 -0430 @@ -0,0 +1,69 @@ +.\" Title: papercut +.\" Author: Jeremy Bobbio +.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/> +.\" Date: October 16, 2005 +.\" Manual: +.\" Source: +.\" +.TH "PAPERCUT" "1" "October 16, 2005" "" "" +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.SH "NAME" +papercut - simple and extensible NNTP server +.SH "SYNOPSIS" +.HP 9 +\fBpapercut\fR [[\-f] | [\-\-foreground]] +.SH "DESCRIPTION" +.PP +This manual page documents briefly the +\fBpapercut\fR +command\. +.PP +This manual page was written for the Debian distribution because the original program does not have a manual page\. +.PP +\fBpapercut\fR +is a simple NNTP server\. Its main objective is to integrate existing web based message board software with an Usenet front\-end\. +.PP +However, using Python, new article containers can be added to store and retrieve messages from various source and formats\. +.PP +Please note that Papercut is only a NNTP server, not a full\-featured news transport system\. It does not handle newsfeeding or other usual news software features\. +.SH "OPTIONS" +.PP +These programs follow the usual +GNU +command line syntax, with long options starting with two dashes (`\-\')\. A summary of options is included below\. +.PP +\fB\-h\fR \fB\-\-help\fR +.RS 4 +Show summary of options\. +.RE +.PP +\fB\-\-version\fR +.RS 4 +Show version of program\. +.RE +.PP +\fB\-f\fR \fB\-\-foreground\fR +.RS 4 +Do not fork and run the process in background\. +.RE +.SH "AUTHOR" +.PP +This manual page was written by Jeremy Bobbio +<[EMAIL PROTECTED]> +for the Debian system (but may be used by others)\. Permission is granted to copy, distribute and/or modify this document under the terms of the +GNU +General Public License, Version 2 any later version published by the Free Software Foundation\. +.PP +On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common\-licenses/GPL\. +.SH "AUTHOR" +.PP +\fBJeremy Bobbio\fR +.sp -1n +.IP "" 4 +Author. +.SH "COPYRIGHT" +Copyright \(co 2005 Jeremy Bobbio +.br diff -urNp papercut-0.9.13/papercut.py papercut-0.9.13_new/papercut.py --- papercut-0.9.13/papercut.py 2008-02-21 23:29:57.000000000 -0430 +++ papercut-0.9.13_new/papercut.py 2008-02-21 19:39:18.000000000 -0430 @@ -19,6 +19,7 @@ sys.path = ['/usr/share/papercut'] + sys # papercut based modules import settings import papercut_cache +import pyDaemon __VERSION__ = '0.9.13' # set this to 0 (zero) for real world use @@ -887,7 +888,7 @@ if __name__ == '__main__': def is_process_running(pid): try: - os.kill(pid, 0) + #os.kill(pid, 0) return True except OSError, e: if e.errno != errno.ESRCH: @@ -953,27 +954,10 @@ if __name__ == '__main__': ip_address = "127.0.0.1" if options.background: - try: - pid = os.fork() - if pid > 0: - # Exit first parent - sys.exit(0) - except OSError, e: - print >>sys.stderr, "fork failed: %d (%s)" % (e.errno, e.strerror) - sys.exit(1) - - # write PID + pyDaemon.createDaemon() write_pid(os.getpid()) - - # unlink parent environment - fp = open('/dev/null', 'rw') - sys.stdin = sys.__stdin__ = fp - sys.stdout = sys.__stdout__ = fp - sys.stderr = sys.__stderr__ = fp - del fp - os.chdir('/') - os.setsid() - os.umask(0) + while 1: + time.sleep(5) else: # foreground write_pid(os.getpid())