[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

--retry <num> and --sleeptime <num>



Hello,

attached patch gives the options --retry <num> and --sleeptime <num> to rpm 
when installing/upgrading packages (-i/-U). My way of testing was to run rpm 
-i bigpackage.rpm and press ^Z, after that trying rpm -i anotherpackage.rpm 
and seeing it retry. The default for sleeptime and retries is 0.

I needed to pass more parameters to rpmInstall(). The (ugly) fix of this was 
to rename rpmInstall() to rpm_Install() and define a macro named rpmInstall() 
which called rpm_Install() with the correct number of parameters. This should 
not break backwards compability with other programs. Should it be done in some 
other way?

The possible use of it is if several machines need to access the same database 
at once. The one that does not get the lock will sleep for the amount of 
seconds specified. Of course this is not a fool proof way.

I used sleep() to do the sleeping. This works on Solaris 2.6 and newer, 
FreeBSD 4.3 and Linux. I do not have other OS' availible for testing.

Is this of any interest for rpm? Does it stand a chance to be included in 
future releases? Should I file a bugreport with status "enhancement" and 
attach patches there instead? http://www.rpm.org does not give too much 
information about things, unfortunately.

/ Peter

diff -Naur rpm-4.0.2/doc/rpm.8 rpm-4.0.2.retry/doc/rpm.8
--- rpm-4.0.2/doc/rpm.8	Thu Jan 11 18:18:27 2001
+++ rpm-4.0.2.retry/doc/rpm.8	Fri Jul 20 14:32:55 2001
@@ -185,7 +185,10 @@
 .IP "\fB\-\-noorder\fP"
 Don't reorder the packages for an install. The list of packages would
 normally be reordered to satisfy dependancies.
-
+.IP "\fB\-\-retry \fI<num>\fP"
+Try to get the lock on the rpm-database \fI<num>\fP times.
+.IP "\fB\-\-sleeptime \fI<num>\fP"
+If lock is not gotten, sleep for \fI<num>\fP seconds before trying again.
 
 .SH QUERY OPTIONS
 The general form of an rpm query command is
diff -Naur rpm-4.0.2/lib/rpminstall.c rpm-4.0.2.retry/lib/rpminstall.c
--- rpm-4.0.2/lib/rpminstall.c	Wed Feb 21 20:13:39 2001
+++ rpm-4.0.2.retry/lib/rpminstall.c	Fri Jul 20 14:18:43 2001
@@ -4,6 +4,8 @@
 
 #include "system.h"
 
+#include <unistd.h>
+
 #include <rpmlib.h>
 #include <rpmmacro.h>
 #include <rpmurl.h>
@@ -169,10 +171,11 @@
 }	
 
 /** @todo Generalize --freshen policies. */
-int rpmInstall(const char * rootdir, const char ** fileArgv,
+int rpm_Install(const char * rootdir, const char ** fileArgv,
 		rpmtransFlags transFlags, 
 		rpmInstallInterfaceFlags interfaceFlags,
 		rpmprobFilterFlags probFilter, 
+                int sleeptime, int retries,
 		rpmRelocation * relocations)
 {
     rpmdb db = NULL;
@@ -327,21 +330,26 @@
 		sourceURL[numSRPMS++] = fileName;
 		Fclose(fd);
 	    } else {
-		if (!dbIsOpen) {
-		    if (rpmdbOpen(rootdir, &db, mode, 0644)) {
-			const char *dn;
-			dn = rpmGetPath( (rootdir ? rootdir : ""), 
-					"%{_dbpath}", NULL);
-			rpmMessage(RPMMESS_ERROR, 
-				_("cannot open Packages database in %s\n"), dn);
-			free((void *)dn);
-			numFailed++;
-			pkgURL[i] = NULL;
-			break;
-		    }
-		    rpmdep = rpmtransCreateSet(db, rootdir);
-		    dbIsOpen = 1;
-		}
+                /* Open db if it is not open. If it is locked, consider retry */
+                if (!dbIsOpen) {
+                    do {
+                        if (!rpmdbOpen(rootdir, &db, mode, 0644)) 
+                            dbIsOpen = 1;
+                        else sleep(sleeptime);
+		     } while(!dbIsOpen && --retries);
+                     if (!dbIsOpen) {
+                         const char *dn;
+                         dn = rpmGetPath( (rootdir ? rootdir : ""),
+                                 "%{_dbpath}", NULL);
+                         rpmMessage(RPMMESS_ERROR,
+                             _("cannot open Packages database in %s\n"), dn);  
+                         free((void *)dn);
+                         numFailed++;
+                         pkgURL[i] = NULL;
+                         break;
+                     }
+	             rpmdep = rpmtransCreateSet(db, rootdir);
+                }
 
 		if (defaultReloc) {
 		    const char ** paths;
diff -Naur rpm-4.0.2/lib/rpmlib.h rpm-4.0.2.retry/lib/rpmlib.h
--- rpm-4.0.2/lib/rpmlib.h	Tue Jan 16 00:10:04 2001
+++ rpm-4.0.2.retry/lib/rpmlib.h	Fri Jul 20 14:26:36 2001
@@ -1377,12 +1377,14 @@
  * @param relocations	package file relocations
  * @return		0 on success
  */
-int rpmInstall(const char * rootdir, const char ** argv,
+int rpm_Install(const char * rootdir, const char ** argv,
 		rpmtransFlags transFlags, 
 		rpmInstallInterfaceFlags interfaceFlags,
 		rpmprobFilterFlags probFilter,
+		int sleeptime, int retries,	
 		rpmRelocation * relocations);
 
+#define rpmInstall(rootdir, argv, transflags, ifflags, filter, reloc) rpm_Install(rootdir, argv, transflags, ifflags, filter, 0, 0, reloc)
 /** \ingroup rpmcli
  * Install source rpm package.
  * @param prefix	path to top of install tree
diff -Naur rpm-4.0.2/rpm.c rpm-4.0.2.retry/rpm.c
--- rpm-4.0.2/rpm.c	Mon Mar 12 19:20:29 2001
+++ rpm-4.0.2.retry/rpm.c	Fri Jul 20 14:18:24 2001
@@ -79,6 +79,8 @@
 static char * rcfile;
 static int replaceFiles;
 static int replacePackages;
+static int retries;
+static int sleeptime;
 static char * rootdir;
 extern int _rpmio_debug;
 static int showPercents;
@@ -153,6 +155,8 @@
  { "replacepkgs", '\0', 0, &replacePackages, 0,	NULL, NULL},
  { "resign", '\0', 0, 0, GETOPT_RESIGN,		NULL, NULL},
  { "root", 'r', POPT_ARG_STRING, &rootdir, 0,	NULL, NULL},
+ { "retry", '\0', POPT_ARG_INT, &retries, 0,    NULL, NULL},
+ { "sleeptime", '\0', POPT_ARG_INT, &sleeptime, 0,           NULL, NULL},
  { "rpmiodebug", '\0', POPT_ARG_VAL, &_rpmio_debug, -1,		NULL, NULL},
  { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,	NULL, NULL},
  { "sign", '\0', 0, &signIt, 0,			NULL, NULL},
@@ -218,6 +222,7 @@
     puts(_("                        [--httpproxy <host>] [--httpport <port>]"));
     puts(_("                        [--justdb] [--noorder] [--relocate oldpath=newpath]"));
     puts(_("                        [--badreloc] [--notriggers] [--excludepath <path>]"));
+    puts(_("                        [--retry <num>] [--sleeptime <num>]"));
     puts(_("                        [--ignoresize] file1.rpm ... fileN.rpm"));
     puts(_("       rpm {--upgrade -U} [-v] [--hash -h] [--percent] [--force] [--test]"));
     puts(_("                        [--oldpackage] [--root <dir>] [--noscripts]"));
@@ -228,6 +233,7 @@
     puts(_("                        [--ignoreos] [--nodeps] [--allfiles] [--justdb]"));
     puts(_("                        [--noorder] [--relocate oldpath=newpath]"));
     puts(_("                        [--badreloc] [--excludepath <path>] [--ignoresize]"));
+    puts(_("                        [--retry <num>] [--sleeptime <num>]"));
     puts(_("                        file1.rpm ... fileN.rpm"));
     puts(_("       rpm {--query -q} [-afpg] [-i] [-l] [-s] [-d] [-c] [-v] [-R]"));
     puts(_("                        [--scripts] [--root <dir>] [--rcfile <file>]"));
@@ -608,6 +614,8 @@
     specedit = 0;
     test = 0;
     _url_debug = 0;
+    sleeptime = 0;
+    retries = 0;
 
     /* XXX Eliminate query linkage loop */
     parseSpecVec = parseSpec;
@@ -1143,8 +1151,9 @@
 	    relocations[numRelocations].newPath = NULL;
 	}
 
-	ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon), 
-			installFlags, interfaceFlags, probFilter, relocations);
+	ec += rpm_Install(rootdir, (const char **)poptGetArgs(optCon), 
+			installFlags, interfaceFlags, probFilter, sleeptime,
+                        retries, relocations);
 	break;
 
       case MODE_QUERY:

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []