Commit Graph

12074 Commits

Author SHA1 Message Date
Panu Matilainen 20a79a7ac7 Refactor pubkey destructor to eliinate Unlink() helper
- Having a helper function to decrement an integer seems a bit much,
  but mostly this is preparing for thread protection where the
  unlink-helpers would just get in the way.
2013-02-19 15:35:10 +02:00
Panu Matilainen 4c7ee7383a Refactor keyring destructor to eliminate Unlink() helper
- Having a helper function to decrement an integer seems a bit much,
  but mostly this is preparing for thread protection where the
  unlink-helpers would just get in the way.
2013-02-19 15:32:54 +02:00
Panu Matilainen 97a37397c7 Initialize keyrings and pubkeys with refcount 1 directly
- Returning through fooLink() gains us nothing, but would complicate
  things wrt locking: fooLink() will require locks, but object
  creation does not.
2013-02-19 15:10:32 +02:00
Panu Matilainen 96e0cdf34b And finally, make rpmlog thread-safe ... mostly
- Now that all of rpmlog global state is in the context hidden behind
  a getter function, adding the actual locking is remarkably simple.
  Alternatively we could use a per-thread storage for this, but
  for now we'll go with global, locked structure.
- Add a reminder note about rpmlogMessage() - while grabbing the message
  from the global context is thread-safe in itself, the returned message
  is not as it points to the global context which could get freed or
  moved before the caller gets to see it.
2013-02-19 14:13:41 +02:00
Panu Matilainen ebf15b5672 Move log mask into the log context, update callers 2013-02-19 13:52:17 +02:00
Panu Matilainen 5adcedeb44 Lift context acquisition and record-save logic to rpmlog() level
- In order to move the log mask to the context, we need to grab
  the context early, which also means we need to figure out the need
  to save the record early to keep things simple wrt locking, pass
  the stuff around in arguments.
2013-02-19 13:45:46 +02:00
Panu Matilainen 85be6095c1 Move log file stream into the log context, update callers 2013-02-19 13:33:19 +02:00
Panu Matilainen b534e59a3a Move log callback stuff into the log context, update callers 2013-02-19 13:20:09 +02:00
Panu Matilainen d5d38f1f60 Introduce rpmlog context object, move saved log records there
- Add functions to acquire and release a log context, update callers:
  forcing callers through a function will allow fairly transparently
  handling either locking for shared context or finding thread
  local context, whichever approach we want to use.
- Callbacks and all need to go to the context as well, but to avoid
  rewriting the entire rpmlog.c at once...
- No functional changes, just preliminaries for thread-sanity
2013-02-19 13:11:56 +02:00
Panu Matilainen a60f55be4b Further simplify tag lookup table initialization
- Just do it all in loadTags(), having a separate function for the
  simple task serves no purpose but to complicate things.
2013-02-19 10:07:14 +02:00
Panu Matilainen 59147483d8 Eliminate the redundant headerTagIndices / _rpmTags tag structs
- Now that all the other fluff is removed, its fairly obvious there's
  no need for this extra structure at all.
2013-02-19 09:30:22 +02:00
Panu Matilainen 3d6b29d898 Eliminate redundant tag table size variables
- Sorted tables are of the same size as the original one, doh...
2013-02-19 09:19:41 +02:00
Panu Matilainen ca424dffb5 Split bsearch by tagname into a helper function too
- Doesn't make the code any smaller (on the contrary), but makes
  the functions that little bit cleaner and more consistent: do just
  one thing and all that...
2013-02-18 23:21:11 +02:00
Panu Matilainen f13eb4364b Reduce two copy-paste manual tag bsearch()'es into helper function 2013-02-18 23:07:18 +02:00
Panu Matilainen 5b71a27b8c Eliminate pointless indirection from tag table getters
- There's not a whole lot of point in making calls through what are
  statically initialized function pointers that can never change.
  The indirection might not be particularly expensive but when there's
  precisely zero advantage to doing it... it only makes simple code
  look hairier than it is.
2013-02-18 22:18:40 +02:00
Panu Matilainen a746036cb1 Eliminate wholly unused function pointers from tag table structures 2013-02-18 22:07:56 +02:00
Panu Matilainen c66d4b66eb Further fsm-fluff removals
- fsm->postpone is only interesting inside the loops, nobody
  is going to look at it after we exited them. In other words
  this just removes stuff that wasn't doing anything at all.
2013-02-18 15:52:34 +02:00
Panu Matilainen 79d8ec88e9 Eliminate redundant break from rpmPackageFilesArchive() loop
- The loop condition makes it terminate on errors already, this
  is just redundant fluff.
2013-02-18 15:42:56 +02:00
Panu Matilainen 57ad4b69c3 Eliminate redundant break from rpmPackageFilesRemove() loop
- The loop condition makes it terminate on errors already, handle
  the case we're really interested in (success) separately instead.
  Less early breaks means less places tired eyes will miss...
2013-02-18 15:32:51 +02:00
Panu Matilainen 26ef4ee6ad Eliminate bunch of unnecessary early breaks from rpmPackageFilesInstall()
- The loop condition makes it terminate on errors, there's no need
  for all these trailing break-on-rc checks. Simply handle success
  in an else-clause instead.
- Supposedly no functional changes, but adding symmetrical
  plugin hooks for files should be much easier now.
2013-02-18 15:19:58 +02:00
Panu Matilainen f5957308d4 Eliminate a very bogus early return from rpmPackageFilesInstall()
- This might've been somewhat less incorrect in earlier incarnations
  of the fsm, but now its just totally totally wrong as it would leak
  resources left and right. In reality this never happens as
  on install, regular files are assumed non-existent always (as we're
  installing to temporary path) from fsmInit() so fsmVerify()
  is guaranteed to return CPIOERR_ENOENT here.
2013-02-18 15:02:07 +02:00
Panu Matilainen 11ba21e2ab A non-naive implementation of argvJoin()
- The previous version was as naive as they get, for reasonable behavior
  with non-trivial amount of data precalculating string lengths and
  allocating at one go is necessary.
2013-02-18 10:50:38 +02:00
Panu Matilainen 713273858d Make rpmConfigDir() thread-safe 2013-02-15 15:20:09 +02:00
Panu Matilainen 1db6c86c8a Make tag-table initialization thread-safe
- pthread_once() fits here like a glove... Unlike the previous
  init-if-not-done-yet checks, call it as the first thing in each
  of these functions, if only for consistency's sake.
2013-02-15 13:39:54 +02:00
Panu Matilainen 3aeab6d5db Add mutex protection around stashKeyid() static variables
- This is one of the first places anybody fooling with threads will
  run into, guard it with a mutex to avoid crash-n-burn on such a
  silly thing and add a reminder to put it out of its misery later.
- rwlock would likely be more optimal than mutex as most callers will
  be just reading but to start simple and obvious...
2013-02-15 13:18:18 +02:00
Panu Matilainen 57000e976b Eliminate an exit point from middle of stashKeyid()
- No functional changes here, but will be needed for nice and
  symmetric locking
2013-02-15 13:14:32 +02:00
Panu Matilainen 4ebc61a83f Isolate the seen-keyid tracking variables inside stashKeyid()
- There's no need to access these outside the function, forcing the
  issue to makes locking easy to guarantee.
2013-02-15 13:10:42 +02:00
Alexey Tourbin c22d5b1299 Stricter macro substitution syntax
This change introduces a separate routine to parse for valid macro
names.  Valid macro names are either regular 3+ character identifiers,
or special names: "S", "P", "0", "#", "*", "**", macro options such as
"-o" and "-o*", and macro arguments such as "1".  Other names are not
valid.  This fixes a number of bugs seen earlier due to sloppy name
parsing: "%_libdir*" and "%01" were not expanded (these are now expanded
to e.g. "/usr/lib64*" and "<name>1", as expected).  This also fixes
bugs in as-is substitution: "%!foo" was expanded to "%foo", and likewise
"%!!!" was expanded to "%" (and to "%<garbage>" at EOL).

Also, bad names in %name and %{name...} substitutions are now handled
differently.  In %name form, the name is parsed tentatively; a silent
fall-back to as-is substitution is provisioned when no valid name can
be obtain.  In %{name...} form, a failure to obtain a valid name is now
a syntax error.  Furthermore, only 3 variants are syntactically valid:
%{name} proper, %{name:...}, and %{name ...}.  This renders invalid
ambiguous macro substitutions such as the one found in FC18 lvm2.spec:

Requires: util-linux >= %{util-linux_version}
error: Invalid macro syntax: %{util-linux_version}
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-02-12 15:53:04 +02:00
Alexey Tourbin 2d647098c8 Fixed buffer problems in doShellEscape
When the output from a command is empty, nothing stops doShellEscape from
chopping newlines past the beginning of the buffer.  This problem was first
identified by Dmitry V. Levin in July 2009.

Also, there is an off-by-one error in replacing trailing '\n' with '\0'.
This problem, however, escaped the attention of Dmitry V. Levin in July 2009.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-02-12 08:30:33 +02:00
Panu Matilainen cca91666d0 Failure to initialize crypto is fatal
- Almost nothing works if crypto fails to initialize for whatever reason,
  check and propagate rpmInitCrypto() failure from rpmReadConfigFiles().
- Logging the error left for individual crypto backends to let them
  identify themselves: beecrypt requires no initialization whatsoever
  so it cannot fail at all, but NSS can fail in a number of entertaining
  ways due to missing dlopen()'ed bits and pieces, this should help
  avoiding wild-goose chases in such cases (RhBug:909627, RhBug:909618...)
2013-02-12 05:19:23 +02:00
Panu Matilainen 65d2e787d5 Failure to calculate digest in rpmDoDigest() is, well, a failure
- This is mostly a cant-happen situation but technically it can
  fail, lets not segfault if it does (RhBug:909618)
2013-02-12 05:19:22 +02:00
Alexey Tourbin 0eb0da9af9 Warn when whitespace is missing before macro body
This will now issue a warning when macro definition is possibly
incorrect or ambigous, such as the one found in FC18 lvm2.spec:

%define util-linux_version 2.22.1
warning: Macro %util needs whitespace before body

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-02-09 14:36:30 +02:00
Panu Matilainen 29e7c4b3bd Check for stale db locks when opening write-cursors
- During long-running transactions its entirely possible for some
  other player to come and go leaving stale locks behind and cause
  the transaction to get stuck until the cavalry comes along in the
  form of somebody else opening the rpmdb, clearing the blockage.
- Presumably dbenv->failchk() is not entirely free of cost so we only
  do this for writes which are way more critical and also more prone to
  getting stuck.
- dbenv->failchk() could return DB_RUNRECOVER in which case we should
  abort everything but we lack a mechanism to do it... just add
  a reminder comment for now.
2013-02-05 10:26:49 +02:00
Panu Matilainen 233e4573d1 Restore legacy behavior on %ghost %config erasure, mostly
- Make rpmfiConfigConflict() consider any existing %ghost %config
  as "modified". This causes them to be left alone on erasure to match
  long-standing rpm behavior (whether the behavior is intended or not...)
  Ghost config testcase passes again, talk about flip-flop. Sigh.
- Legacy behavior had an extra twist which we are intentionally NOT
  restoring: if a non-empty %ghost exists at build-time, its digest
  is stored in the header despite the file not being present in
  the payload. With previous versions of rpm, the contents of an
  existing  %ghost %config would be compared to the one in header and
  resulting in different behavior on erasure: if the contents matched
  that of build-time, the file would be removed, otherwise it would
  be preserved. Ghosts remembering their identity from previous life
  goes a little bit too far into the land of paranormal for me...
2013-01-31 16:22:34 +02:00
Panu Matilainen 4efec66338 Adjust ghost config test case to match legacy behavior
- Rpm has traditionally (at least for the last decade) preserved
  existing %ghost %config file on erasure. Whether this was intentional
  or not, changing the behavior now risks data loss in case people
  are relying on this long-standing behavior.
- This fails now: The behavior changed as (an unexpected) side-effect
  of commit 389b1ab706.
2013-01-31 15:55:22 +02:00
Panu Matilainen 147a26c5f6 Dont skip shared file/dir create if the other one is a ghost
- Explicitly test for shared file/dir being ghost when deciding whether
  to skip create: we must never skip the creation of a real file/dir
  because of a ghost as the ghosts do not get created.
- This fixes the shared ghost testcase, ie the thing that commit
  a712252392 was supposed to fix,
  without side-effects that I can see.
2013-01-30 14:07:33 +02:00
Panu Matilainen 471b74bf6e Revert the severely broken FA_SKIP on %ghost "fix"
- Reverts the bad half of commit a712252392eca75443ca45c10a72873cabec7963:
  treating files that wont be installed as skipped seems logical enough,
  but rpm disagrees... making %ghosts FA_SKIP on install causes
  upgrades on %ghost %config files to miss the necessary FA_SKIP getting
  set on the erase half via handleInstInstalledFile() and
  rpmfiDecideFate(), causing %ghost %config files to be nuked. Which isn't
  very nice when your /var/lib/rpm/ contents are packaged as
  %ghost %config...
- This fixes the %ghost %config testcase but breaks the shared %ghost
  case in turn.
2013-01-30 14:01:59 +02:00
Panu Matilainen 0485eab2c9 Add testcase for %ghost shared with a real file
- Further parametrize conflicttest.spec to allow for different attributes
- Verify that the real file gets created without conflicts, that
  it doesn't get removed when ghost is removed and gets normally removed
  on erase.
- This is the case commit a712252392 was
  supposed to fix (which it does but with, ahem, "slight" side-effects)
2013-01-30 14:01:07 +02:00
Panu Matilainen 5121ea2151 Add testcase for %ghost %config behavior
- Further parametrize configtest.spec to allow for different attributes
- Verify pre-existing %ghost %config is preserved on install,
  that it survives upgrades and gets removed on erase.
  This fails now because it IS broken due to commit
  a712252392.
2013-01-30 13:51:17 +02:00
Panu Matilainen 58f41cb4e1 Dont mess with global user identity in __scm_setup_bzr
- Bzr defaults to global value on "bzr whoami", so we would mess
  up user identity on "%autosetup -S bzr". Oops. Move identity setting
  after repo initialization and set the identity per-branch, not global.
  The notion of "per-branch identity" seems odd, but then bzr is...
  I guess this would be bzr-speak for "per-directory identity"
2013-01-28 22:40:11 +02:00
Panu Matilainen 321a87d789 Setup git identity in __scm_setup_git (RhBug:905002)
- For some reason on my own account git keeps functioning even if
  I remove its configuration, but on a newly created account git commit
  bails out with "Please tell me who you are" unless we set the
  (per-repo) configuration here.
2013-01-28 22:31:30 +02:00
Panu Matilainen 1a21dc867d Split __scm_author to separate name and email address macros
- At least git wants name and email separately, change __scm_author
  to combine the two instead. Related to RhBug:905002.
2013-01-28 22:31:05 +02:00
Panu Matilainen 49519f2564 Acommodate to glibc 2.17 __secure_getenv() renaming
- glibc 2.17 renames __secure_getenv() to secure_getenv() so now we
  need to test for both. Meh.
2013-01-28 18:53:12 +02:00
Panu Matilainen a712252392 Be more careful about skipping shared file/directory creation
- Only skip shared file/dir creation if its actually being created
  by another package. Previously we could've decided to skip an entry
  where the other file was also being skipped for some other reason.
- Ensure %ghost entries always have FA_SKIP on install, previously
  they often were FA_CREATE which makes no sense for %ghost. We dont
  encounter %ghosts at all during install in the FSM as they dont
  exist in the payload, but the file disposition calculations need
  to take them into account now that we're avoiding redundant creates.
- Fixes a regression from commit f7f5f88f9f
  which unearthed the %ghost FA_CREATE issue, reported here:
  http://lists.fedoraproject.org/pipermail/buildsys/2013-January/004047.html
2013-01-28 12:50:39 +02:00
Alexey Tourbin 4eb824937c Adjust rpmspec -P to invoke non-build parse
In the query mode, rpmspecQuery puts the parser into non-build mode
by invoking rpmSpecParse with (RPMSPEC_ANYARCH|RPMSPEC_FORCE) flags.
The same flags should be applied in the parse mode, so that it is
possible to preprocess specfiles separately, i.e. without also
installing sources and patches.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-01-22 13:34:14 +02:00
Panu Matilainen a1d9364adb Make double-quoting work for special %doc (and %license) too
- Up to now, special %doc has been different from everything else in
  %files: double-quoting which is used to escape eg spaces in filenames
  has not worked, but single-quoting and backslash-escapes (which do
  not work elsewhere in %files) "worked" by happenstance due to getting
  passed verbatim to shell/cp. Those and various other %doc hacks people
  have come with stopped working (ticket #858) as starting from
  commit 29677605d4 we perform the
  copies in slightly more controlled manner.
- Rather than re-enable old quirks, make %doc and %license behavior
  consistent with the rest of the %files section: double-quoting and
  globs work, other escaping methods do not.
- This does mean a minor (as docs with spaces are relatively rare)
  compatibility rift in specs, the "official workaround" is that
  if compatibility with older rpm versions is required globs can
  be used instead of quotation.
2013-01-22 08:13:58 +02:00
Panu Matilainen 90463ac2ce On a second thought, rename block_shutdown plugin to systemd_inhibit
- This is highly systemd-specific functionality so it makes sense to
  name the plugin in a way that makes it (more) obvious. No other
  changes besides renaming.
2013-01-21 19:27:57 +02:00
Panu Matilainen 2ffdd6206b First cut at shutdown prevention plugin
- We wouldn't want anybody to shutdown (or reboot) the system while a
  transaction is in progress, it's just that there hasn't been a whole lot
  that could've been done about it. Recent systemd versions provide an API to
  prevent shutdowns however:
  http://www.freedesktop.org/wiki/Software/systemd/inhibit
- Add a simple plugin which, if enabled, tries to acquire a shutdown
  inhibitor lock from systemd for the duration of transactionsd. This
  could use better error handling and all... but its a start at least.
- Note that D-BUS is required, but only for the plugin, not (lib)rpm.
2013-01-15 11:40:11 +02:00
Panu Matilainen e83cc97792 Revert "make "canonicalization(...)shrank by one character" error message more usefull"
- The message is not about basedir and destdir, and printing them
  here only makes the message even more confusing than it was, eg:
      canonicalization unexpectedly shrank by one character \
          ('/home/pmatilai/rpmbuild/BUILD/' vs '/usr/src/debug/')
- This reverts commit 1eea433d99
2013-01-09 14:06:56 +02:00
Panu Matilainen 6941d51e7e Alternatively accept files from command line arguments in elfdeps
- Nothing actually needs this, but for testing & debugging command line
  args are often nicer than having to pass stuff via stdin.
2013-01-08 13:57:41 +02:00