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=e892aa4fdc56459ed60ae7e8c857eb364cbc0d8d

commit e892aa4fdc56459ed60ae7e8c857eb364cbc0d8d
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Aug 13 18:59:39 2022 +0200

    dpkg-deb: Move DPKG_DEB_THREADS_MAX parsing from libdpkg
    
    This environment variable is dpkg-deb specific, and has no place in the
    generic libdpkg code.
    
    Changelog: internal
---
 lib/dpkg/compress.c | 19 -------------------
 src/deb/main.c      | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c
index dfb6a6dea..8cfba80cc 100644
--- a/lib/dpkg/compress.c
+++ b/lib/dpkg/compress.c
@@ -697,25 +697,10 @@ filter_xz_get_memlimit(void)
        return mt_memlimit;
 }
 
-static long
-parse_threads_max(const char *str)
-{
-       long value;
-       char *end;
-
-       errno = 0;
-       value = strtol(str, &end, 10);
-       if (str == end || *end != '\0' || errno != 0)
-               return 0;
-
-       return value;
-}
-
 static uint32_t
 filter_xz_get_cputhreads(struct compress_params *params)
 {
        long threads_max;
-       const char *env;
 
        threads_max = lzma_cputhreads();
        if (threads_max == 0)
@@ -724,10 +709,6 @@ filter_xz_get_cputhreads(struct compress_params *params)
        if (params->threads_max >= 0)
                return clamp(params->threads_max, 1, threads_max);
 
-       env = getenv("DPKG_DEB_THREADS_MAX");
-       if (str_is_set(env))
-               return clamp(parse_threads_max(env), 1, threads_max);
-
        return threads_max;
 }
 #endif
diff --git a/src/deb/main.c b/src/deb/main.c
index d1e6fbb08..fb997b335 100644
--- a/src/deb/main.c
+++ b/src/deb/main.c
@@ -202,6 +202,20 @@ set_compress_type(const struct cmdinfo *cip, const char 
*value)
     badusage(_("obsolete compression type '%s'; use xz or gzip instead"), 
value);
 }
 
+static long
+parse_threads_max(const char *str)
+{
+  long value;
+  char *end;
+
+  errno = 0;
+  value = strtol(str, &end, 10);
+  if (str == end || *end != '\0' || errno != 0)
+    return 0;
+
+  return value;
+}
+
 static void
 set_threads_max(const struct cmdinfo *cip, const char *value)
 {
@@ -240,10 +254,15 @@ static const struct cmdinfo cmdinfos[]= {
 
 int main(int argc, const char *const *argv) {
   struct dpkg_error err;
+  char *env;
   int ret;
 
   dpkg_locales_init(PACKAGE);
   dpkg_program_init(BACKEND);
+  /* XXX: Integrate this into options initialization/parsing. */
+  env = getenv("DPKG_DEB_THREADS_MAX");
+  if (str_is_set(env))
+    compress_params.threads_max = parse_threads_max(env);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 
   if (!cipaction) badusage(_("need an action option"));

-- 
Dpkg.Org's dpkg

Reply via email to