diff options
author | jbj <jbj> | 2006-12-02 16:57:37 +0000 |
---|---|---|
committer | jbj <jbj> | 2006-12-02 16:57:37 +0000 |
commit | c6daafc4d3802adc8b18b8a7adba7d1671352116 (patch) | |
tree | 7e44d41bc9d746cbc54c85547a1745dc61184d90 | |
parent | 7c11b91b4cce1228966532590ca0943a2c7a9173 (diff) | |
download | libpopt-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.c | 19 | ||||
-rw-r--r-- | popt.h | 1 |
2 files changed, 20 insertions, 0 deletions
@@ -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) { @@ -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] */ /*@}*/ |