pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
mainloop.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2024 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 PCMK__CRM_COMMON_MAINLOOP__H
11 #define PCMK__CRM_COMMON_MAINLOOP__H
12 
13 #include <stdbool.h> // bool
14 #include <signal.h> // sighandler_t
15 #include <sys/types.h> // pid_t, ssize_t
16 
17 #include <glib.h> // gpointer, gboolean, guint, GSourceFunc, GMainLoop
18 #include <qb/qbipcs.h> // qb_ipcs_service_t, etc.
19 
20 #include <crm/common/ipc.h>
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
34  /* don't kill pid group on timeout, only kill the pid */
36 };
37 
38 // NOTE: sbd (as of at least 1.5.2) uses this
39 typedef struct trigger_s crm_trigger_t;
40 
41 typedef struct mainloop_io_s mainloop_io_t;
42 typedef struct mainloop_child_s mainloop_child_t;
43 
44 // NOTE: sbd (as of at least 1.5.2) uses this
45 typedef struct mainloop_timer_s mainloop_timer_t;
46 
47 void mainloop_cleanup(void);
48 
49 // NOTE: sbd (as of at least 1.5.2) uses this
50 crm_trigger_t *mainloop_add_trigger(int priority, int (*dispatch) (gpointer user_data),
51  gpointer userdata);
52 
53 // NOTE: sbd (as of at least 1.5.2) uses this
54 void mainloop_set_trigger(crm_trigger_t * source);
55 
57 
58 gboolean mainloop_destroy_trigger(crm_trigger_t * source);
59 
60 #ifndef HAVE_SIGHANDLER_T
61 typedef void (*sighandler_t)(int);
62 #endif
63 
65 
66 // NOTE: sbd (as of at least 1.5.2) uses this
67 gboolean mainloop_add_signal(int sig, void (*dispatch) (int sig));
68 
69 gboolean mainloop_destroy_signal(int sig);
70 
72 
73 // NOTE: sbd (as of at least 1.5.2) uses this
75 
76 // NOTE: sbd (as of at least 1.5.2) uses this
78 
79 guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms);
80 
81 // NOTE: sbd (as of at least 1.5.2) uses this
82 mainloop_timer_t *mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata);
83 
85 
96  int (*dispatch) (const char *buffer, ssize_t length, gpointer userdata);
97 
103  void (*destroy) (gpointer userdata);
104 };
105 
106 qb_ipcs_service_t *mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
107  struct qb_ipcs_service_handlers *callbacks);
108 
128 qb_ipcs_service_t *mainloop_add_ipc_server_with_prio(const char *name,
129  enum qb_ipc_type type,
130  struct qb_ipcs_service_handlers *callbacks,
131  enum qb_loop_priority prio);
132 
133 void mainloop_del_ipc_server(qb_ipcs_service_t * server);
134 
135 mainloop_io_t *mainloop_add_ipc_client(const char *name, int priority, size_t max_size,
136  void *userdata, struct ipc_client_callbacks *callbacks);
137 
139 
141 
150  int (*dispatch) (gpointer userdata);
151 
157  void (*destroy) (gpointer userdata);
158 };
159 
160 mainloop_io_t *mainloop_add_fd(const char *name, int priority, int fd, void *userdata,
161  struct mainloop_fd_callbacks *callbacks);
162 
163 void mainloop_del_fd(mainloop_io_t * client);
164 
165 /*
166  * Create a new tracked process
167  * To track a process group, use -pid
168  */
169 void mainloop_child_add(pid_t pid,
170  int timeout,
171  const char *desc,
172  void *userdata,
173  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
174 
176  int timeout,
177  const char *desc,
178  void *userdata,
180  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
181 
184 const char *mainloop_child_name(mainloop_child_t * child);
185 
186 pid_t mainloop_child_pid(mainloop_child_t * child);
188 gboolean mainloop_child_kill(pid_t pid);
189 
190 void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n);
191 void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms,
192  bool (*check)(guint));
193 
194 #define G_PRIORITY_MEDIUM (G_PRIORITY_HIGH/2)
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif
gboolean mainloop_add_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:353
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
Definition: mainloop.c:956
void mainloop_timer_start(mainloop_timer_t *t)
Definition: mainloop.c:1330
guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms)
Definition: mainloop.c:1350
mainloop_child_flags
Definition: mainloop.h:33
void mainloop_timer_del(mainloop_timer_t *t)
Definition: mainloop.c:1385
const char * name
Definition: cib.c:26
enum pcmk_ipc_server type
Definition: cpg.c:51
gboolean mainloop_child_kill(pid_t pid)
Definition: mainloop.c:1196
void(* destroy)(gpointer userdata)
Destroy function for mainloop file descriptor client data.
Definition: mainloop.h:157
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:644
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:1444
struct mainloop_timer_s mainloop_timer_t
Definition: mainloop.h:45
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:41
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:1252
struct mainloop_child_s mainloop_child_t
Definition: mainloop.h:42
void mainloop_set_trigger(crm_trigger_t *source)
Definition: mainloop.c:195
void mainloop_cleanup(void)
Definition: mainloop.c:417
pid_t mainloop_child_pid(mainloop_child_t *child)
Definition: mainloop.c:1016
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
Definition: mainloop.c:203
void mainloop_timer_stop(mainloop_timer_t *t)
Definition: mainloop.c:1340
struct trigger_s crm_trigger_t
Definition: mainloop.h:39
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
Definition: mainloop.h:150
uint32_t pid
Definition: cpg.c:49
void * mainloop_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:1034
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:151
void(* destroy)(gpointer userdata)
Destroy function for mainloop IPC connection client data.
Definition: mainloop.h:103
sighandler_t crm_signal_handler(int sig, sighandler_t dispatch)
Definition: mainloop.c:304
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Create a trigger to be used as a mainloop source.
Definition: mainloop.c:183
void mainloop_del_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:941
bool mainloop_timer_running(mainloop_timer_t *t)
Definition: mainloop.c:1321
void(* sighandler_t)(int)
Definition: mainloop.h:61
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:1283
void mainloop_trigger_complete(crm_trigger_t *trig)
Definition: mainloop.c:164
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:947
void mainloop_clear_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:1040
void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n)
Drain some remaining main loop events then quit it.
Definition: mainloop.c:1415
IPC interface to Pacemaker daemons.
void mainloop_del_fd(mainloop_io_t *client)
Definition: mainloop.c:1000
void mainloop_del_ipc_server(qb_ipcs_service_t *server)
Definition: mainloop.c:681
mainloop_timer_t * mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
Definition: mainloop.c:1366
gboolean mainloop_destroy_signal(int sig)
Definition: mainloop.c:397
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:916
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:637
const char * mainloop_child_name(mainloop_child_t *child)
Definition: mainloop.c:1022
unsigned int timeout
Definition: pcmk_fence.c:34
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
Definition: mainloop.h:96
int mainloop_child_timeout(mainloop_child_t *child)
Definition: mainloop.c:1028