31 #include <boost/interprocess/sync/file_lock.hpp>
32 #include <boost/interprocess/sync/scoped_lock.hpp>
33 #include <boost/interprocess/sync/sharable_lock.hpp>
35 using boost::interprocess::file_lock;
36 using boost::interprocess::scoped_lock;
37 using boost::interprocess::sharable_lock;
49 void sigsegvHandler(
int sig );
50 ::sighandler_t lastSigsegvHandler = ::signal( SIGSEGV, sigsegvHandler );
53 void sigsegvHandler(
int sig )
56 ::signal( SIGSEGV, lastSigsegvHandler );
64 {
return getenv(
"ZYPP_LOCKFILE_ROOT") ? getenv(
"ZYPP_LOCKFILE_ROOT") :
"/"; }
68 namespace zypp_readonly_hack
71 static bool active = getenv(
"ZYPP_READONLY_HACK");
76 MIL <<
"ZYPP_READONLY promised." << endl;
117 MIL <<
"Cleanned lock file. (" << getpid() <<
")" << std::endl;
195 MIL <<
"Checking " << status << endl;
197 if ( ! status.
isDir() )
199 DBG <<
"No such process." << endl;
203 static char buffer[513];
204 buffer[0] = buffer[512] = 0;
206 if ( std::ifstream( (procdir/
"cmdline").c_str() ).
read( buffer, 512 ).gcount() > 0 )
213 DBG <<
"In zombie state." << endl;
223 MIL <<
"read: Lockfile " <<
_zyppLockFilePath <<
" has pid " << readpid <<
" (our pid: " << getpid() <<
") "<< std::endl;
224 return (pid_t)readpid;
245 if ( geteuid() != 0 )
270 WAR <<
_lockerPid <<
" is running and has a ZYpp lock. Sorry." << std::endl;
275 MIL <<
_lockerPid <<
" is dead. Taking the lock file." << std::endl;
281 INT <<
"Oops! We should not be here!" << std::endl;
293 ZYppGlobalLock & globalLock()
295 if ( !_theGlobalLock )
296 _theGlobalLock.reset(
new ZYppGlobalLock );
297 return *_theGlobalLock;
312 MIL <<
"ZYpp is on..." << endl;
317 _theGlobalLock.reset();
318 MIL <<
"ZYpp is off..." << endl;
329 , _lockerPid( lockerPid_r )
330 , _lockerName( lockerName_r )
355 ZYpp::Ptr _instance = _theZYppInstance.lock();
358 if ( geteuid() != 0 )
360 MIL <<
"Running as user. Skip creating " << globalLock().zyppLockFilePath() << std::endl;
364 MIL <<
"ZYPP_READONLY active." << endl;
366 else if ( globalLock().zyppLocked() )
369 const long LOCK_TIMEOUT = str::strtonum<long>( getenv(
"ZYPP_LOCK_TIMEOUT" ) );
370 if ( LOCK_TIMEOUT > 0 )
372 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within $LOCK_TIMEOUT=" << LOCK_TIMEOUT <<
" sec." << endl;
375 for (
long i = 0; i < LOCK_TIMEOUT; i += delay )
381 MIL <<
"Retry after " << i <<
" sec." << endl;
382 failed = globalLock().zyppLocked();
386 MIL <<
"Waiting whether pid " << globalLock().lockerPid() <<
" ends within " << (LOCK_TIMEOUT-i) <<
" sec." << endl;
391 MIL <<
"Finally got the lock!" << endl;
399 std::string t =
str::form(
_(
"System management is locked by the application with pid %d (%s).\n"
400 "Close this application before trying again."),
401 globalLock().lockerPid(),
402 globalLock().lockerName().c_str()
409 if ( !_theImplInstance )
411 _instance.reset(
new ZYpp( _theImplInstance ) );
412 _theZYppInstance = _instance;
421 {
return !_theZYppInstance.expired(); }
430 return str <<
"ZYppFactory";