summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <jbj>2006-12-02 16:57:37 +0000
committerjbj <jbj>2006-12-02 16:57:37 +0000
commitc6daafc4d3802adc8b18b8a7adba7d1671352116 (patch)
tree7e44d41bc9d746cbc54c85547a1745dc61184d90
parent7c11b91b4cce1228966532590ca0943a2c7a9173 (diff)
downloadlibpopt-c6daafc4d3802adc8b18b8a7adba7d1671352116.tar.gz
- add robustness to posix shared mutexes.
- discard stale locks when opening an rpmdb environment. - popt: add POP_ARGFLAG_RANDOM using random(3) for a random value. - add --{r,w}segfault options to randomly interrupt rpm execution.
-rw-r--r--popt.c19
-rw-r--r--popt.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/popt.c b/popt.c
index d8e1885..1552217 100644
--- a/popt.c
+++ b/popt.c
@@ -645,12 +645,23 @@ static void poptStripArg(/*@special@*/ poptContext con, int which)
/*@=compdef@*/
}
+/*@unchecked@*/
+static unsigned int seed = 0;
+
int poptSaveLong(long * arg, int argInfo, long aLong)
{
/* XXX Check alignment, may fail on funky platforms. */
if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
return POPT_ERROR_NULLARG;
+ if (aLong != 0 && argInfo & POPT_ARGFLAG_RANDOM) {
+ if (!seed) {
+ srandom((unsigned)getpid());
+ srandom((unsigned)random());
+ }
+ aLong = random() % (aLong > 0 ? aLong : -aLong);
+ aLong++;
+ }
if (argInfo & POPT_ARGFLAG_NOT)
aLong = ~aLong;
switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
@@ -679,6 +690,14 @@ int poptSaveInt(/*@null@*/ int * arg, int argInfo, long aLong)
if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
return POPT_ERROR_NULLARG;
+ if (aLong != 0 && argInfo & POPT_ARGFLAG_RANDOM) {
+ if (!seed) {
+ srandom((unsigned)getpid());
+ srandom((unsigned)random());
+ }
+ aLong = random() % (aLong > 0 ? aLong : -aLong);
+ aLong++;
+ }
if (argInfo & POPT_ARGFLAG_NOT)
aLong = ~aLong;
switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
diff --git a/popt.h b/popt.h
index 18f764c..47de002 100644
--- a/popt.h
+++ b/popt.h
@@ -61,6 +61,7 @@
/*!< clear arg bit(s) */
#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000 /*!< show default value in --help */
+#define POPT_ARGFLAG_RANDOM 0x00400000 /*<! random value in [1,arg] */
/*@}*/