Log more details about zypp lock owner.
authorMichael Andres <ma@suse.de>
Mon, 10 Dec 2007 11:49:03 +0000 (11:49 +0000)
committerMichael Andres <ma@suse.de>
Mon, 10 Dec 2007 11:49:03 +0000 (11:49 +0000)
devel/devel.ma/NewPool.cc
package/libzypp.changes
zypp/PathInfo.cc
zypp/PathInfo.h
zypp/ZYppFactory.cc

index 1047341..a507a00 100644 (file)
@@ -476,6 +476,7 @@ int main( int argc, char * argv[] )
   USR << "pool: " << pool << endl;
   pool.satSync();
 
+  waitForInput();
 
   //std::for_each( pool.begin(), pool.end(), Xprint() );
 
index bdde232..f985d3e 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Mon Dec 10 12:46:26 CET 2007 - ma@suse.de
+
+- Log more details about zypp lock owner. (#294094)
+- revision 8088
+
+-------------------------------------------------------------------
 Fri Dec  7 15:47:53 CET 2007 - ma@suse.de
 
 - Remove runtime dependency for libboost_filesystem (#345773)
index 877c8ba..9b673ba 100644 (file)
@@ -735,6 +735,27 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
+    // METHOD NAME : readlink
+    // METHOD TYPE : int
+    //
+    int readlink( const Pathname & symlink_r, Pathname & target_r )
+    {
+      static const ssize_t bufsiz = 2047;
+      static char buf[bufsiz+1];
+      ssize_t ret = ::readlink( symlink_r.c_str(), buf, bufsiz );
+      if ( ret == -1 )
+      {
+        target_r = Pathname();
+        MIL << "readlink " << symlink_r;
+        return _Log_Result( errno );
+      }
+      buf[ret] = '\0';
+      target_r = buf;
+      return 0;
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    //
     // METHOD NAME : copy_file2dir
     // METHOD TYPE : int
     //
index 7c33602..2f537d2 100644 (file)
@@ -567,6 +567,21 @@ namespace zypp
     int hardlink( const Pathname & oldpath, const Pathname & newpath );
 
     /**
+     * Like '::readlink'. Return the contents of the symbolic link
+     * \a symlink_r via \a target_r.
+     *
+     * @return 0 on success, errno on failure.
+     */
+    int readlink( const Pathname & symlink_r, Pathname & target_r );
+    /** \overload Return an empty Pathname on error. */
+    inline Pathname readlink( const Pathname & symlink_r )
+    {
+      Pathname target;
+      readlink( symlink_r, target );
+      return target;
+    }
+
+    /**
      * Like 'cp file dest'. Copy file to dest dir.
      *
      * @return 0 on success, EINVAL if file is not a file, ENOTDIR if dest
index caf1734..e62a4d7 100644 (file)
@@ -9,16 +9,16 @@
 /** \file      zypp/ZYppFactory.cc
  *
 */
-
+extern "C"
+{
 #include <sys/file.h>
-#include <cstdio>
-#include <unistd.h>
-#include <fstream>
+}
 #include <iostream>
-#include <sstream>
+#include <fstream>
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/Gettext.h"
+#include "zypp/base/IOStream.h"
 #include "zypp/PathInfo.h"
 
 #include "zypp/ZYppFactory.h"
@@ -28,7 +28,6 @@
 #define ZYPP_LOCK_FILE "/var/run/zypp.pid"
 
 using std::endl;
-using namespace std;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -163,14 +162,29 @@ namespace zypp
       closeLockFile();
     }
 
-    bool isProcessRunning(pid_t pid)
+    bool isProcessRunning(pid_t pid_r)
     {
-    // it is another program, not me, see if it is still running
-      stringstream ss;
-      ss << "/proc/" << pid << "/status";
-      Pathname procfile = Pathname(ss.str());
-      MIL << "Checking " << procfile << " to determine if pid is running: " << pid << std::endl;
-      bool still_running = PathInfo(procfile).isExist();
+      // it is another program, not me, see if it is still running
+      Pathname procdir( "/proc"/str::numstring(pid_r) );
+
+      PathInfo status( procdir/"status" );
+      MIL << "Checking " <<  status << endl;
+      bool still_running = status.isExist();
+
+      if ( still_running )
+      {
+        Pathname p( procdir/"exe" );
+        MIL << p << " -> " << filesystem::readlink( p ) << endl;
+
+        p = procdir/"cmdline";
+        MIL << p << ": ";
+        std::ifstream infile( p.c_str() );
+        for( iostr::EachLine in( infile ); in; in.next() )
+        {
+          MIL << *in << endl;
+        }
+      }
+
       return still_running;
     }
 
@@ -337,9 +351,9 @@ namespace zypp
       /*--------------------------------------------------*/
       if ( globalLock.zyppLocked() )
       {
-       string t = str::form(N_("System management is locked by the application with pid %d. "
-                               "Please close this application before trying again."),
-                            globalLock.locker_pid());
+       std::string t = str::form(N_("System management is locked by the application with pid %d. "
+                                  "Please close this application before trying again."),
+                                  globalLock.locker_pid());
        ZYPP_THROW(ZYppFactoryException(t, globalLock.locker_pid()));
       }
       else