File: EventsSourceSpawner.h

package info (click to toggle)
drbd-utils 9.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,388 kB
  • sloc: ansic: 43,698; xml: 15,968; cpp: 7,783; sh: 3,699; makefile: 1,353; perl: 353
file content (73 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef EVENTSSOURCESPAWNER_H
#define	EVENTSSOURCESPAWNER_H

#include <new>
#include <stdexcept>

#include <MessageLog.h>
#include <exceptions.h>

extern "C"
{
    #include <sys/types.h>
}

class EventsSourceSpawner
{
  public:
    static const char* EVENTS_PROGRAM;
    static const char* EVENTS_PROGRAM_ARGS[];

    static const int PIPE_READ_SIDE;
    static const int PIPE_WRITE_SIDE;

    EventsSourceSpawner(MessageLog& logRef);
    virtual ~EventsSourceSpawner();

    EventsSourceSpawner(const EventsSourceSpawner& orig) = delete;
    EventsSourceSpawner& operator=(const EventsSourceSpawner& orig) = delete;
    EventsSourceSpawner(EventsSourceSpawner&& orig) = default;
    EventsSourceSpawner& operator=(EventsSourceSpawner&& orig) = default;

    virtual pid_t get_process_id();
    virtual int get_events_source_fd();

    // @throws std::bad_alloc, EventSourceException
    virtual int spawn_source();

    // @throws EventsSourceException
    virtual void cleanup_child_processes();
  private:
    MessageLog& log;

    void close_pipe();

    // @throws EventsSourceException
    void checked_int_rc(int rc) const;

    // @throws std::bad_alloc
    char** init_spawn_args() const;
    void destroy_spawn_args(char** spawn_args) const noexcept;

    // @throws EventsSourceException
    void cleanup_child_processes_impl();

    void terminate_child_process() noexcept;

    pid_t spawned_pid {-1};
    int   pipe_fd[2]  {-1, -1};
};

class EventsSourceException : public EventException
{
  public:
    EventsSourceException() = default;
    virtual ~EventsSourceException() noexcept = default;

    EventsSourceException(const EventsSourceException& orig) = delete;
    EventsSourceException& operator=(const EventsSourceException& orig) = delete;
    EventsSourceException(EventsSourceException&& orig) = default;
    EventsSourceException& operator=(EventsSourceException&& orig) = default;
};

#endif	/* EVENTSSOURCESPAWNER_H */