From c6daafc4d3802adc8b18b8a7adba7d1671352116 Mon Sep 17 00:00:00 2001 From: jbj Date: Sat, 2 Dec 2006 16:57:37 +0000 Subject: - 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. --- popt.c | 19 +++++++++++++++++++ popt.h | 1 + 2 files changed, 20 insertions(+) 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 /*