Re: The Control-C Problem

Panu Matilainen <[email protected]> Thu, 15 Jul 2004 12:38:39 +0300 (EEST)
Newsgroups gmane.linux.conectiva.apt-rpm
Message-ID <[email protected]>
On Wed, 14 Jul 2004, Omar Kilani wrote:

> Hi,
> 
> I was wondering whether anyone had come up with a proper solution to the 
> "Segfault on Control-C" problem, or if it had been decided that the 
> safest way to solve the problem was to segfault? :)

If we'd found a proper solution it WOULD have been implemented already :)
It's not at all impossible that the segfault on ctrl-c problem is a bug in 
rpmlib, that's where it crashes afterall. Or then it's some strange 
interaction between apt and rpmlib which just doesn't happen with rpm 
itself. One thing I've been pondering is whether there's some kind of 
conflict between apt and rpmlib signal handling but there aren't that many 
places doing signal handling in apt and disabling those didn't change 
anything so that reason is probably out.

There is a partial (and ugly) workaround to it (patches attached):
1) make apt always take a readonly lock on rpmdb initially (this is what 
fedora.us apt does anyway, for other reasons)
2) cause a deliberate memory leak by not freeing an rpm transaction set 

With both those done, ctrl-c during download doesn't segfault and doesn't
cause stale rpmdb locks. For some reason that still occasionally leaves
stale locks behind if you do ctrl-c during apt-cache search :( 

Conectiva ships with a patched rpm to work around this outside apt but 
that patch isn't exactly a proper fix to the problem either.

	- Panu -

_______________________________________________
apt-rpm mailing list
[email protected]
http://distro2.conectiva.com.br/mailman/listinfo/apt-rpm
apt-0.5.15cnc6-rdonly.patch (text/plain, 829 B)
--- apt-0.5.15cnc6/apt-pkg/rpm/rpmhandler.cc.rdonly	2004-04-08 17:28:12.000000000 +0300
+++ apt-0.5.15cnc6/apt-pkg/rpm/rpmhandler.cc	2004-04-08 17:28:46.000000000 +0300
@@ -367,7 +367,7 @@
    Handler = rpmtsCreate();
    rpmtsSetVSFlags(Handler, (rpmVSFlags_e)-1);
    rpmtsSetRootDir(Handler, Dir.c_str());
-   if (rpmtsOpenDB(Handler, WriteLock?O_RDWR:O_RDONLY) != 0)
+   if (rpmtsOpenDB(Handler, O_RDONLY) != 0)
    {
       _error->Error(_("could not open RPM database"));
       return;
@@ -376,7 +376,7 @@
    const char *RootDir = NULL;
    if (!Dir.empty())
       RootDir = Dir.c_str();
-   if (rpmdbOpen(RootDir, &Handler, WriteLock?O_RDWR:O_RDONLY, 0644) != 0)
+   if (rpmdbOpen(RootDir, &Handler, O_RDONLY, 0644) != 0)
    {
       _error->Error(_("could not open RPM database"));
       return;
apt-0.5.15cnc6-no-tsfree.patch (text/plain, 516 B)
Index: apt-pkg/rpm/rpmhandler.cc
===================================================================
--- apt-pkg/rpm/rpmhandler.cc	(revision 320)
+++ apt-pkg/rpm/rpmhandler.cc	(revision 321)
@@ -424,7 +424,9 @@
 
    if (Handler != NULL) {
 #if RPM_VERSION >= 0x040100
-      rpmtsFree(Handler);
+      // This is segfaulting APT on CTRL-C. RPM seems to return
+      // something invalid during rpmtsCreate() in this situation.
+      //rpmtsFree(Handler);
 #else
       rpmdbClose(Handler);
 #endif