96d4812
commit 6ce2d43e2533505aa252159bfa8cc799965655bb
96d4812
Author: Panu Matilainen <pmatilai@redhat.com>
96d4812
Date:   Wed Oct 1 09:59:21 2014 +0300
96d4812
96d4812
    Dont wait for transaction lock within scriptlets (RhBug:1135596)
96d4812
    
96d4812
    - Packages doing stupid things like rpm -U/-i/-e from their scriptlets
96d4812
      can and will get hung waiting on the transaction lock, which can
96d4812
      prompt users to kill the entire transaction, possibly with severe
96d4812
      consequences. Starting with rpm >= 4.12 we also take the transaction
96d4812
      lock for importing public keys, which seems to have caught one of
96d4812
      the bigger fishes in the pond (Google Chrome packages).
96d4812
    - Only wait when stdin is a tty, this affects more than scriptlets but
96d4812
      most likely we dont want to wait for locks in those situations either.
96d4812
96d4812
diff --git a/lib/rpmlock.c b/lib/rpmlock.c
96d4812
index 7696cbe..9c07654 100644
96d4812
--- a/lib/rpmlock.c
96d4812
+++ b/lib/rpmlock.c
96d4812
@@ -124,10 +124,11 @@ rpmlock rpmlockNew(const char *lock_path, const char *descr)
96d4812
 int rpmlockAcquire(rpmlock lock)
96d4812
 {
96d4812
     int locked = 0; /* assume failure */
96d4812
+    int maywait = isatty(STDIN_FILENO); /* dont wait within scriptlets */
96d4812
 
96d4812
     if (lock) {
96d4812
 	locked = rpmlock_acquire(lock, RPMLOCK_WRITE);
96d4812
-	if (!locked && (lock->openmode & RPMLOCK_WRITE)) {
96d4812
+	if (!locked && (lock->openmode & RPMLOCK_WRITE) && maywait) {
96d4812
 	    rpmlog(RPMLOG_WARNING, _("waiting for %s lock on %s\n"),
96d4812
 		    lock->descr, lock->path);
96d4812
 	    locked = rpmlock_acquire(lock, (RPMLOCK_WRITE|RPMLOCK_WAIT));