27 #include <zypp/zyppng/base/private/threaddata_p.h>
33 #include <boost/interprocess/sync/file_lock.hpp>
34 #include <boost/interprocess/sync/scoped_lock.hpp>
35 #include <boost/interprocess/sync/sharable_lock.hpp>
39 using boost::interprocess::file_lock;
40 using boost::interprocess::scoped_lock;
41 using boost::interprocess::sharable_lock;
53 void sigsegvHandler(
int sig );
54 ::sighandler_t lastSigsegvHandler = ::signal( SIGSEGV, sigsegvHandler );
57 void sigsegvHandler(
int sig )
61 ::signal( SIGSEGV, lastSigsegvHandler );
69 {
return getenv(
"ZYPP_LOCKFILE_ROOT") ? getenv(
"ZYPP_LOCKFILE_ROOT") :
"/"; }
73 namespace zypp_readonly_hack
76 static bool active = getenv(
"ZYPP_READONLY_HACK");
81 MIL <<
"ZYPP_READONLY promised." << endl;
122 MIL <<
"Cleanned lock file. (" << getpid() <<
")" << std::endl;
200 MIL <<
"Checking " << status << endl;
202 if ( ! status.
isDir() )
204 DBG <<
"No such process." << endl;
208 static char buffer[513];
209 buffer[0] = buffer[512] = 0;
211 if ( std::ifstream( (procdir/
"cmdline").c_str() ).
read( buffer, 512 ).gcount() > 0 )
218 DBG <<
"In zombie state." << endl;
228 MIL <<
"read: Lockfile " <<
_zyppLockFilePath <<
" has pid " << readpid <<
" (our pid: " << getpid() <<
") "<< std::endl;
229 return (pid_t)readpid;
250 if ( geteuid() != 0 )
275 WAR <<
_lockerPid <<
" is running and has a ZYpp lock. Sorry." << std::endl;
280 MIL <<
_lockerPid <<
" is dead. Taking the lock file." << std::endl;
286 INT <<
"Oops! We should not be here!" << std::endl;
298 ZYppGlobalLock & globalLock()
300 if ( !_theGlobalLock )
301 _theGlobalLock.reset(
new ZYppGlobalLock );
302 return *_theGlobalLock;
316 zyppng::ThreadData::current().setName(
"Zypp-Main");
318 MIL <<
"ZYpp is on..." << endl;
323 _theGlobalLock.reset();
324 MIL <<
"ZYpp is off..." << endl;
335 , _lockerPid( lockerPid_r )
336 , _lockerName( lockerName_r )
361 ZYpp::Ptr _instance = _theZYppInstance.lock();
364 if ( geteuid() != 0 )
366 MIL <<
"Running as user. Skip creating " << globalLock().zyppLockFilePath() << std::endl;
370 MIL <<
"ZYPP_READONLY active." << endl;
372 else if ( globalLock().zyppLocked() )
375 const long LOCK_TIMEOUT = str::strtonum<long>( getenv(
"ZYPP_LOCK_TIMEOUT" ) );
376 if ( LOCK_TIMEOUT > 0 )
378 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within $LOCK_TIMEOUT=" << LOCK_TIMEOUT <<
" sec." << endl;
381 for (
long i = 0; i < LOCK_TIMEOUT; i += delay )
387 MIL <<
"Retry after " << i <<
" sec." << endl;
388 failed = globalLock().zyppLocked();
392 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within " << (LOCK_TIMEOUT-i) <<
" sec." << endl;
397 MIL <<
"Finally got the lock!" << endl;
405 std::string t =
str::form(
_(
"System management is locked by the application with pid %d (%s).\n"
406 "Close this application before trying again."),
407 globalLock().lockerPid(),
408 globalLock().lockerName().c_str()
415 if ( !_theImplInstance )
417 _instance.reset(
new ZYpp( _theImplInstance ) );
418 _theZYppInstance = _instance;
427 {
return !_theZYppInstance.expired(); }
436 return str <<
"ZYppFactory";