Control: tags -1 + confirmed upstream

Hello James Cowgill,

Thanks for your bug report.

On Wed, Jan 25, 2017 at 02:57:01PM +0000, James Cowgill wrote:
[...]
> As the subject says, if there is no pager installed then the fdisk 'l'
> command does not work. Example:
[...]
> > Command (m for help): l
> > sh: 1: less: not found
> > 

Yes, less is used if PAGER is unset:
http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L181

This problem can also be reproduced by using:
PAGER="foobar" fdisk /dev/sda

We could carry a patch in Debian to make 'sensible-pager' the default
(instead of less) but even that can sometimes fail, so I'd rather see
the case of not being able to start the pager handled.

The start_command function tries to promise us that it'll close the
pager fd if launching the pager fails:
http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L59

Unfortunately its attempt is not good enough, since the pager is wrapped
in 'sh -c $PAGER' (to search PATH for the given pager?):
http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L25
http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L187
This means we'll always succeed in exec:ing the process, but then sh
will exit with an error code later when it doesn't find the actual pager
program. When sh exits, it's already to late for start_command to catch
that.

Help welcome in figuring out a way to catch this case.

Possibly hooking up SIGCHLD and introducing a small delay in
the end of pager_open could work, but the delay has to be
small enough to not be annoying (less than half a second?)
and large enough for slow machines to have time (likely several
seconds?). I guess there's no way to please everybody so maybe
just waiting a short time is good enough for most cases even
though not completely reliable.

Another option might be to make the util-linux build system
detect full path of less during configure, then add code to
check if the file exists or bail out early at:
http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L59

The latter one might be the better solution as it should be more
reliable. It doesn't solve the PAGER="foobar" case but I guess you
get to keep both halves if you actively break it like that.

> 
> Setting PAGER=/bin/more (which obviously will exist) can workaround it,
> but fdisk should fallback to that automatically when less does not exist
> (or just use that anyway when PAGER is not set).

Another workaround is to disable paging which can be done using:
PAGER="" fdisk /dev/sda

(Using PAGER="cat" also works.)

Regards,
Andreas Henriksson

Reply via email to