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