File: EventsSourceSpawner.h

package info (click to toggle)
drbd-utils 9.22.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,768 kB
  • sloc: ansic: 48,975; xml: 11,553; cpp: 9,843; sh: 4,568; makefile: 1,029; perl: 353; ruby: 43
file content (62 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download | duplicates (4)
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
#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[];

    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_out_fd();
    virtual int get_events_err_fd();

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

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

    void close_pipe();

    void set_nonblocking(int fd);

    // @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   out_pipe_fd[2]  {-1, -1};
    int   err_pipe_fd[2]  {-1, -1};
};

#endif	/* EVENTSSOURCESPAWNER_H */