libzypp 17.31.7
ShutdownLock.cc
Go to the documentation of this file.
1#include "ShutdownLock_p.h"
2
3#include <zypp/base/LogTools.h>
4#include <zypp/ExternalProgram.h>
5#include <iostream>
6
7zypp::ShutdownLock::ShutdownLock(const std::string &reason)
8{
9 try {
10 MIL << "Try to acquire an inhibitor lock..." << endl;
11 std::string whyStr = str::form("--why=%s", reason.c_str());
12
13 const char* argv[] =
14 {
15 "/usr/bin/systemd-inhibit",
16 "--what=sleep:shutdown:idle",
17 "--who=zypp",
18 "--mode=block",
19 whyStr.c_str(),
20 "/usr/bin/cat",
21 NULL
22 };
23 _prog = shared_ptr<ExternalProgramWithSeperatePgid>( new ExternalProgramWithSeperatePgid( argv, ExternalProgram::Discard_Stderr ) );
24 } catch (...) {
25 }
26}
27
29{
30 if (_prog) {
31 MIL << "Terminate inhibitor lock: pid " << _prog->getpid() << endl;
32 _prog->kill(15);
33 _prog->close();
34 }
35}
ExternalProgramWithStderr & _prog
Definition: PluginScript.cc:77
ExternalProgram extended to change the progress group ID after forking.
bool kill()
Kill the program.
pid_t getpid()
return pid
int close()
Wait for the progamm to complete.
shared_ptr< ExternalProgramWithSeperatePgid > _prog
ShutdownLock(const std::string &reason)
Definition: ShutdownLock.cc:7
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
#define MIL
Definition: Logger.h:96