This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

commit 44b0bf1a576e3b0cfcb4c87f18d4195c3ffccb8f
Author: Guillem Jover <[email protected]>
Date:   Mon Oct 9 08:15:25 2017 +0200

    dpkg: Print the package name on maintainter script errors
    
    When processing an archive or a package, we can call maintainer script
    for other packages. Not printing the package name for the script that
    failed means we can get very confusing output.
    
    Closes: #877521
---
 debian/changelog |  1 +
 src/script.c     | 29 ++++++++++++++++++++++-------
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4416caa..db66fbf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -46,6 +46,7 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
   * Make --uniform-compression the new default dpkg-deb behavior. Add support
     for negating the option via --no-uniform-compression.
   * Clarify subprocess error message by shuffling words around.
+  * Print the package name on maintainter script errors. Closes: #877521
   * Perl modules:
     - Switch from Dpkg::Util to List::Util, now that the module in the
       new required Perl contains the needed functions.
diff --git a/src/script.c b/src/script.c
index 2f252ae..ac58779 100644
--- a/src/script.c
+++ b/src/script.c
@@ -212,10 +212,11 @@ vmaintscript_installed(struct pkginfo *pkg, const char 
*scriptname,
        struct command cmd;
        const char *scriptpath;
        struct stat stab;
-       char buf[100];
+       char *buf;
 
        scriptpath = pkg_infodb_get_file(pkg, &pkg->installed, scriptname);
-       sprintf(buf, _("installed %s script"), desc);
+       m_asprintf(&buf, _("installed %s package %s script"),
+                  pkg_name(pkg, pnaw_nonambig), desc);
 
        command_init(&cmd, scriptpath, buf);
        command_add_arg(&cmd, scriptname);
@@ -223,6 +224,8 @@ vmaintscript_installed(struct pkginfo *pkg, const char 
*scriptname,
 
        if (stat(scriptpath, &stab)) {
                command_destroy(&cmd);
+               free(buf);
+
                if (errno == ENOENT) {
                        debug(dbg_scripts,
                              "vmaintscript_installed nonexistent %s",
@@ -234,6 +237,7 @@ vmaintscript_installed(struct pkginfo *pkg, const char 
*scriptname,
        maintscript_exec(pkg, &pkg->installed, &cmd, &stab, 0);
 
        command_destroy(&cmd);
+       free(buf);
 
        return 1;
 }
@@ -282,10 +286,11 @@ maintscript_new(struct pkginfo *pkg, const char 
*scriptname,
        struct command cmd;
        struct stat stab;
        va_list args;
-       char buf[100];
+       char *buf;
 
        strcpy(cidirrest, scriptname);
-       sprintf(buf, _("new %s script"), desc);
+       m_asprintf(&buf, _("new %s package %s script"),
+                  pkg_name(pkg, pnaw_nonambig), desc);
 
        va_start(args, cidirrest);
        command_init(&cmd, cidir, buf);
@@ -295,6 +300,8 @@ maintscript_new(struct pkginfo *pkg, const char *scriptname,
 
        if (stat(cidir, &stab)) {
                command_destroy(&cmd);
+               free(buf);
+
                if (errno == ENOENT) {
                        debug(dbg_scripts,
                              "maintscript_new nonexistent %s '%s'",
@@ -306,6 +313,7 @@ maintscript_new(struct pkginfo *pkg, const char *scriptname,
        maintscript_exec(pkg, &pkg->available, &cmd, &stab, 0);
 
        command_destroy(&cmd);
+       free(buf);
        post_script_tasks();
 
        return 1;
@@ -320,10 +328,11 @@ maintscript_fallback(struct pkginfo *pkg,
        struct command cmd;
        const char *oldscriptpath;
        struct stat stab;
-       char buf[100];
+       char *buf;
 
        oldscriptpath = pkg_infodb_get_file(pkg, &pkg->installed, scriptname);
-       sprintf(buf, _("old %s script"), desc);
+       m_asprintf(&buf, _("old %s package %s script"),
+                  pkg_name(pkg, pnaw_nonambig), desc);
 
        command_init(&cmd, oldscriptpath, buf);
        command_add_args(&cmd, scriptname, ifok,
@@ -336,6 +345,7 @@ maintscript_fallback(struct pkginfo *pkg,
                              "maintscript_fallback nonexistent %s '%s'",
                              scriptname, oldscriptpath);
                        command_destroy(&cmd);
+                       free(buf);
                        return 0;
                }
                warning(_("unable to stat %s '%.250s': %s"),
@@ -343,6 +353,7 @@ maintscript_fallback(struct pkginfo *pkg,
        } else {
                if (!maintscript_exec(pkg, &pkg->installed, &cmd, &stab, 
SUBPROC_WARN)) {
                        command_destroy(&cmd);
+                       free(buf);
                        post_script_tasks();
                        return 1;
                }
@@ -350,7 +361,8 @@ maintscript_fallback(struct pkginfo *pkg,
        notice(_("trying script from the new package instead ..."));
 
        strcpy(cidirrest, scriptname);
-       sprintf(buf, _("new %s script"), desc);
+       m_asprintf(&buf, _("new %s package %s script"),
+                  pkg_name(pkg, pnaw_nonambig), desc);
 
        command_destroy(&cmd);
        command_init(&cmd, cidir, buf);
@@ -361,6 +373,8 @@ maintscript_fallback(struct pkginfo *pkg,
 
        if (stat(cidir, &stab)) {
                command_destroy(&cmd);
+               free(buf);
+
                if (errno == ENOENT)
                        ohshit(_("there is no script in the new version of the 
package - giving up"));
                else
@@ -371,6 +385,7 @@ maintscript_fallback(struct pkginfo *pkg,
        notice(_("... it looks like that went OK"));
 
        command_destroy(&cmd);
+       free(buf);
        post_script_tasks();
 
        return 1;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/dpkg/dpkg.git

Reply via email to