simple fork and pidfile aptwebserver
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 24 Jun 2013 14:34:38 +0000 (16:34 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 24 Jun 2013 15:01:33 +0000 (17:01 +0200)
Forking only after being ready to accept clients avoids running races
with the tests which sometimes failed on the first 'apt-get update'
(or similar) with the previous background-start and hope for the best…

The commit fixes also some oversight output-order changes in regards to
Description-md5 and (I-M-S) race conditions in various tests.

Git-Dch: Ignore

test/integration/Packages-pdiff-usage
test/integration/Packages-pdiff-usage-new
test/integration/Packages-releasefile-verification
test/integration/Packages-releasefile-verification-new
test/integration/framework
test/integration/test-bug-590041-prefer-non-virtual-packages
test/integration/test-bug-601016-description-translation
test/integration/test-cve-2013-1051-InRelease-parsing
test/integration/test-pdiff-usage
test/integration/test-releasefile-verification
test/interactive-helper/aptwebserver.cc

index d1530a9..ac962f2 100644 (file)
@@ -19,6 +19,7 @@ Description: Advanced front-end for dpkg
  .
  APT features complete installation ordering, multiple source capability
  and several other unique features, see the Users Guide in apt-doc.
+Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
 
 Package: oldstuff
 Version: 1.0
@@ -32,3 +33,4 @@ SHA1: 3c695e028f74d5c544deeddaaa1242desa81088c
 SHA256: b46fd1546151c545fe4bfa56a5cc0e7deaef23e2da3e4f129727fd660f28f050
 Description: some cool but old stuff
  This package will disappear in the next mirror update
+Description-md5: 1948af60eda0a41dfa9fe83f60eb8389
index 4f374b3..f8d7b19 100644 (file)
@@ -22,6 +22,7 @@ Description: Advanced front-end for dpkg
  .
  APT features complete installation ordering, multiple source capability
  and several other unique features, see the Users Guide in apt-doc.
+Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
 
 Package: newstuff
 Version: 1.0
@@ -35,3 +36,4 @@ SHA1: 3c695e028f7a1ae324deeddaaa1242desa81088c
 SHA256: b46fd154615edefab321cc56a5cc0e7deaef23e2da3e4f129727fd660f28f050
 Description: some cool and shiny new stuff
  This package will appear in the next mirror update
+Description-md5: d5f89fbbc2ac69c43d7e4c9b67d82b6b
index 29a385f..eb73272 100644 (file)
@@ -16,3 +16,4 @@ Description: Advanced front-end for dpkg
  .
  APT features complete installation ordering, multiple source capability
  and several other unique features, see the Users Guide in apt-doc.
+Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
index e3b2edf..61509d1 100644 (file)
@@ -19,3 +19,4 @@ Description: Advanced front-end for dpkg
  .
  APT features complete installation ordering, multiple source capability
  and several other unique features, see the Users Guide in apt-doc.
+Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
index 3a02cfb..7dd7c20 100644 (file)
@@ -605,9 +605,12 @@ buildaptarchivefromfiles() {
                cat ${line} | bzip2 > ${line}.bz2
                cat ${line} | xz --format=lzma > ${line}.lzma
                cat ${line} | xz > ${line}.xz
+               if [ -n "$1" ]; then
+                       touch -d "$1" ${line}.gz ${line}.bz2 ${line}.lzma ${line}.xz
+               fi
                msgdone "info"
        done
-       generatereleasefiles
+       generatereleasefiles "$@"
 }
 
 # can be overridden by testcases for their pleasure
@@ -719,7 +722,10 @@ signreleasefiles() {
        done
        for RELEASE in $(find aptarchive/ -name Release); do
                gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
-               gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
+               local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
+               gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o $INRELEASE $RELEASE
+               # we might have set a specific date for the Release file, so copy it
+               touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
        done
        msgdone "info"
 }
@@ -728,8 +734,12 @@ changetowebserver() {
        local LOG='/dev/null'
        if test -x ${BUILDDIRECTORY}/aptwebserver; then
                cd aptarchive
-               LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver "$@" >$LOG 2>&1 &
-               addtrap "kill $!;"
+               LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
+               local PID="$(cat aptwebserver.pid)"
+               if [ -z "$PID" ]; then
+                       msgdie 'Could not fork aptwebserver successfully'
+               fi
+               addtrap "kill $PID;"
                cd - > /dev/null
        elif [ $# -gt 0 ]; then
                msgdie 'Need the aptwebserver when passing arguments for the webserver'
index e0dd773..0ce4c14 100755 (executable)
@@ -9,6 +9,7 @@ pkglibc6="Package: libc6
 Architecture: armel
 Version: 2.11.2-2~0.3
 Description: Embedded GNU C Library: Shared libraries
+Description-md5: b8c1e0561b75e2dc6b6482a99079c3e4
 Filename: pool/main/e/eglibc/libc6_2.11.2-2_armel.deb
 Installed-Size: 9740
 MD5sum: f5b878ce5fb8aa01a7927fa1460df537
@@ -25,6 +26,7 @@ Architecture: i386
 Version: 2.1.3-13~0.3
 Replaces: libc6 (<< 2.2.5-13~0.3)
 Description: The Berkeley database routines [glibc 2.0/2.1 compatibility]
+Description-md5: de1876f7fe7f7709a110875e145e38a8
 Filename: pool/main/d/db1-compat/libdb1-compat_2.1.3-13_armel.deb
 Installed-Size: 136
 MD5sum: 4043f176ab2b40b0c01bc1211b8c103c
index 03fddbf..33c209e 100755 (executable)
@@ -9,8 +9,9 @@ configarchitecture 'i386' 'amd64'
 # we need a valid locale here, otherwise the language configuration
 # will be overridden by LC_ALL=C
 LOCALE="$(echo "$LANG" | cut -d'_' -f 1)"
+MD5Sum='Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c'
 
-PACKAGESTANZA="Package: apt
+PACKAGESTANZA='Package: apt
 Priority: important
 Section: admin
 Installed-Size: 5984
@@ -19,8 +20,7 @@ Architecture: i386
 Version: 0.8.7
 Filename: pool/main/a/apt/apt_0.8.7_i386.deb
 Size: 2140230
-MD5sum: 74769bfbcef9ebc4fa74f7a5271b9c08
-Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c"
+MD5sum: 74769bfbcef9ebc4fa74f7a5271b9c08'
 
 PACKAGESTANZA2='Package: apt
 Priority: important
@@ -31,22 +31,23 @@ Architecture: amd64
 Version: 0.8.7
 Filename: pool/main/a/apt/apt_0.8.7_amd64.deb
 Size: 2210342
-MD5sum: 4a869bfbdef9ebc9fa74f7a5271e8d1a
-Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c'
+MD5sum: 4a869bfbdef9ebc9fa74f7a5271e8d1a'
 
 echo "$PACKAGESTANZA
 Description: Advanced front-end for dpkg
+$MD5Sum
 
 $PACKAGESTANZA2
-Description: Advanced front-end for dpkg" > aptarchive/Packages
+Description: Advanced front-end for dpkg
+$MD5Sum" > aptarchive/Packages
 
 echo "Package: apt
-Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
 Description-${LOCALE}: Mächtige Oberfläche für dpkg
  Das Paket bietet dem Nutzer technisch führende Methoden für den Zugriff
  auf den dpkg-Paketmanager. Es beinhaltet das apt-get-Werkzeug und die
  APT-Dselect-Methode. Beides sind einfache und sicherere Wege,
- um Pakete zu installieren und Upgrades durchzuführen." | bzip2 > aptarchive/${LOCALE}.bz2
+ um Pakete zu installieren und Upgrades durchzuführen.
+$MD5Sum" | bzip2 > aptarchive/${LOCALE}.bz2
 
 # the $LOCALE translation file will not be included as it is a flat archive it came from and therefore
 # its name can not be guessed correctly… (in non-flat archives the files are called Translation-*)
@@ -54,10 +55,12 @@ echo 'APT::Cache::Generate "false";' > rootdir/etc/apt/apt.conf.d/00nogenerate
 
 NOLONGSTANZA="$PACKAGESTANZA
 Description: Advanced front-end for dpkg
+$MD5Sum
 "
 
 ENGLISHSTANZA="$PACKAGESTANZA
 Description: Advanced front-end for dpkg
+$MD5Sum
 "
 
 LOCALESTANZA="$PACKAGESTANZA
@@ -66,6 +69,7 @@ Description-${LOCALE}: Mächtige Oberfläche für dpkg
  auf den dpkg-Paketmanager. Es beinhaltet das apt-get-Werkzeug und die
  APT-Dselect-Methode. Beides sind einfache und sicherere Wege,
  um Pakete zu installieren und Upgrades durchzuführen.
+$MD5Sum
 "
 LOCALESTANZA2="$PACKAGESTANZA2
 Description-${LOCALE}: Mächtige Oberfläche für dpkg
@@ -73,6 +77,7 @@ Description-${LOCALE}: Mächtige Oberfläche für dpkg
  auf den dpkg-Paketmanager. Es beinhaltet das apt-get-Werkzeug und die
  APT-Dselect-Methode. Beides sind einfache und sicherere Wege,
  um Pakete zu installieren und Upgrades durchzuführen.
+$MD5Sum
 "
 
 testrun() {
@@ -97,28 +102,32 @@ testrun
 
 echo "$PACKAGESTANZA
 Description: Advanced front-end for dpkg
+$MD5Sum
 
 $PACKAGESTANZA2
-Description: Advanced front-end for dpkg" > aptarchive/Packages
+Description: Advanced front-end for dpkg
+$MD5Sum" > aptarchive/Packages
 
 echo "Package: apt
-Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c
 Description-en: Advanced front-end for dpkg
  This is Debian's next generation front-end for the dpkg package manager.
  It provides the apt-get utility and APT dselect method that provides a
- simpler, safer way to install and upgrade packages." | bzip2 > aptarchive/en.bz2
+ simpler, safer way to install and upgrade packages.
+$MD5Sum" | bzip2 > aptarchive/en.bz2
 
 ENGLISHSTANZA="$PACKAGESTANZA
 Description-en: Advanced front-end for dpkg
  This is Debian's next generation front-end for the dpkg package manager.
  It provides the apt-get utility and APT dselect method that provides a
  simpler, safer way to install and upgrade packages.
+$MD5Sum
 "
 ENGLISHSTANZA2="$PACKAGESTANZA2
 Description-en: Advanced front-end for dpkg
  This is Debian's next generation front-end for the dpkg package manager.
  It provides the apt-get utility and APT dselect method that provides a
  simpler, safer way to install and upgrade packages.
+$MD5Sum
 "
 
 testrun
index 853da5f..6764fef 100755 (executable)
@@ -37,7 +37,7 @@ sed -i '/^-----BEGIN PGP SIGNATURE-----/,/^-----END PGP SIGNATURE-----/ s/^$/  /
 
 # we append the (evil unsigned) Release file to the (good signed) InRelease
 cat aptarchive/dists/stable/Release >> aptarchive/dists/stable/InRelease
-
+touch -d '+1hour' aptarchive/dists/stable/InRelease
 
 # ensure the update fails
 # useful for debugging to add "-o Debug::pkgAcquire::auth=true"
index 29301d0..e453269 100755 (executable)
@@ -35,7 +35,7 @@ SHA1-History:
 SHA1-Patches:
  7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-0814.28
  $(sha1sum $PATCHFILE | cut -d' ' -f 1) $(stat -c%s $PATCHFILE) $(basename $PATCHFILE)" > $PATCHINDEX
-generatereleasefiles
+generatereleasefiles '+1hour'
 signreleasefiles
 find aptarchive -name 'Packages*' -type f -delete
 aptget update -qq
index fba7ab2..e56f458 100755 (executable)
@@ -184,5 +184,5 @@ runtest2
 
 DELETEFILE="InRelease"
 runtest
-#DELETEFILE="Release.gpg"
-#runtest
+DELETEFILE="Release.gpg"
+runtest
index 05b8756..a8d191d 100644 (file)
@@ -387,6 +387,41 @@ int main(int const argc, const char * argv[])
       return 2;
    }
 
+   FileFd pidfile;
+   if (_config->FindB("aptwebserver::fork", false) == true)
+   {
+      std::string const pidfilename = _config->Find("aptwebserver::pidfile", "aptwebserver.pid");
+      int const pidfilefd = GetLock(pidfilename);
+      if (pidfilefd < 0 || pidfile.OpenDescriptor(pidfilefd, FileFd::WriteOnly) == false)
+      {
+        _error->Errno("aptwebserver", "Couldn't acquire lock on pidfile '%s'", pidfilename.c_str());
+        _error->DumpErrors(std::cerr);
+        return 3;
+      }
+
+      pid_t child = fork();
+      if (child < 0)
+      {
+        _error->Errno("aptwebserver", "Forking failed");
+        _error->DumpErrors(std::cerr);
+        return 4;
+      }
+      else if (child != 0)
+      {
+        // successfully forked: ready to serve!
+        std::string pidcontent;
+        strprintf(pidcontent, "%d", child);
+        pidfile.Write(pidcontent.c_str(), pidcontent.size());
+        if (_error->PendingError() == true)
+        {
+           _error->DumpErrors(std::cerr);
+           return 5;
+        }
+        std::cout << "Successfully forked as " << child << std::endl;
+        return 0;
+      }
+   }
+
    std::clog << "Serving ANY file on port: " << port << std::endl;
 
    listen(sock, 1);
@@ -502,5 +537,7 @@ int main(int const argc, const char * argv[])
                << " on socket " << sock << std::endl;
       close(client);
    }
+   pidfile.Close();
+
    return 0;
 }