This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=74100d9d04efeee4dd1b3fbe3fd5d10ccc2f92b6 commit 74100d9d04efeee4dd1b3fbe3fd5d10ccc2f92b6 (HEAD -> main) Author: Guillem Jover <[email protected]> AuthorDate: Sun Nov 27 03:25:15 2022 +0100 libdpkg: Add support for a new DPKG_DEBUG environment variable This makes it possible to set the debugging mask for any program calling the dpkg_program_init() function. --- lib/dpkg/debug.c | 19 +++++++++++++++++++ lib/dpkg/debug.h | 1 + lib/dpkg/libdpkg.map | 1 + lib/dpkg/program.c | 2 ++ man/dpkg-divert.pod | 6 ++++++ man/dpkg-query.pod | 6 ++++++ man/dpkg-split.pod | 6 ++++++ man/dpkg-statoverride.pod | 6 ++++++ man/dpkg-trigger.pod | 6 ++++++ man/dpkg.pod | 5 +++++ 10 files changed, 58 insertions(+) diff --git a/lib/dpkg/debug.c b/lib/dpkg/debug.c index efd8c70a4..115d45545 100644 --- a/lib/dpkg/debug.c +++ b/lib/dpkg/debug.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <dpkg/dpkg.h> +#include <dpkg/i18n.h> #include <dpkg/report.h> #include <dpkg/debug.h> @@ -112,3 +113,21 @@ debug(int flag, const char *fmt, ...) va_end(args); putc('\n', debug_output); } + +/** + * Initialize the debugging support. + */ +void +dpkg_debug_init(void) +{ + const char envvar[] = "DPKG_DEBUG"; + const char *env; + + env = getenv(envvar); + if (env == NULL) + return; + + if (debug_parse_mask(env) < 0) + warning(_("cannot parse debug mask from environment variable %s"), + envvar); +} diff --git a/lib/dpkg/debug.h b/lib/dpkg/debug.h index bb08a1543..c276ec57e 100644 --- a/lib/dpkg/debug.h +++ b/lib/dpkg/debug.h @@ -54,6 +54,7 @@ enum debugflags { dbg_triggersstupid = 040000, }; +void dpkg_debug_init(void); void debug_set_output(FILE *output, const char *filename); void debug_set_mask(int mask); int debug_parse_mask(const char *str); diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index a525f4fee..64c62879b 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -71,6 +71,7 @@ LIBDPKG_PRIVATE { debug_parse_mask; debug_has_flag; debug; + dpkg_debug_init; # Generic cleanup cu_closepipe; diff --git a/lib/dpkg/program.c b/lib/dpkg/program.c index 09a2c0cfb..12226c0c4 100644 --- a/lib/dpkg/program.c +++ b/lib/dpkg/program.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <dpkg/progname.h> +#include <dpkg/debug.h> #include <dpkg/report.h> #include <dpkg/ehandle.h> #include <dpkg/program.h> @@ -40,6 +41,7 @@ dpkg_program_init(const char *progname) { dpkg_set_progname(progname); dpkg_set_report_buffer(stdout); + dpkg_debug_init(); push_error_context(); diff --git a/man/dpkg-divert.pod b/man/dpkg-divert.pod index 99c6ca62e..8392611b3 100644 --- a/man/dpkg-divert.pod +++ b/man/dpkg-divert.pod @@ -185,6 +185,12 @@ specified, it will be used as the B<dpkg> data directory. If set and the B<--local> and B<--package> options have not been specified, B<dpkg-divert> will use it as the package name. +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<dpkg --debug> option, +but not all these flags might have an effect on this program. + =item B<DPKG_COLORS> Sets the color mode (since dpkg 1.18.5). diff --git a/man/dpkg-query.pod b/man/dpkg-query.pod index d07bedee0..7db0957d1 100644 --- a/man/dpkg-query.pod +++ b/man/dpkg-query.pod @@ -517,6 +517,12 @@ be used as the filesystem root directory (since dpkg 1.21.0). If set and the B<--admindir> option has not been specified, it will be used as the B<dpkg> data directory. +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<dpkg --debug> option, +but not all these flags might have an effect on this program. + =item B<DPKG_COLORS> Sets the color mode (since dpkg 1.18.5). diff --git a/man/dpkg-split.pod b/man/dpkg-split.pod index 4fbba64ba..6419c1a15 100644 --- a/man/dpkg-split.pod +++ b/man/dpkg-split.pod @@ -249,6 +249,12 @@ memory allocations, etc. =over +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<dpkg --debug> option, +but not all these flags might have an effect on this program. + =item B<DPKG_COLORS> Sets the color mode (since dpkg 1.18.5). diff --git a/man/dpkg-statoverride.pod b/man/dpkg-statoverride.pod index f32dc1596..3c4e6649c 100644 --- a/man/dpkg-statoverride.pod +++ b/man/dpkg-statoverride.pod @@ -191,6 +191,12 @@ specified, it will be used as the filesystem root directory If set and the B<--admindir> or B<--root> options have not been specified, it will be used as the B<dpkg> data directory. +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<dpkg --debug> option, +but not all these flags might have an effect on this program. + =item B<DPKG_FORCE> If set and none of the B<--force->I<...> options have been diff --git a/man/dpkg-trigger.pod b/man/dpkg-trigger.pod index eba3622ce..b5757482f 100644 --- a/man/dpkg-trigger.pod +++ b/man/dpkg-trigger.pod @@ -140,6 +140,12 @@ the filesystem root directory (since dpkg 1.21.0). If set and the B<--admindir> option has not been specified, it will be used as the B<dpkg> data directory. +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<dpkg --debug> option, +but not all these flags might have an effect on this program. + =item B<DPKG_COLORS> Sets the color mode (since dpkg 1.18.5). diff --git a/man/dpkg.pod b/man/dpkg.pod index fd1b026b3..6ceab28c9 100644 --- a/man/dpkg.pod +++ b/man/dpkg.pod @@ -1202,6 +1202,11 @@ Sets the color mode (since dpkg 1.18.5). The currently accepted values are: B<auto> (default), B<always> and B<never>. +=item B<DPKG_DEBUG> + +Sets the debug mask (since dpkg 1.21.10) from an octal value. +The currently accepted flags are described in the B<--debug> option. + =item B<DPKG_FORCE> Sets the force flags (since dpkg 1.19.5). -- Dpkg.Org's dpkg

