The following commit has been merged in the master branch:
commit 5c32f0c0e4c537fc00bf3ccace8799fe27a522aa
Author: Guillem Jover <guil...@debian.org>
Date:   Sun May 22 16:07:49 2011 +0200

    libdpkg: Properly pop the cleanup handler in trk_explicit_interest_change
    
    In case of error all cleanup handlers will get called but the nf FILE
    variable might have been already closed, which would cause the
    subsequent fclose() to fail, this will not be fatal as the return
    value for fclose() in the cleanup handler is not checked, but it's
    still not correct.
    
    Refactor trk_explicit_interest_change() into
    trk_explicit_interest_remove(), trk_explicit_interest_flush() and
    trk_explicit_interest_commit() to reflow the function and make it
    clearer by sharing the main code path.
    
    Regression introduced in commit 83b591340ec92cf0e9814e8403da7711cbbc6b46.

diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c
index ae0f5b9..2a1cc36 100644
--- a/lib/dpkg/triglib.c
+++ b/lib/dpkg/triglib.c
@@ -404,6 +404,37 @@ trk_explicit_activate_awaiter(struct pkginfo *aw)
 }
 
 static void
+trk_explicit_interest_flush(const char *newfilename, FILE *nf)
+{
+       if (ferror(nf))
+               ohshite(_("unable to write new trigger interest file `%.250s'"),
+                       newfilename);
+       if (fflush(nf))
+               ohshite(_("unable to flush new trigger interest file '%.250s'"),
+                       newfilename);
+       if (fsync(fileno(nf)))
+               ohshite(_("unable to sync new trigger interest file '%.250s'"),
+                       newfilename);
+}
+
+static void
+trk_explicit_interest_commit(const char *newfilename)
+{
+       if (rename(newfilename, trk_explicit_fn.buf))
+               ohshite(_("unable to install new trigger interest file 
`%.250s'"),
+                       trk_explicit_fn.buf);
+}
+
+static void
+trk_explicit_interest_remove(const char *newfilename)
+{
+       if (unlink(newfilename))
+               ohshite(_("cannot remove `%.250s'"), newfilename);
+       if (unlink(trk_explicit_fn.buf))
+               ohshite(_("cannot remove `%.250s'"), trk_explicit_fn.buf);
+}
+
+static void
 trk_explicit_interest_change(const char *trig,  struct pkginfo *pkg, int 
signum)
 {
        static struct varbuf newfn;
@@ -432,34 +463,18 @@ trk_explicit_interest_change(const char *trig,  struct 
pkginfo *pkg, int signum)
                empty = false;
        }
 
-       if (empty) {
-               /* The triggers interest file is no longer needed, drop it */
-               fclose(nf); /* We don't care if it fails */
-               if (unlink(newfn.buf))
-                       ohshite(_("cannot remove `%.250s'"), newfn.buf);
-               if (unlink(trk_explicit_fn.buf))
-                       ohshite(_("cannot remove `%.250s'"), 
trk_explicit_fn.buf);
-               dir_sync_path(triggersdir);
-               return;
-       }
+       if (!empty)
+               trk_explicit_interest_flush(newfn.buf, nf);
 
-       if (ferror(nf))
-               ohshite(_("unable to write new trigger interest file `%.250s'"),
-                       newfn.buf);
-       if (fflush(nf))
-               ohshite(_("unable to flush new trigger interest file '%.250s'"),
-                       newfn.buf);
-       if (fsync(fileno(nf)))
-               ohshite(_("unable to sync new trigger interest file '%.250s'"),
-                       newfn.buf);
        pop_cleanup(ehflag_normaltidy);
        if (fclose(nf))
                ohshite(_("unable to close new trigger interest file `%.250s'"),
                        newfn.buf);
 
-       if (rename(newfn.buf, trk_explicit_fn.buf))
-               ohshite(_("unable to install new trigger interest file 
`%.250s'"),
-                       trk_explicit_fn.buf);
+       if (empty)
+               trk_explicit_interest_remove(newfn.buf);
+       else
+               trk_explicit_interest_commit(newfn.buf);
 
        dir_sync_path(triggersdir);
 }

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to