Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DobbyLogger.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 #ifndef DOBBYLOGGER_H
21 #define DOBBYLOGGER_H
22 
23 #include <sys/types.h>
24 
25 #include "ContainerId.h"
26 #include "IDobbyRdkLoggingPlugin.h"
27 #include <IDobbySettings.h>
28 #include "DobbyRdkPluginManager.h"
29 #include "DobbyLogRelay.h"
30 #include "PollLoop.h"
31 #include <rt_dobby_schema.h>
32 
33 #include <pthread.h>
34 
35 #include <string>
36 #include <thread>
37 #include <vector>
38 #include <mutex>
39 
41 {
42 public:
43  DobbyLogger(const std::shared_ptr<const IDobbySettings> &settings);
44  ~DobbyLogger();
45 
46 public:
47  bool StartContainerLogging(std::string containerId,
48  pid_t runtimePid,
49  pid_t containerPid,
50  std::shared_ptr<IDobbyRdkLoggingPlugin> loggingPlugin);
51 
52  bool DumpBuffer(int bufferMemFd,
53  pid_t containerPid,
54  std::shared_ptr<IDobbyRdkLoggingPlugin> loggingPlugin);
55 
56 private:
57  int createDgramSocket(const std::string &path);
58  int createUnixSocket(const std::string path);
59  int receiveFdFromSocket(const int connectionFd);
60  void connectionMonitorThread(const int socketFd);
61 
62  void closeAndDeleteSocket(const int fd, const std::string& path);
63 
64 private:
65  std::mutex mLock;
66 
67  int mSocketFd;
68  const std::string mSocketPath;
69  const std::string mSyslogSocketPath;
70  const std::string mJournaldSocketPath;
71 
72  // Map of container PID -> tty file descriptor
73  std::map<pid_t, int> mTempFds;
74 
75  std::shared_ptr<AICommon::PollLoop> mPollLoop;
76 
77  std::shared_ptr<DobbyLogRelay> mSyslogRelay;
78  std::shared_ptr<DobbyLogRelay> mJournaldRelay;
79 };
80 
81 #endif // !defined(DOBBYLOGGER_H)
82 
Definition: DobbyLogger.h:41
bool DumpBuffer(int bufferMemFd, pid_t containerPid, std::shared_ptr< IDobbyRdkLoggingPlugin > loggingPlugin)
Blocking method that writes the contents of a buffer at a given memFd to the logger specified in the ...
Definition: DobbyLogger.cpp:383
int createUnixSocket(const std::string path)
Create a new UNIX domain socket that the OCI runtime can connect to and send the fd of the ptty used ...
Definition: DobbyLogger.cpp:125
bool StartContainerLogging(std::string containerId, pid_t runtimePid, pid_t containerPid, std::shared_ptr< IDobbyRdkLoggingPlugin > loggingPlugin)
Public method that should be called once a container has been created to match the container PID with...
Definition: DobbyLogger.cpp:337
int receiveFdFromSocket(const int connectionFd)
Once a connection to the socket has been made, wait to receive a message that contains a file descrip...
Definition: DobbyLogger.cpp:179
void closeAndDeleteSocket(const int fd, const std::string &path)
Closes and deletes a socket at a given fd/path.
Definition: DobbyLogger.cpp:414
void connectionMonitorThread(const int socketFd)
Runs for the lifetime of the daemon, waiting for new connections to the socket. Once a connection is ...
Definition: DobbyLogger.cpp:243