Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
OOMCrashPlugin.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2020 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: OOMCrashPlugin.h
21  *
22  */
23 #ifndef OOMCRASH_H
24 #define OOMCRASH_H
25 
26 #include <RdkPluginBase.h>
27 
28 #include <sys/stat.h>
29 
35 class OOMCrash : public RdkPluginBase
36 {
37 public:
38  OOMCrash(std::shared_ptr<rt_dobby_schema>& containerConfig,
39  const std::shared_ptr<DobbyRdkPluginUtils> &utils,
40  const std::string &rootfsPath);
41 
42 public:
43  inline std::string name() const override
44  {
45  return mName;
46  };
47 
48  // Override to return the appropriate hints for what we implement
49  unsigned hookHints() const override;
50 
51 public:
52  bool postInstallation() override;
53  bool postHalt() override;
54 
55 public:
56  std::vector<std::string> getDependencies() const override;
57 
58 private:
59  bool readCgroup(unsigned long *val);
60  bool checkForOOM();
61  void createFileForOOM();
62 
63  const std::string mName;
64  std::shared_ptr<rt_dobby_schema> mContainerConfig;
65  const std::string mRootfsPath;
66  const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
67 };
68 
69 
70 #endif // !defined(OOMCRASH_H)
Dobby RDK OOMCrash Plugin.
Definition: OOMCrashPlugin.h:36
OOMCrash(std::shared_ptr< rt_dobby_schema > &containerConfig, const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::string &rootfsPath)
Constructor - called when plugin is loaded by PluginLauncher.
Definition: OOMCrashPlugin.cpp:35
bool readCgroup(unsigned long *val)
Read cgroup file.
Definition: OOMCrashPlugin.cpp:161
bool checkForOOM()
Check for Out of Memory by reading cgroup file.
Definition: OOMCrashPlugin.cpp:201
std::vector< std::string > getDependencies() const override
Should return the names of the plugins this plugin depends on.
Definition: OOMCrashPlugin.cpp:140
bool postInstallation() override
Dobby Hook - run in host namespace once when container bundle is downloaded.
Definition: OOMCrashPlugin.cpp:63
std::string name() const override
Should return the name of the plugin.
Definition: OOMCrashPlugin.h:43
unsigned hookHints() const override
Set the bit flags for which hooks we're going to use.
Definition: OOMCrashPlugin.cpp:53
void createFileForOOM()
Create OOM crash file named oom_crashed_<container_name>.txt on the configured path.
Definition: OOMCrashPlugin.cpp:223
bool postHalt() override
Dobby Hook - Run in host namespace when container terminates.
Definition: OOMCrashPlugin.cpp:96
Basic object that provides the default overrides for a plugin.
Definition: RdkPluginBase.h:34