30 #include <boost/interprocess/sync/file_lock.hpp>
31 #include <boost/interprocess/sync/scoped_lock.hpp>
32 #include <boost/interprocess/sync/sharable_lock.hpp>
34 using boost::interprocess::file_lock;
35 using boost::interprocess::scoped_lock;
36 using boost::interprocess::sharable_lock;
48 void sigsegvHandler(
int sig );
49 ::sighandler_t lastSigsegvHandler = ::signal( SIGSEGV, sigsegvHandler );
52 void sigsegvHandler(
int sig )
55 ::signal( SIGSEGV, lastSigsegvHandler );
63 {
return getenv(
"ZYPP_LOCKFILE_ROOT") ? getenv(
"ZYPP_LOCKFILE_ROOT") :
"/"; }
67 namespace zypp_readonly_hack
70 static bool active = getenv(
"ZYPP_READONLY_HACK");
75 MIL <<
"ZYPP_READONLY promised." << endl;
116 MIL <<
"Cleaned lock file. (" << getpid() <<
")" << std::endl;
194 MIL <<
"Checking " << status << endl;
196 if ( ! status.
isDir() )
198 DBG <<
"No such process." << endl;
202 static char buffer[513];
203 buffer[0] = buffer[512] = 0;
205 if ( std::ifstream( (procdir/
"cmdline").c_str() ).
read( buffer, 512 ).gcount() > 0 )
212 DBG <<
"In zombie state." << endl;
222 MIL <<
"read: Lockfile " <<
_zyppLockFilePath <<
" has pid " << readpid <<
" (our pid: " << getpid() <<
") "<< std::endl;
223 return (pid_t)readpid;
244 if ( geteuid() != 0 )
269 WAR <<
_lockerPid <<
" is running and has a ZYpp lock. Sorry." << std::endl;
274 MIL <<
_lockerPid <<
" is dead. Taking the lock file." << std::endl;
280 INT <<
"Oops! We should not be here!" << std::endl;
292 ZYppGlobalLock & globalLock()
294 if ( !_theGlobalLock )
295 _theGlobalLock.reset(
new ZYppGlobalLock );
296 return *_theGlobalLock;
311 MIL <<
"ZYpp is on..." << endl;
316 _theGlobalLock.reset();
317 MIL <<
"ZYpp is off..." << endl;
328 , _lockerPid( lockerPid_r )
329 , _lockerName( lockerName_r )
354 ZYpp::Ptr _instance = _theZYppInstance.lock();
357 if ( geteuid() != 0 )
359 MIL <<
"Running as user. Skip creating " << globalLock().zyppLockFilePath() << std::endl;
363 MIL <<
"ZYPP_READONLY active." << endl;
365 else if ( globalLock().zyppLocked() )
368 const long LOCK_TIMEOUT = str::strtonum<long>( getenv(
"ZYPP_LOCK_TIMEOUT" ) );
369 if ( LOCK_TIMEOUT > 0 )
371 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within $LOCK_TIMEOUT=" << LOCK_TIMEOUT <<
" sec." << endl;
374 for (
long i = 0; i < LOCK_TIMEOUT; i += delay )
380 MIL <<
"Retry after " << i <<
" sec." << endl;
381 failed = globalLock().zyppLocked();
385 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within " << (LOCK_TIMEOUT-i) <<
" sec." << endl;
390 MIL <<
"Finally got the lock!" << endl;
398 std::string t =
str::form(
_(
"System management is locked by the application with pid %d (%s).\n"
399 "Close this application before trying again."),
400 globalLock().lockerPid(),
401 globalLock().lockerName().c_str()
408 if ( !_theImplInstance )
410 _instance.reset(
new ZYpp( _theImplInstance ) );
411 _theZYppInstance = _instance;
420 {
return !_theZYppInstance.expired(); }
429 return str <<
"ZYppFactory";