Debian Bug report logs - #448470
Portmap does not start if a random user has a process named portmap

version graph

Package: portmap; Maintainer for portmap is Anibal Monsalve Salazar <anibal@debian.org>;

Reported by: Michael Gebetsroither <gebi@grml.org>

Date: Mon, 29 Oct 2007 10:18:01 UTC

Severity: serious

Tags: security

Found in versions portmap/6.0-4, portmap/6.0-8

Fixed in version portmap/6.0-9

Done: Anibal Monsalve Salazar <anibal@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. Full text and rfc822 format available.

Acknowledgement sent to Michael Gebetsroither <gebi@grml.org>:
New Bug report received and forwarded. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Michael Gebetsroither <gebi@grml.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Portmap does not start if a random user has a process named portmap
Date: Mon, 29 Oct 2007 11:11:20 +0100
Package: portmap
Version: 6.0-4
Severity: important


Hi,

Ich some random user has a programm portmap running, /etc/init.d/portmap
start refuses to start the portmap daemon, which introdruces a local
DOS.

cu,
michael

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (991, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.22-grml64 (SMP w/2 CPU cores; PREEMPT)
Locale: LANG=en_US.iso885915, LC_CTYPE=en_US.iso885915 (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages portmap depends on:
ii  debconf [debconf-2.0]         1.5.14     Debian configuration management sy
ii  libc6                         2.6.1-1    GNU C Library: Shared libraries
ii  libwrap0                      7.6.dbs-14 Wietse Venema's TCP wrappers libra
ii  lsb-base                      3.1-24     Linux Standard Base 3.1 init scrip

portmap recommends no packages.

-- debconf information:
  portmap/loopback: false




Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. Full text and rfc822 format available.

Acknowledgement sent to Petter Reinholdtsen <pere@hungry.com>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. Full text and rfc822 format available.

Message #10 received at 448470@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <pere@hungry.com>
To: 448470@bugs.debian.org
Subject: Re: Portmap does not start if a random user has a process named portmap
Date: Mon, 19 May 2008 22:22:24 +0200
tags 448470 + patch
thanks

This problem is solved by getting portmap to write a pidfile, making
sure the correct process is checked by the start script instead of a
random one with the portmap name.  This is the same patch as the one
submitted for bug #468665.

--- portmap-6.0.orig/portmap.c
+++ portmap-6.0/portmap.c
@@ -98,6 +98,8 @@

 #include <stdlib.h>
 #include <pwd.h>
+#include <stdarg.h>
+#include <sys/stat.h>

 #ifndef LOG_PERROR
 #define LOG_PERROR 0
@@ -169,6 +171,126 @@
        int priv;
 };

+#ifndef PIDFILE
+#  define PIDFILE "/var/run/portmap.pid"
+#endif
+
+/*
+ * Copied from the atd source
+ */
+static int
+lock_fd(int fd)
+{
+    struct flock lock;
+
+    lock.l_type = F_WRLCK;
+    lock.l_whence = SEEK_SET;
+    lock.l_start = 0;
+    lock.l_len = 0;
+
+    return fcntl(fd, F_SETLK, &lock);
+}
+
+void
+perr(const char *fmt,...)
+{
+    char buf[1024];
+    va_list args;
+
+    va_start(args, fmt);
+    vsnprintf(buf, sizeof(buf), fmt, args);
+    va_end(args);
+
+    if (debugging) {
+       perror(buf);
+    } else
+       syslog(LOG_ERR, "%s: %m", buf);
+
+    exit(EXIT_FAILURE);
+}
+
+void
+pabort(const char *fmt,...)
+{
+    char buf[1024];
+    va_list args;
+
+    va_start(args, fmt);
+    vsnprintf(buf, sizeof(buf), fmt, args);
+    va_end(args);
+
+    if (debugging) {
+       fprintf(stderr, "%s\n", buf);
+    } else
+       syslog(LOG_ERR, "%s", buf);
+
+    exit(EXIT_FAILURE);
+}
+
+FILE *
+save_pidfile(void) {
+    pid_t pid;
+    int fd;
+    FILE *fp;
+    fd = open(PIDFILE, O_RDWR | O_CREAT | O_EXCL,
+             S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
+
+    if (fd == -1) {
+
+       if (errno != EEXIST)
+           perr("Cannot open " PIDFILE);
+
+       if ((fd = open(PIDFILE, O_RDWR)) < 0)
+           perr("Cannot open " PIDFILE);
+
+       fp = fdopen(fd, "rw");
+       if (fp == NULL) {
+           perr("Cannot open " PIDFILE " for reading");
+       }
+       pid = -1;
+       if ((fscanf(fp, "%d", &pid) != 1) || (pid == getpid())
+           || (lock_fd(fileno(fp)) == 0)) {
+           int rc;
+
+           syslog(LOG_NOTICE, "Removing stale lockfile for pid %d", pid);
+
+           rc = unlink(PIDFILE);
+
+           if (rc == -1) {
+               perr("Cannot unlink " PIDFILE);
+           }
+       } else {
+           pabort("Another atd already running with pid %d", pid);
+       }
+       fclose(fp);
+
+       unlink(PIDFILE);
+       fd = open(PIDFILE, O_RDWR | O_CREAT | O_EXCL,
+                 S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
+
+
+       if (fd == -1)
+           perr("Cannot open " PIDFILE " the second time round");
+
+    }
+
+    if (lock_fd(fd) == -1)
+       perr("Cannot lock " PIDFILE);
+
+    fp = fdopen(fd, "w");
+    if (fp == NULL)
+       perr("Special weirdness: fdopen failed");
+
+    fprintf(fp, "%d\n", getpid());
+
+    /* We do NOT close fd, since we want to keep the lock. However, we don't
+     * want to keep the file descriptor in case of an exec().
+     */
+    fflush(fp);
+    fcntl(fd, F_SETFD, (long) 1);
+    return fp;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -252,6 +374,8 @@
                exit(1);
        }

+       save_pidfile();
+
 #ifdef LOG_DAEMON
        openlog("portmap", LOG_PID|LOG_NDELAY | ( foreground ? LOG_PERROR : 0),
            FACILITY);




Tags added: patch Request was from Petter Reinholdtsen <pere@hungry.com> to control@bugs.debian.org. (Mon, 19 May 2008 20:27:03 GMT) Full text and rfc822 format available.

Reply sent to Petter Reinholdtsen <pere@debian.org>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to Michael Gebetsroither <gebi@grml.org>:
Bug acknowledged by developer. Full text and rfc822 format available.

Message #17 received at 448470-close@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <pere@debian.org>
To: 448470-close@bugs.debian.org
Subject: Bug#448470: fixed in portmap 6.0-5.1
Date: Sat, 24 May 2008 17:02:03 +0000
Source: portmap
Source-Version: 6.0-5.1

We believe that the bug you reported is fixed in the latest version of
portmap, which is due to be installed in the Debian FTP archive:

portmap_6.0-5.1.diff.gz
  to pool/main/p/portmap/portmap_6.0-5.1.diff.gz
portmap_6.0-5.1.dsc
  to pool/main/p/portmap/portmap_6.0-5.1.dsc
portmap_6.0-5.1_i386.deb
  to pool/main/p/portmap/portmap_6.0-5.1_i386.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 448470@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Petter Reinholdtsen <pere@debian.org> (supplier of updated portmap package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 24 May 2008 17:28:21 +0200
Source: portmap
Binary: portmap
Architecture: source i386
Version: 6.0-5.1
Distribution: unstable
Urgency: low
Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Changed-By: Petter Reinholdtsen <pere@debian.org>
Description: 
 portmap    - RPC port mapper
Closes: 356784 412636 448470 454208 463798 468665 472236
Changes: 
 portmap (6.0-5.1) unstable; urgency=low
 .
   * Non-maintainer upload.
   * Avoid useless 1 second sleep during boot, while still doing
     it when needed during restarts (Closes: #412636).  Patch
     from Petter Reinholdtsen.
   * New patch 02-448470-pidfile.diff to write pid to
     /var/run/portmap.pid (Closes: #448470).  Patch
     from Petter Reinholdtsen.
   * New patch 03-356784-lotsofinterfaces.diff to handle more
     than 256 network interfaces (Closes: #356784).  Patch
     from Steven Wilton.
   * Updated upstream URL and name in copyright file (Closes: #454208).
   * Change init.d script to use the omitpid feature in sendsigs to
     allow it to stop later during shutdown (Closes: #468665).  Patch
     from Petter Reinholdtsen.
   * Fix bashism in postinst script (Closes: #472236).  Patch
     from Raphael Geissert.
   * Updated Dutch debconf translation from Vincent Zweije (Closes: #463798).
Checksums-Sha1: 
 54d32e034e1cbe32d774dd20e495b839d37cc2b4 1062 portmap_6.0-5.1.dsc
 ea7f3bf3b1c4419284e4c6157922bd88a6972e43 25579 portmap_6.0-5.1.diff.gz
 f563cbc5f0685f967d6b4ddf709ad03541b4ea7c 35636 portmap_6.0-5.1_i386.deb
Checksums-Sha256: 
 ba0cc9273beba21fb778b235f8804d4d686d09e91dfe49f8622154ba4e3768e0 1062 portmap_6.0-5.1.dsc
 971cd7992f9a32f166178ffb273752d8e7a56dbd8f668b031475299469a75f4b 25579 portmap_6.0-5.1.diff.gz
 901f751c309d00330644f7ffdb857233087e15aa0723af808657efd25a7df3e8 35636 portmap_6.0-5.1_i386.deb
Files: 
 a5379aa11b2b1195c8f81ac3c4c160a6 1062 net standard portmap_6.0-5.1.dsc
 14c5c5f7e7a28598041696b9cddfa5bc 25579 net standard portmap_6.0-5.1.diff.gz
 7d625c2daca201ae3ea0e3be91a95bdd 35636 net standard portmap_6.0-5.1_i386.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIOEX020zMSyow1ykRAl6xAKDm6CTsXiH6JTKkGAGreREwWkn0dgCgnB5I
E8op+hc6JPREKSvlKDNvCnw=
=Se1y
-----END PGP SIGNATURE-----





Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Thu, 26 Jun 2008 07:37:47 GMT) Full text and rfc822 format available.

Bug unarchived. Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:30:04 GMT) Full text and rfc822 format available.

Bug reopened, originator not changed. Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:30:06 GMT) Full text and rfc822 format available.

Bug no longer marked as fixed in version portmap/6.0-5.1. Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:30:06 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Sun, 26 Oct 2008 00:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ben Hutchings <ben@decadent.org.uk>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Sun, 26 Oct 2008 00:33:02 GMT) Full text and rfc822 format available.

Message #30 received at 448470@bugs.debian.org (full text, mbox):

From: Ben Hutchings <ben@decadent.org.uk>
To: 448470@bugs.debian.org, Petter Reinholdtsen <pere@debian.org>
Subject: Re: Portmap does not start if a random user has a process named portmap
Date: Sun, 26 Oct 2008 01:33:53 +0100
[Message part 1 (text/plain, inline)]
This bug is not fixed; the init script is still broken.

Ben.

[signature.asc (application/pgp-signature, inline)]

Tags added: security Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:36:02 GMT) Full text and rfc822 format available.

Severity set to `serious' from `important' Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:36:03 GMT) Full text and rfc822 format available.

Tags removed: patch Request was from Ben Hutchings <ben@decadent.org.uk> to control@bugs.debian.org. (Sun, 26 Oct 2008 00:36:06 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Sun, 26 Oct 2008 03:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petter Reinholdtsen <pere@hungry.com>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Sun, 26 Oct 2008 03:12:03 GMT) Full text and rfc822 format available.

Message #41 received at 448470@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <pere@hungry.com>
To: Ben Hutchings <ben@decadent.org.uk>
Cc: 448470@bugs.debian.org
Subject: Re: Portmap does not start if a random user has a process named portmap
Date: Sun, 26 Oct 2008 04:09:50 +0100
[Ben Hutchings]
> This bug is not fixed; the init script is still broken.

I had a look at the script in unstable, and it seem to me that it
isn't using pidofproc() from /lib/lsb/init-functions as I believed,
but pidof:

  case "$1" in
    start)
        log_begin_msg "Starting portmap daemon..."
        pid=`pidof portmap`
        if [ -n "$pid" ] ; then
              log_begin_msg "Already running."
              log_end_msg 0
              exit 0
        fi

Thus the 'start' option isn't using the pid file.  This should be
fixed.

Happy hacking,
-- 
Petter Reinholdtsen




Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Sun, 26 Oct 2008 17:39:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yves-Alexis Perez <corsac@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Sun, 26 Oct 2008 17:39:08 GMT) Full text and rfc822 format available.

Message #46 received at 448470@bugs.debian.org (full text, mbox):

From: Yves-Alexis Perez <corsac@debian.org>
To: 448470@bugs.debian.org
Cc: 448470-subscribe@bugs.debian.org, Anibal Monsalve Salazar <anibal@debian.org>
Subject: intent to NMU
Date: Sun, 26 Oct 2008 18:38:54 +0100
Is there a reason not to upload an NMU (or even a MU) for this bug?

Cheers,
-- 
Yves-Alexis




Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Sun, 26 Oct 2008 17:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yves-Alexis Perez <corsac@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Sun, 26 Oct 2008 17:48:03 GMT) Full text and rfc822 format available.

Message #51 received at 448470@bugs.debian.org (full text, mbox):

From: Yves-Alexis Perez <corsac@debian.org>
To: 448470@bugs.debian.org
Cc: Anibal Monsalve Salazar <anibal@debian.org>
Subject: Re: intent to NMU
Date: Sun, 26 Oct 2008 18:46:02 +0100
[Message part 1 (text/plain, inline)]
On Sun, Oct 26, 2008 at 06:38:54PM +0100, Yves-Alexis Perez wrote:
> Is there a reason not to upload an NMU (or even a MU) for this bug?

Ok, I'm uploading the attached debdiff to DELAYED/1

Cheers,
-- 
Yves-Alexis
[portmap-nm-448470.diff (text/x-diff, attachment)]

Reply sent to Anibal Monsalve Salazar <anibal@debian.org>:
You have taken responsibility. (Sun, 26 Oct 2008 23:51:09 GMT) Full text and rfc822 format available.

Notification sent to Michael Gebetsroither <gebi@grml.org>:
Bug acknowledged by developer. (Sun, 26 Oct 2008 23:51:09 GMT) Full text and rfc822 format available.

Message #56 received at 448470-close@bugs.debian.org (full text, mbox):

From: Anibal Monsalve Salazar <anibal@debian.org>
To: 448470-close@bugs.debian.org
Subject: Bug#448470: fixed in portmap 6.0-7
Date: Sun, 26 Oct 2008 23:47:09 +0000
Source: portmap
Source-Version: 6.0-7

We believe that the bug you reported is fixed in the latest version of
portmap, which is due to be installed in the Debian FTP archive:

portmap_6.0-7.diff.gz
  to pool/main/p/portmap/portmap_6.0-7.diff.gz
portmap_6.0-7.dsc
  to pool/main/p/portmap/portmap_6.0-7.dsc
portmap_6.0-7_amd64.deb
  to pool/main/p/portmap/portmap_6.0-7_amd64.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 448470@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Anibal Monsalve Salazar <anibal@debian.org> (supplier of updated portmap package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Mon, 27 Oct 2008 10:21:24 +1100
Source: portmap
Binary: portmap
Architecture: source amd64
Version: 6.0-7
Distribution: unstable
Urgency: high
Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Changed-By: Anibal Monsalve Salazar <anibal@debian.org>
Description: 
 portmap    - RPC port mapper
Closes: 448470
Changes: 
 portmap (6.0-7) unstable; urgency=high
 .
   [ Yves-Alexis Perez ]
   * urgency=high for RC bug closing.
   * debian/init.d: use pidofproc to check portmap pid, so it check if portmap
     is running by looking in /var/run/portmap.pid instead of running
     processes. Finally closes: #448470
Checksums-Sha1: 
 98ab313f2ea1affaabf212db9ce87ac8056f1ba6 1049 portmap_6.0-7.dsc
 06ae6c987ec6efc2b5f1ac332d0ff46e8cb1dfef 25649 portmap_6.0-7.diff.gz
 10ede36bfcee6df86532b830094b4f4315bd6576 37146 portmap_6.0-7_amd64.deb
Checksums-Sha256: 
 8864ee18068f3a3afee19b55faec988580e4bba64c837b101040aac2928cb22b 1049 portmap_6.0-7.dsc
 1300d3c5da1afaf166a09138d7281a501c71ff5cb7681e9680cf0b8862ac22ac 25649 portmap_6.0-7.diff.gz
 889428c94234775f86e2b435a18d34754196a02022c1e8f77dd5a667cfd1ee69 37146 portmap_6.0-7_amd64.deb
Files: 
 7bc4d8fba08a825e369c986dfd31da78 1049 net standard portmap_6.0-7.dsc
 9491090ff1710bed6da91c7667b02426 25649 net standard portmap_6.0-7.diff.gz
 f8704eacff68560f1a2c52ca30c07ed0 37146 net standard portmap_6.0-7_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkkFAA4ACgkQgY5NIXPNpFUbjQCeMQeNpz1gA+ETZodB/0X4E3wW
3yoAoJP/ialWNp3ggeVzZzbnIlkWCvG3
=9dT2
-----END PGP SIGNATURE-----





Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Mon, 24 Nov 2008 15:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to maximilian.gass@credativ.de:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Mon, 24 Nov 2008 15:00:02 GMT) Full text and rfc822 format available.

Message #61 received at 448470@bugs.debian.org (full text, mbox):

From: maximilian.gass@credativ.de
To: 448470@bugs.debian.org
Subject: pidofproc falls back to pidof
Date: Mon, 24 Nov 2008 15:57:35 +0100
[Message part 1 (text/plain, inline)]
I suspect this is still not fixed. On a freshly installed Lenny system
of mine, portmap refuses to start stating "Already running". Adding
debug output to the init script shows that $(pidofproc portmap) returns
the PID of the shell running the init script ($$).

pidofproc falls back to pidof when there is no PID file, like on system
startup.

In my case, this leads to statd not being able to register with the
portmapper and my NFS mounts failing.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Mon, 24 Nov 2008 22:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Aníbal Monsalve Salazar <anibal@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Mon, 24 Nov 2008 22:18:02 GMT) Full text and rfc822 format available.

Message #66 received at 448470@bugs.debian.org (full text, mbox):

From: Aníbal Monsalve Salazar <anibal@debian.org>
To: maximilian.gass@credativ.de, 448470@bugs.debian.org
Cc: Petter Reinholdtsen <pere@hungry.com>, Yves-Alexis Perez <corsac@debian.org>
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Tue, 25 Nov 2008 09:15:16 +1100
[Message part 1 (text/plain, inline)]
On Mon, Nov 24, 2008 at 03:57:35PM +0100, maximilian.gass@credativ.de wrote:

>I suspect this is still not fixed. On a freshly installed Lenny system
>of mine,

Maybe that's how I could reproduce this bug. I'll do a fresh lenny
install this coming weekend.

>portmap refuses to start stating "Already running". Adding debug output
>to the init script shows that $(pidofproc portmap) returns the PID of
>the shell running the init script ($$).
>
>pidofproc falls back to pidof when there is no PID file, like on system
>startup.
>
>In my case, this leads to statd not being able to register with the
>portmapper and my NFS mounts failing.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Tue, 25 Nov 2008 16:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philipp Kern <pkern@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Tue, 25 Nov 2008 16:45:02 GMT) Full text and rfc822 format available.

Message #71 received at 448470@bugs.debian.org (full text, mbox):

From: Philipp Kern <pkern@debian.org>
To: Aníbal Monsalve Salazar <anibal@debian.org>, 448470@bugs.debian.org
Cc: maximilian.gass@credativ.de, Petter Reinholdtsen <pere@hungry.com>, Yves-Alexis Perez <corsac@debian.org>, control@bugs.debian.org
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Tue, 25 Nov 2008 17:44:15 +0100
[Message part 1 (text/plain, inline)]
reopen 448470
found 448470 6.0-8
thanks

On Tue, Nov 25, 2008 at 09:15:16AM +1100, Aníbal Monsalve Salazar wrote:
> On Mon, Nov 24, 2008 at 03:57:35PM +0100, maximilian.gass@credativ.de wrote:
> >I suspect this is still not fixed. On a freshly installed Lenny system
> >of mine,
> Maybe that's how I could reproduce this bug. I'll do a fresh lenny
> install this coming weekend.

*argh* pidofproc returns the pid of the init script -> portmap does not start
at all -> rpc.statd and other NFS daemons do not start.  This affects lenny
and severely breaks on-boot mounting of NFS shares.

Kind regards,
Philipp Kern
[signature.asc (application/pgp-signature, inline)]

Bug reopened, originator not changed. Request was from Philipp Kern <pkern@debian.org> to control@bugs.debian.org. (Tue, 25 Nov 2008 16:45:04 GMT) Full text and rfc822 format available.

Bug marked as found in version 6.0-8. Request was from Philipp Kern <pkern@debian.org> to control@bugs.debian.org. (Tue, 25 Nov 2008 16:45:05 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Tue, 25 Nov 2008 17:09:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petter Reinholdtsen <pere@hungry.com>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Tue, 25 Nov 2008 17:09:08 GMT) Full text and rfc822 format available.

Message #80 received at 448470@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <pere@hungry.com>
To: Philipp Kern <pkern@debian.org>
Cc: Aníbal Monsalve Salazar <anibal@debian.org>, 448470@bugs.debian.org, maximilian.gass@credativ.de, Yves-Alexis Perez <corsac@debian.org>
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Tue, 25 Nov 2008 18:07:40 +0100
[Philipp Kern]
> *argh* pidofproc returns the pid of the init script -> portmap does
> not start at all -> rpc.statd and other NFS daemons do not start.
> This affects lenny and severely breaks on-boot mounting of NFS
> shares.

Hm, is this the /lib/lsb/init-functions implementation of pidofproc?
It seem to be completely useless if it behave as described here.

I tested this in etch and unstable.  It do not work this way in etch:

  % cat x
  #!/bin/sh
  . /lib/lsb/init-functions
  pid=`pidofproc x`
  echo $pid
  % PATH=.:$PATH x

  %

While in unstabe, the same script return a pid:

  % PATH=.:$PATH x
  18769
  %

I would say this is a bug in lsb-base.  Version 3.1-23.2etch1 work,
while 3.2-20 do not.

This is the working version:

pidofproc () {
    local pidfile line i pids= status specified pid
    pidfile=
    specified=

    OPTIND=1
    while getopts p: opt ; do
        case "$opt" in
            p)  pidfile="$OPTARG"; specified=1;;
        esac
    done
    shift $(($OPTIND - 1))

    if [ -z "${pidfile:-}" ]; then
        pidfile=/var/run/${1##*/}.pid
    fi

    if [ -f "$pidfile" ]; then
        read pid < "$pidfile"
        if [ -n "${pid:-}" ]; then
            if $(kill -0 "${pid:-}" 2> /dev/null); then
                echo "$pid"
                return 0
            else
                return 1 # program is dead and /var/run pid file exists
            fi
        fi
    fi
    if [ -x /bin/pidof -a ! "$specified" ]; then
        /bin/pidof -o %PPID $1
        status="$?"
        [ "$status" = 1 ] && return 3 # program is not running
        return 0
    fi
    return 4 # program or service is unknown
}

And this is the diff to the unstable version:

@@ -69,25 +71,31 @@
     done
     shift $(($OPTIND - 1))

-    if [ -z "${pidfile:-}" ]; then
-        pidfile=/var/run/${1##*/}.pid
+    base=${1##*/}
+    if [ ! "$specified" ]; then
+        pidfile="/var/run/$base.pid"
     fi

-    if [ -f "$pidfile" ]; then
+    if [ -n "${pidfile:-}" -a -e "$pidfile" ]; then
         read pid < "$pidfile"
         if [ -n "${pid:-}" ]; then
             if $(kill -0 "${pid:-}" 2> /dev/null); then
                 echo "$pid"
                 return 0
+            elif ps "${pid:-}" >/dev/null 2>&1; then
+                echo "$pid"
+                return 0 # program is running, but not owned by this user
             else
                 return 1 # program is dead and /var/run pid file exists
             fi
         fi
     fi
     if [ -x /bin/pidof -a ! "$specified" ]; then
-        /bin/pidof -o %PPID $1
-        status="$?"
-        [ "$status" = 1 ] && return 3 # program is not running
+        status="0"
+        /bin/pidof -o %PPID -x $1 || status="$?"
+        if [ "$status" = 1 ]; then
+            return 3 # program is not running
+        fi
         return 0
     fi
     return 4 # program or service is unknown


Happy hacking,
-- 
Petter Reinholdtsen






Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Tue, 25 Nov 2008 18:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yves-Alexis Perez <corsac@corsac.net>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Tue, 25 Nov 2008 18:09:03 GMT) Full text and rfc822 format available.

Message #85 received at 448470@bugs.debian.org (full text, mbox):

From: Yves-Alexis Perez <corsac@corsac.net>
To: Petter Reinholdtsen <pere@hungry.com>
Cc: Philipp Kern <pkern@debian.org>, Aníbal Monsalve Salazar <anibal@debian.org>, 448470@bugs.debian.org, maximilian.gass@credativ.de, Yves-Alexis Perez <corsac@debian.org>
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Tue, 25 Nov 2008 19:06:04 +0100
On Tue, Nov 25, 2008 at 06:07:40PM +0100, Petter Reinholdtsen wrote:
> [Philipp Kern]
> > *argh* pidofproc returns the pid of the init script -> portmap does
> > not start at all -> rpc.statd and other NFS daemons do not start.
> > This affects lenny and severely breaks on-boot mounting of NFS
> > shares.
> 
> Hm, is this the /lib/lsb/init-functions implementation of pidofproc?
> It seem to be completely useless if it behave as described here.
> 
> I tested this in etch and unstable.  It do not work this way in etch:
> 
>   % cat x
>   #!/bin/sh
>   . /lib/lsb/init-functions
>   pid=`pidofproc x`
>   echo $pid
>   % PATH=.:$PATH x
> 
>   %
> 
> While in unstabe, the same script return a pid:
> 
>   % PATH=.:$PATH x
>   18769
>   %
> 
> I would say this is a bug in lsb-base.  Version 3.1-23.2etch1 work,
> while 3.2-20 do not.

Hmhm yes that looks spurious. It's weird nobody noticed this before,
because it should break in many situations…

-- 
Yves-Alexis




Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Tue, 25 Nov 2008 19:03:03 GMT) Full text and rfc822 format available.

Message #88 received at 448470@bugs.debian.org (full text, mbox):

From: Philipp Kern <pkern@debian.org>
To: Yves-Alexis Perez <corsac@corsac.net>
Cc: Petter Reinholdtsen <pere@hungry.com>, Aníbal Monsalve Salazar <anibal@debian.org>, 448470@bugs.debian.org, maximilian.gass@credativ.de, Yves-Alexis Perez <corsac@debian.org>
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Tue, 25 Nov 2008 19:57:45 +0100
[Message part 1 (text/plain, inline)]
On Tue, Nov 25, 2008 at 07:06:04PM +0100, Yves-Alexis Perez wrote:
> Hmhm yes that looks spurious. It's weird nobody noticed this before,
> because it should break in many situations…

It's possible that it does break here due to subshell usage.  Maybe
adding `-o $$' to pidof calls would help to catch another case, as the
invocation of pidof already tries to leave the parent out, but maybe
it misses some processes on the chain.

Kind regards,
Philipp Kern
-- 
 .''`.  Philipp Kern                        Debian Developer
: :' :  http://philkern.de                         Release Assistant
`. `'   xmpp:phil@0x539.de                         Stable Release Manager
  `-    finger pkern/key@db.debian.org
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Tue, 25 Nov 2008 22:24:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arthur de Jong <adejong@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Tue, 25 Nov 2008 22:24:03 GMT) Full text and rfc822 format available.

Message #93 received at 448470@bugs.debian.org (full text, mbox):

From: Arthur de Jong <adejong@debian.org>
To: 506429@bugs.debian.org, 448470@bugs.debian.org
Subject: bugs are the same
Date: Tue, 25 Nov 2008 23:21:15 +0100
[Message part 1 (text/plain, inline)]
Bugs #506429 and #448470 are the same. Also, a workaround (if you can't
downgrade to 6.0-7) is to add
  ASYNCMOUNTNFS=no
to /etc/default/rcS (at least until this is fixed).

-- 
-- arthur - adejong@debian.org - http://people.debian.org/~adejong --
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Wed, 26 Nov 2008 07:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yves-Alexis Perez <corsac@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Wed, 26 Nov 2008 07:06:03 GMT) Full text and rfc822 format available.

Message #98 received at 448470@bugs.debian.org (full text, mbox):

From: Yves-Alexis Perez <corsac@debian.org>
To: Petter Reinholdtsen <pere@hungry.com>, 448470@bugs.debian.org
Cc: Philipp Kern <pkern@debian.org>, Aníbal Monsalve Salazar <anibal@debian.org>, maximilian.gass@credativ.de
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Wed, 26 Nov 2008 08:05:00 +0100
[Message part 1 (text/plain, inline)]
On mar, 2008-11-25 at 18:07 +0100, Petter Reinholdtsen wrote:
> 
> [Philipp Kern]
> > *argh* pidofproc returns the pid of the init script -> portmap does
> > not start at all -> rpc.statd and other NFS daemons do not start.
> > This affects lenny and severely breaks on-boot mounting of NFS
> > shares.
> 
> Hm, is this the /lib/lsb/init-functions implementation of pidofproc?
> It seem to be completely useless if it behave as described here.
> 
> I tested this in etch and unstable.  It do not work this way in etch:
> 
>   % cat x
>   #!/bin/sh
>   . /lib/lsb/init-functions
>   pid=`pidofproc x`
>   echo $pid
>   % PATH=.:$PATH x
> 
>   %
> 
> While in unstabe, the same script return a pid:
> 
>   % PATH=.:$PATH x
>   18769
>   %
> 
> I would say this is a bug in lsb-base.  Version 3.1-23.2etch1 work,
> while 3.2-20 do not.

On ntp init, it uses -p $PIDFILE, so the last part is never executed.
I'm not sure if the behavior in intended in lsb-base. But
yes /etc/init.d/portmap and portmap will look the same way in:
ps -o %PID portmap

and this should be the case for all initscripts. We should better
protect us, I'll prepare another NMU with:

diff --git a/debian/init.d b/debian/init.d
index 7692c83..dc35d4b 100644
--- a/debian/init.d
+++ b/debian/init.d
@@ -30,7 +30,7 @@ fi
 case "$1" in
     start)
        log_begin_msg "Starting portmap daemon..."
-       pid=$( pidofproc portmap )
+       pid=$( pidofproc -p /var/run/portmap.pid portmap)
        if [ -n "$pid" ] ; then
              log_begin_msg "Already running."
              log_end_msg 0


btw, in init-function, below pidofproc there's a comment:
# start-stop-daemon uses the same algorithm as "pidofproc" above.

so maybe we wouldn't need to check (using pidofproc) if the program is
running before. For example, ntp doesn't check and relies on
start-stop-daemon.

What do you think?
-- 
Yves-Alexis
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Wed, 26 Nov 2008 08:57:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arthur de Jong <adejong@debian.org>:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Wed, 26 Nov 2008 08:57:07 GMT) Full text and rfc822 format available.

Message #103 received at 448470@bugs.debian.org (full text, mbox):

From: Arthur de Jong <adejong@debian.org>
To: Yves-Alexis Perez <corsac@debian.org>
Cc: Petter Reinholdtsen <pere@hungry.com>, 448470@bugs.debian.org, Philipp Kern <pkern@debian.org>, Aníbal Monsalve Salazar <anibal@debian.org>, maximilian.gass@credativ.de
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Wed, 26 Nov 2008 09:56:14 +0100 (CET)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


I've tested the above patch and it seems to solve the problem. It took me 
a couple of times reading though /lib/lsb/init-functions to understand why 
though (use of $specified is confusing).

Also this problem doesn't seem to show in all circumstances. It shows up 
on systems with and /etc/network/interfaces like:
  auto lo eth0
  iface lo inet loopback
  iface eth0 inet dhcp
but not with:
  auto lo
  iface lo inet loopback
  allow-hotplug eth0
  iface eth0 inet dhcp
(the second was on a machine that was more recently installed)

- -- 
- -- arthur - adejong@debian.org - http://people.debian.org/~adejong --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFJLQ8xVYan35+NCKcRAiTYAKDl7aNSWNLKs+1ubN0+HrVicdmgEACfT8ox
f5uXIUK2j7k2Z1fgAoht2UA=
=/UbY
-----END PGP SIGNATURE-----




Reply sent to Anibal Monsalve Salazar <anibal@debian.org>:
You have taken responsibility. (Wed, 26 Nov 2008 10:33:15 GMT) Full text and rfc822 format available.

Notification sent to Michael Gebetsroither <gebi@grml.org>:
Bug acknowledged by developer. (Wed, 26 Nov 2008 10:33:16 GMT) Full text and rfc822 format available.

Message #108 received at 448470-close@bugs.debian.org (full text, mbox):

From: Anibal Monsalve Salazar <anibal@debian.org>
To: 448470-close@bugs.debian.org
Subject: Bug#448470: fixed in portmap 6.0-9
Date: Wed, 26 Nov 2008 10:17:04 +0000
Source: portmap
Source-Version: 6.0-9

We believe that the bug you reported is fixed in the latest version of
portmap, which is due to be installed in the Debian FTP archive:

portmap_6.0-9.diff.gz
  to pool/main/p/portmap/portmap_6.0-9.diff.gz
portmap_6.0-9.dsc
  to pool/main/p/portmap/portmap_6.0-9.dsc
portmap_6.0-9_amd64.deb
  to pool/main/p/portmap/portmap_6.0-9_amd64.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 448470@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Anibal Monsalve Salazar <anibal@debian.org> (supplier of updated portmap package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Wed, 26 Nov 2008 20:14:15 +1100
Source: portmap
Binary: portmap
Architecture: source amd64
Version: 6.0-9
Distribution: unstable
Urgency: medium
Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Changed-By: Anibal Monsalve Salazar <anibal@debian.org>
Description: 
 portmap    - RPC port mapper
Closes: 448470 506429
Changes: 
 portmap (6.0-9) unstable; urgency=medium
 .
   * In both init.d and postinst, replace "pidofproc portmap" with
     "pidofproc -p /var/run/portmap.pid /sbin/portmap";
     closes: #448470, #506429
Checksums-Sha1: 
 9a18962fa344c5e423562ef20ee325eb39a063f7 1049 portmap_6.0-9.dsc
 719126a4ef594eb4d2efb7c1b392c7e17d62e835 25819 portmap_6.0-9.diff.gz
 132daad6300b18c2518b4d5d6e7e5db1740c1235 37318 portmap_6.0-9_amd64.deb
Checksums-Sha256: 
 60f8883e47b1876d479c38b05c3c009dcfc619bccd1433b8abfacea02d533f09 1049 portmap_6.0-9.dsc
 7a51a800d652608cb6c197c951bd75536f6cff6b6e1e2718aca199253ffb61ee 25819 portmap_6.0-9.diff.gz
 18dfc408e53b9eaf3e99730d012e7c38e9f85302684a52c224f3d13c8a0007d6 37318 portmap_6.0-9_amd64.deb
Files: 
 a47f0a290c7cd6b3b6027ab6f778278f 1049 net standard portmap_6.0-9.dsc
 dbd605ad10295b22ad9bb9bfc4fe2b88 25819 net standard portmap_6.0-9.diff.gz
 2ea40c4b4593778f0d30ddc91539a86d 37318 net standard portmap_6.0-9_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkktH7MACgkQgY5NIXPNpFUkaQCgph2dlMbmL/apA6VcUw7M1MZu
7DAAoM05AAkT/tJfts5g05jNI8rFHhVC
=+881
-----END PGP SIGNATURE-----





Information forwarded to debian-bugs-dist@lists.debian.org, Anibal Monsalve Salazar <anibal@debian.org>:
Bug#448470; Package portmap. (Wed, 26 Nov 2008 11:39:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to maximilian.gass@credativ.de:
Extra info received and forwarded to list. Copy sent to Anibal Monsalve Salazar <anibal@debian.org>. (Wed, 26 Nov 2008 11:39:06 GMT) Full text and rfc822 format available.

Message #113 received at 448470@bugs.debian.org (full text, mbox):

From: maximilian.gass@credativ.de
To: 448470@bugs.debian.org
Subject: Re: Bug#448470: pidofproc falls back to pidof
Date: Wed, 26 Nov 2008 12:37:34 +0100
[Message part 1 (text/plain, inline)]
On Wed, Nov 26, 2008 at 08:05:00AM +0100, Yves-Alexis Perez wrote:
> btw, in init-function, below pidofproc there's a comment:
> # start-stop-daemon uses the same algorithm as "pidofproc" above.

I think that's the proper way to go. Quoting the pidof manpage: "If the
system has a start-stop- daemon (8) program that should be used
instead."
[signature.asc (application/pgp-signature, inline)]

Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Wed, 31 Dec 2008 07:27:56 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Wed Apr 16 23:47:13 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.