pkg: Add limited --debug/-d support

Add an internal debug level global:
 - Level 1 (-d) currently does nothing.

 - Level 2 (-d -d) enables libfetch debugging (quite verbose) so it's
   possible to see what pkg is attempting to download without having
   to sniff traffic.

Reviewed by:	debdrup, bapt
Differential Revision:	https://reviews.freebsd.org/D35756
This commit is contained in:
Brooks Davis 2022-08-24 18:32:09 +01:00
parent 8036234c72
commit e9ad2964f5
2 changed files with 24 additions and 4 deletions

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 30, 2022
.Dd August 24, 2022
.Dt PKG 7
.Os
.Sh NAME
@ -32,16 +32,17 @@
.Nd a utility for manipulating packages
.Sh SYNOPSIS
.Nm
.Op Fl d
.Ar command ...
.Nm
.Cm add
.Op Fl fy
.Op Fl dfy
.Op Fl r Ar reponame
.Ar pkg.txz
.Nm
.Fl N
.Nm
.Op Fl 46
.Op Fl 46d
.Cm bootstrap
.Op Fl fy
.Op Fl r Ar reponame
@ -121,6 +122,17 @@ If a
.Ar reponame
has been specified, then the configuration for that repository will be used.
.El
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width indent
.It Fl d, Fl -debug
Show debug information.
May be specified more than once to increase the level of detail.
When specified twice,
.Xr fetch 3
debug output is enabled.
.El
.Sh CONFIGURATION
Configuration varies in whether it is in a repository configuration file
or the global configuration file.

View File

@ -91,6 +91,8 @@ static const char *bootstrap_names [] = {
STAILQ_HEAD(fingerprint_list, fingerprint);
static int debug;
static int
extract_pkg_static(int fd, char *p, int sz)
{
@ -1113,6 +1115,7 @@ main(int argc, char *argv[])
yes = false;
struct option longopts[] = {
{ "debug", no_argument, NULL, 'd' },
{ "force", no_argument, NULL, 'f' },
{ "only-ipv4", no_argument, NULL, '4' },
{ "only-ipv6", no_argument, NULL, '6' },
@ -1122,8 +1125,11 @@ main(int argc, char *argv[])
snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", getlocalbase());
while ((ch = getopt_long(argc, argv, "-:fr::yN46", longopts, NULL)) != -1) {
while ((ch = getopt_long(argc, argv, "-:dfr::yN46", longopts, NULL)) != -1) {
switch (ch) {
case 'd':
debug++;
break;
case 'f':
force = true;
break;
@ -1220,6 +1226,8 @@ main(int argc, char *argv[])
break;
}
}
if (debug > 1)
fetchDebug = 1;
if ((bootstrap_only && force) || access(pkgpath, X_OK) == -1) {
/*