Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
tracker_alone.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2  *
3  * Copyright (c) 2022, 郑昱笙,濮雯旭,张典典(牛校牛子队)
4  * All rights reserved.
5  */
6 
7 #ifndef TRACKER_ALONE_H
8 #define TRACKER_ALONE_H
9 
10 #include <vector>
11 
12 #include "tracker.h"
13 
16 {
17  volatile bool *exiting;
19 
24  typedef int (*start_func)(int argc, char **argv);
27  std::vector<std::string> process_args;
28 };
29 
32 {
34  int pid;
36 
38  std::string process_messages;
39 };
40 
41 // Run tracker as a standalone process, and communicate with pipe
42 struct tracker_alone_base : public tracker_with_config<tracker_alone_env, tracker_alone_event>
43 {
44  private:
46  constexpr static int MAX_PROCESS_MESSAGE_LENGTH = 1024 * 1024 * 4;
47  pid_t child_pid;
49  int stdout_pipe_fd[2];
50  char stdout_pipe_buf[MAX_PROCESS_MESSAGE_LENGTH];
52  void start_child_process();
54  void start_parent_process();
55 
57  int handle_message_event(std::string&& event);
58 
59  public:
62 
64  void start_tracker();
65 
67  static std::unique_ptr<tracker_alone_base> create_tracker_with_default_env(tracker_event_handler handler);
68 
70  struct plain_text_event_printer final : public event_handler<tracker_alone_event>
71  {
73  };
74 };
75 
76 #endif
tracker.h
tracker_alone_env::start_func
int(* start_func)(int argc, char **argv)
The main func.
Definition: tracker_alone.h:24
tracker_alone_base::start_tracker
void start_tracker()
start the separated process
Definition: tracker_alone.cpp:122
tracker_alone_env::exiting
volatile bool * exiting
Definition: tracker_alone.h:17
tracker_alone_base::create_tracker_with_default_env
static std::unique_ptr< tracker_alone_base > create_tracker_with_default_env(tracker_event_handler handler)
create a tracker with config
Definition: tracker_alone.cpp:161
tracker_alone_base::tracker_alone_base
tracker_alone_base(config_data config)
Definition: tracker_alone.cpp:155
event_handler
the event handler for single type
Definition: event_handler.h:52
tracker_alone_event
The single process tracker reported event.
Definition: tracker_alone.h:31
tracker_alone_base::~tracker_alone_base
~tracker_alone_base()
Definition: tracker_alone.cpp:88
tracker_alone_event::pid
int pid
pid for the event
Definition: tracker_alone.h:34
tracker_with_config< tracker_alone_env, tracker_alone_event >::config_data
tracker_config< tracker_alone_env, tracker_alone_event > config_data
type alias for env and config
Definition: tracker.h:65
tracker_alone_env::wait_ms_for_read
int wait_ms_for_read
wait for the child process to write in the pipe
Definition: tracker_alone.h:22
tracker_with_config
tracker template with env and data
Definition: tracker.h:59
tracker_alone_base::plain_text_event_printer::handle
void handle(tracker_event< tracker_alone_event > &e)
implement this function to handle the event
Definition: tracker_alone.cpp:170
tracker_alone_base::plain_text_event_printer
print to stdout
Definition: tracker_alone.h:70
tracker_alone_env::main_func
start_func main_func
the main func
Definition: tracker_alone.h:26
tracker_alone_env::process_args
std::vector< std::string > process_args
Definition: tracker_alone.h:27
tracker_event
the basic event type
Definition: event_handler.h:31
tracker_alone_env
the tracker alone config env
Definition: tracker_alone.h:15
tracker_with_config< tracker_alone_env, tracker_alone_event >::tracker_event_handler
std::shared_ptr< event_handler< tracker_alone_event > > tracker_event_handler
type alias for event handler
Definition: tracker.h:67
config
seccomp_config config
Definition: seccomp_test.cpp:13
tracker_alone_event::process_messages
std::string process_messages
the message for the event
Definition: tracker_alone.h:38
tracker_alone_base
Definition: tracker_alone.h:42