#764521 debirf: gpm fails to install in debirf

Package:
gpm
Source:
gpm
Description:
General Purpose Mouse interface
Submitter:
jhcha54008
Date:
2014-11-13 21:24:14 UTC
Severity:
normal
#764521#5
Date:
2014-10-08 21:25:19 UTC
From:
To:
Dear Maintainer,

Installing gpm in a debirf instance results in an error :

$ debirf make minimal
[ ... ]
$ debirf enter minimal
# apt-get update
# apt-get install gpm
[ ... ]
Unpacking gpm (1.20.4-6.1) ...
E: Sub-process /usr/bin/dpkg returned an error code (1)

The postinst script tries to set up a link under /dev (lines 51-55
- gpm version 1.20.4-6.1) :
  if [ -n "$repeat_type" ] && [ "$repeat_type" != "none" ]; then
    ln -s gpmdata /dev/mouse
  else
    ln -s ${device#/dev/} /dev/mouse
  fi

It fails because of insufficient permissions to write in /dev
on the build machine (#686881 is similar in trying to make
directories under /dev)

This error doesn't occur if I make use of a wrapper as ln_in_dev.sh
below :
$ export FAKECHROOT_CMD_SUBST=/bin/ln=$(readlink -f ln_in_dev.sh)
$ debirf enter minimal
# apt-get install gpm
[ ... ]
Setting up gpm (1.20.4-6.1) ...

Creating config file /etc/gpm.conf with new version
open: No such file or directory
ioctl: Bad file descriptor
[ ok ] Stopping mouse interface server: gpm.
[....] Starting mouse interface server: gpm/etc/init.d/gpm: 66: /etc/init.d/gpm: cannot open /dev/input/mice: No such file
invoke-rc.d: initscript gpm, action "restart" failed.
dpkg: error processing package gpm (--configure):
 subprocess installed post-installation script returned error exit status 2
E: Sub-process /usr/bin/dpkg returned an error code (1)

The second error occurs when gpm is started (on the build machine !)
by the postinst script (lines 90-94) :
db_get gpm/restart
if [ "$RET" = true ] || /usr/lib/gpm/gpm_has_mouse_control; then
  # Note, yes, this is restart, its ment to be..
  invoke-rc.d gpm restart
fi

We may disable  /usr/lib/gpm/gpm_has_mouse_control :
$ export FAKECHROOT_CMD_SUBST="${FAKECHROOT_CMD_SUBST:+${FAKECHROOT_CMD_SUBST}:}/usr/lib/gpm/gpm_has_mouse_control=/bin/false"
(Or we may solve #754470. But gpm_has_mouse_control triggers a message anyway :
open: No such file or directory
ioctl: Bad file descriptor
)

Regards,
JH Chatenet

File ln_in_dev.sh :
----------8<-------------------8<--------------------
#!/bin/bash

# ln
#
# Wrapper for /bin/ln.
# Write in /dev outside of fakechroot environment.
# May be needed to install gpm.

fakechroot_wrapper_base="$FAKECHROOT_BASE_ORIG"

# is /dev an excluded path ?
dev_is_excluded=`
    IFS=:
    for target_d in $FAKECHROOT_EXCLUDE_PATH; do
        if [ "$target_d" = "/dev" ]; then
            echo "1"
            exit
        fi
    done
    echo "0"
`

# link name
make_replacement() {
    filename="$1"
# is it a relative path ?
    if [ "${filename#/}" = "$filename" ]; then
        absfilename=$(readlink -m "$filename")
        filename="$absfilename"
    fi

# is a symlink to be created in /dev ?
    if [ "$filename" = "/dev" -o "${filename#/dev/}" != "$filename" ]; then
        replacement="${fakechroot_wrapper_base}${filename}"
    fi
}

# walk through command line arguments
is_replacement_needed() {
  is_symbolic=0
  ln_arg_nr=0
# parse options
  while [ $# -gt 0 ]; do
    ln_arg_nr=$(($ln_arg_nr + 1))
    case "$1" in
      -s|--symbolic)
        is_symbolic=1
        shift
        ;;
      -t|--target-directory)
        fourth_form=1
        make_replacement "$2"
        if [ -n "$replacement" ]; then
          replacement_nr=$(($ln_arg_nr + 1))
        fi
        shift 2
        ;;
      --target-directory=*)
        fourth_form=1
        make_replacement "${1#--target-directory=}"
        if [ -n "$replacement" -a -z "$replacement_nr" ]; then
          replacement_nr=$ln_arg_nr
          replacement="--target-directory=$replacement"
        fi
        shift
        ;;
      --)
        shift
        break
        ;;
      -*)
        shift
        ;;
      *)
        break
        ;;
    esac
  done


  if [ "$is_symbolic" = "0" ]; then
    replacement=
    replacement_nr=
    return
  elif [ "$fourth_form" = "1" ]; then
# fourth syntactical form in the man page
    return
  elif [ $# -eq 1 ]; then
# second syntactical form in the man page
    make_replacement "."
    if [ -n "$replacement" ]; then
      replacement_nr=$(($ln_arg_nr + 1))
    fi
  else
# first or third syntactical form in the man page
    ln_arg_nr=$(($ln_arg_nr + $# - 1))
    shift $(($# - 1 ))
    make_replacement "$1"
    if [ -n "$replacement" ]; then
      replacement_nr=$ln_arg_nr
    fi
  fi

}

# calculate a replacement of destination
if [ $dev_is_excluded -eq 1 ]; then
  is_replacement_needed "$@"
fi

# set up the link
if [ -n "$replacement_nr" ]; then
  ln "${@:1:$(($replacement_nr - 1))}" "$replacement" "${@:$(($replacement_nr + 1))}"
else
  env -u FAKECHROOT_BASE_ORIG FAKECHROOT_BASE="$fakechroot_wrapper_base" ln "$@"
fi
----------8<-------------------8<--------------------

#764521#12
Date:
2014-10-08 20:00:57 UTC
From:
To:
hi there--

This strikes me as a bug in gpm more than anything else.  almost all
systems have a dynamic /dev these days, and creating a new symlink in
the postinst script isn't guaranteed to make anything work in the
future.  gpm will have to be cleverer than that, and it really shouldn't
fail to install just because /dev isn't writable at package installation
time.

Have you tested with debootstrap --fakechroot ?

#764521#17
Date:
2014-10-09 00:22:00 UTC
From:
To:
Le mercredi  8 octobre à 16h 00mn 57s (-0400), Daniel Kahn Gillmor a écrit :

Same result with debootstrap (using the workaround of #763391) :

$ export FAKECHROOT_CMD_SUBST=/usr/bin/chfn=$(readlink -f chfn.fakechroot)
$ fakechroot fakeroot -s .fakeroot.state debootstrap --variant=fakechroot --include=gpm,busybox-static,gpgv,less \
 --exclude=apt-utils,bsdmainutils,cron,ed,info,logrotate,man-db,manpages,tasksel,tasksel-data,tcpd,traceroute jessie my_chroot
[ ... ]
I: Configuring rsyslog...
W: Failure while configuring base packages.  This will be re-attempted up to five times.
W: See /home/me/my_chroot/debootstrap/debootstrap.log for details (possibly the package gpm is at fault)
I: Configuring gpm...
W: Failure while configuring base packages.  This will be re-attempted up to five times.
W: See /home/me/my_chroot/debootstrap/debootstrap.log for details (possibly the package gpm is at fault)
W: Failure while configuring base packages.  This will be re-attempted up to five times.
W: See /home/me/my_chroot/debootstrap/debootstrap.log for details (possibly the package gpm is at fault)
W: Failure while configuring base packages.  This will be re-attempted up to five times.
W: See /home/me/my_chroot/debootstrap/debootstrap.log for details (possibly the package gpm is at fault)
W: Failure while configuring base packages.  This will be re-attempted up to five times.
W: See /home/me/my_chroot/debootstrap/debootstrap.log for details (possibly the package gpm is at fault)

$ cat my_chroot/debootstrap/debootstrap.log
[ ... ]
Setting up gpm (1.20.4-6.1) ...
ln: failed to create symbolic link '/dev/mouse': Permission denied
dpkg: error processing package gpm (--configure):
 subprocess installed post-installation script returned error exit status 1
[ ... ]
Errors were encountered while processing:
 gpm
Setting up gpm (1.20.4-6.1) ...
ln: failed to create symbolic link '/home/moi/my_chroot/dev/mouse': Permission denied
dpkg: error processing package gpm (--configure):
 subprocess installed post-installation script returned error exit status 1

(four times)

The workaroud (export FAKECHROOT_CMD_SUBST=/bin/ln=$(readlink -f ln_in_dev.sh))
is of no help, as debootstrap --variant fakechroot set up a symlink my_chroot/dev
pointing to /dev (debootstrap 1.0.63, /usr/share/debootstrap/functions lines 1073-1076 :

setup_devices_fakechroot () {
        rm -rf "$TARGET/dev"
        ln -s /dev "$TARGET"
}
)

Regards,
JH Chatenet

#764521#28
Date:
2014-11-13 22:24:14 UTC
From:
To:
Hi,

The following patch (against gpm version 1.20.4-6.1) solved
the second issue for me (gpm restart and
gpm_has_mouse_control giving an error).

I hope it will help.

Regards,
JH Chatenet

diff -Naur a/DEBIAN/postinst b/DEBIAN/postinst
--- a/DEBIAN/postinst	2014-11-13 20:28:55.000000000 +0100
+++ b/DEBIAN/postinst	2014-11-13 20:40:37.000000000 +0100
@@ -87,10 +87,12 @@

 update-rc.d gpm defaults >/dev/null