pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
mainloop.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2020 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef CRM_COMMON_MAINLOOP__H
11 # define CRM_COMMON_MAINLOOP__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 # include <signal.h> // sighandler_t
24 # include <glib.h>
25 
27  /* don't kill pid group on timeout, only kill the pid */
29 };
30 
31 typedef struct trigger_s crm_trigger_t;
32 typedef struct mainloop_io_s mainloop_io_t;
33 typedef struct mainloop_child_s mainloop_child_t;
34 typedef struct mainloop_timer_s mainloop_timer_t;
35 
36 void mainloop_cleanup(void);
37 
38 crm_trigger_t *mainloop_add_trigger(int priority, int (*dispatch) (gpointer user_data),
39  gpointer userdata);
40 
41 void mainloop_set_trigger(crm_trigger_t * source);
42 
44 
45 gboolean mainloop_destroy_trigger(crm_trigger_t * source);
46 
47 # ifndef HAVE_SIGHANDLER_T
48 typedef void (*sighandler_t)(int);
49 # endif
50 
52 
53 gboolean mainloop_add_signal(int sig, void (*dispatch) (int sig));
54 
55 gboolean mainloop_destroy_signal(int sig);
56 
58 
60 
62 
63 guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms);
64 
65 mainloop_timer_t *mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata);
66 
68 
69 
70 # include <crm/common/ipc.h>
71 # include <qb/qbipcs.h>
72 
74  int (*dispatch) (const char *buffer, ssize_t length, gpointer userdata);
75  void (*destroy) (gpointer);
76 };
77 
78 qb_ipcs_service_t *mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
79  struct qb_ipcs_service_handlers *callbacks);
80 
100 qb_ipcs_service_t *mainloop_add_ipc_server_with_prio(const char *name,
101  enum qb_ipc_type type,
102  struct qb_ipcs_service_handlers *callbacks,
103  enum qb_loop_priority prio);
104 
105 void mainloop_del_ipc_server(qb_ipcs_service_t * server);
106 
107 mainloop_io_t *mainloop_add_ipc_client(const char *name, int priority, size_t max_size,
108  void *userdata, struct ipc_client_callbacks *callbacks);
109 
111 
113 
115  int (*dispatch) (gpointer userdata);
116  void (*destroy) (gpointer userdata);
117 };
118 
119 mainloop_io_t *mainloop_add_fd(const char *name, int priority, int fd, void *userdata,
120  struct mainloop_fd_callbacks *callbacks);
121 
122 void mainloop_del_fd(mainloop_io_t * client);
123 
124 /*
125  * Create a new tracked process
126  * To track a process group, use -pid
127  */
128 void mainloop_child_add(pid_t pid,
129  int timeout,
130  const char *desc,
131  void *userdata,
132  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
133 
135  int timeout,
136  const char *desc,
137  void *userdata,
139  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
140 
143 const char *mainloop_child_name(mainloop_child_t * child);
144 
145 pid_t mainloop_child_pid(mainloop_child_t * child);
147 gboolean mainloop_child_kill(pid_t pid);
148 
149 void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n);
150 void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms,
151  bool (*check)(guint));
152 
153 # define G_PRIORITY_MEDIUM (G_PRIORITY_HIGH/2)
154 
155 #ifndef PCMK__NO_COMPAT
156 /* Everything here is deprecated and kept only for public API backward
157  * compatibility. It will be moved to compatibility.h in a future release.
158  */
159 gboolean crm_signal(int sig, void (*dispatch) (int sig)); // deprecated
160 #endif
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
void(* destroy)(gpointer)
Definition: mainloop.h:75
gboolean mainloop_add_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:328
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
Definition: mainloop.c:915
void mainloop_timer_start(mainloop_timer_t *t)
Definition: mainloop.c:1301
guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms)
Definition: mainloop.c:1321
mainloop_child_flags
Definition: mainloop.h:26
void mainloop_timer_del(mainloop_timer_t *t)
Definition: mainloop.c:1358
gboolean mainloop_child_kill(pid_t pid)
Definition: mainloop.c:1155
void(* destroy)(gpointer userdata)
Definition: mainloop.h:116
qb_ipcs_service_t * mainloop_add_ipc_server_with_prio(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks, enum qb_loop_priority prio)
Start server-side API end-point, hooked into the internal event loop.
Definition: mainloop.c:650
void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms, bool(*check)(guint))
Process main loop events while a certain condition is met.
Definition: mainloop.c:1416
struct mainloop_timer_s mainloop_timer_t
Definition: mainloop.h:34
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:32
void mainloop_child_add_with_flags(pid_t pid, int timeout, const char *desc, void *userdata, enum mainloop_child_flags, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
Definition: mainloop.c:1211
struct mainloop_child_s mainloop_child_t
Definition: mainloop.h:33
void mainloop_set_trigger(crm_trigger_t *source)
Definition: mainloop.c:171
void mainloop_cleanup(void)
Definition: mainloop.c:402
pid_t mainloop_child_pid(mainloop_child_t *child)
Definition: mainloop.c:975
uint32_t pid
Definition: internal.h:81
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
Definition: mainloop.c:179
void mainloop_timer_stop(mainloop_timer_t *t)
Definition: mainloop.c:1311
struct trigger_s crm_trigger_t
Definition: mainloop.h:31
int(* dispatch)(gpointer userdata)
Definition: mainloop.h:115
void * mainloop_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:993
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:162
gboolean crm_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:1447
sighandler_t crm_signal_handler(int sig, sighandler_t dispatch)
Definition: mainloop.c:280
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Definition: mainloop.c:159
void mainloop_del_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:900
bool mainloop_timer_running(mainloop_timer_t *t)
Definition: mainloop.c:1292
void(* sighandler_t)(int)
Definition: mainloop.h:48
void mainloop_child_add(pid_t pid, int timeout, const char *desc, void *userdata, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
Definition: mainloop.c:1245
void mainloop_trigger_complete(crm_trigger_t *trig)
Definition: mainloop.c:147
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:906
void mainloop_clear_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:999
void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n)
Drain some remaining main loop events then quit it.
Definition: mainloop.c:1388
IPC interface to Pacemaker daemons.
void mainloop_del_fd(mainloop_io_t *client)
Definition: mainloop.c:959
void mainloop_del_ipc_server(qb_ipcs_service_t *server)
Definition: mainloop.c:689
mainloop_timer_t * mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
Definition: mainloop.c:1337
gboolean mainloop_destroy_signal(int sig)
Definition: mainloop.c:382
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
Definition: mainloop.c:880
qb_ipcs_service_t * mainloop_add_ipc_server(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
Definition: mainloop.c:643
char * name
Definition: pcmk_fence.c:31
const char * mainloop_child_name(mainloop_child_t *child)
Definition: mainloop.c:981
unsigned int timeout
Definition: pcmk_fence.c:32
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Definition: mainloop.h:74
enum crm_ais_msg_types type
Definition: internal.h:83
int mainloop_child_timeout(mainloop_child_t *child)
Definition: mainloop.c:987