///////////////////////////////////////////////////////////////////
//
+ // 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
//
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
/** \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"
#define ZYPP_LOCK_FILE "/var/run/zypp.pid"
using std::endl;
-using namespace std;
///////////////////////////////////////////////////////////////////
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;
}
/*--------------------------------------------------*/
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