csirac2 / snazzer

btrfs snapshotting and backup system offering snapshot measurement, transport and pruning.
BSD 2-Clause "Simplified" License
89 stars 9 forks source link

Without perl-doc installed `snazzer --man` doesn't behave well #49

Open jamiereid opened 7 years ago

jamiereid commented 7 years ago

uname -a = Linux 4.8.0-1-amd64 #1 SMP Debian 4.8.7-1 (2016-11-13) x86_64 GNU/Linux Bash version 4.4.5(1)-release

Without perl-doc installed, when running snazzer --man, the source code for snazzer is displayed. After closing (is it less that's used?) a message is presented saying that "You need to install the perl-doc package to use this program".

Expected behaviour: I believe it would be good to, if the dependency isn't there, gracefully fail to the info message instead of opening the source code.

florianjacob commented 7 years ago

It seems like the perl-doc debian package only contains perl manpages, and no executables.

snazzer manpage display generation needs the pod2usage executable, that is bundled with perl in Debian as well. Could it be that you didn't have perl installed, and perl-doc pulled in perl as a dependency?

The code to display the manpage in snazzer essentially boils down to a simple pod2usage --verbose 3 ./snazzer.

Currently investigating how this could result in source code display instead of command not found…

florianjacob commented 7 years ago

Ok, if I replace pod2usage with a command that doesn't exist, I get an error that that command does not exist. This is strange. So I guess you a

Questions:

jamiereid commented 7 years ago

Sorry it's taken a while for me to reply @florianjacob

florianjacob commented 7 years ago

No worries, I now have an idea what's happening there. 😄

I found out that without perl-doc installed, /usr/bin/perldoc contains only this:

#!/bin/sh
# place-holder, diverted by perl-doc
echo You need to install the perl-doc package to use this program. >&2
exit 1

which is (very probably) the thing that's causing the error message.

I guess there's some pipe in pod2usage /usr/bin/snazzer like cat /usr/bin/snazzer | perldoc --some-options | $PAGER, which would explain the observed behaviour.

There's nothing we can do about this in our usage of pod2usage, it seems.

Calling perldoc without arguments returns 255 on Debian 7 Wheezy, 22 using the current perl version on Arch Linux. So we could probably work around this Debian packaging by introducing a check into the --man branch like:

…
perldoc
if [ $? -eq 1 ]
  printf "Calling perldoc returned 1. You're probably running Debian and are missing the perl-doc package for this function." >&2
  exit 1
fi
…

Of course this somewhat ugly and depends on the real perldoc never returning 1. @csirac2 what do you think of this?

I'm a little reluctant to add this code as a permanent workaround for what seems like a downstream packaging bug, though.

It would be interesting to hear the Debian packager's stance to this. Maybe they're not aware that pod2usage might use perldoc in this way, or at least have a better idea how one should check whether their perldoc works or not.

Note that this isn't snazzer-specific at all, you can actually reproduce this with any text file, e.g. pod2usage --verbose 3 /usr/bin/pod2usage or even pod2usage --verbose 3 /etc/os-release. Each of those will first show the file and afterwards display the error message.

@jamiereid, in case you want to help @csirac and me out some more, do you think you could open a Debian bug about pod2usage behaving like you described, and post the link here?

csirac2 commented 7 years ago

I'm aware of the perl-doc limitation. I'm not sure we want to complicate snazzer here; perhaps this would be a problem best solved by doing proper releases with pre-compiled man pages.

I think the actionable thing here for this bug is to ensure we're failing loudly during make if man pages can't be generated properly; we should create a separate issue for packaging and/or proper tarball releases.

jamiereid commented 7 years ago

Would implementing something like:

cover the "failing loudly during make if the man pages can't be generated properly"?

csirac2 commented 7 years ago

AFAIK the dummy pod2usage already exits non-zero, is that the case? We just want the "build" to fail if build dependencies are missing

jamiereid commented 7 years ago

Strange thing is, at least on Debian Jessie, the pod2usage call for snazzer --help works, it's only when you attempt the pod2usage -verbose 3 call that it fails without the real perldoc installed. Without perl-doc installed /usr/bin/perldoc is a simple shell script telling you to install perl-doc

That's lead me to think the problem is more around perl-doc missing and less around pod2usage. Have I followed a red herring?

florianjacob commented 7 years ago

@jamiereid No, you're right. :smile: I found the same and tried to express that in https://github.com/csirac2/snazzer/issues/49#issuecomment-266236004 .

pod2usage is fully functional without perl-doc installed, except in the case of -verbose 3 where manpages are generated. In that case, the dummy perldoc is still executed, but pod2usage doesn't expect perldoc to return -1 and no output, which leads to this strange behaviour. A real perldoc called without arguments returns neither 0 or 1 but something higher, so we could use this to make the check in the Makefile.