pacemaker  2.1.9-49aab99839
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 <signal.h> // sighandler_t
14 #include <glib.h>
15 #include <stdbool.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
28  /* don't kill pid group on timeout, only kill the pid */
30 };
31 
32 // NOTE: sbd (as of at least 1.5.2) uses this
33 typedef struct trigger_s crm_trigger_t;
34 
35 typedef struct mainloop_io_s mainloop_io_t;
36 typedef struct mainloop_child_s mainloop_child_t;
37 
38 // NOTE: sbd (as of at least 1.5.2) uses this
39 typedef struct mainloop_timer_s mainloop_timer_t;
40 
41 void mainloop_cleanup(void);
42 
43 // NOTE: sbd (as of at least 1.5.2) uses this
44 crm_trigger_t *mainloop_add_trigger(int priority, int (*dispatch) (gpointer user_data),
45  gpointer userdata);
46 
47 // NOTE: sbd (as of at least 1.5.2) uses this
48 void mainloop_set_trigger(crm_trigger_t * source);
49 
51 
52 gboolean mainloop_destroy_trigger(crm_trigger_t * source);
53 
54 #ifndef HAVE_SIGHANDLER_T
55 typedef void (*sighandler_t)(int);
56 #endif
57 
59 
60 // NOTE: sbd (as of at least 1.5.2) uses this
61 gboolean mainloop_add_signal(int sig, void (*dispatch) (int sig));
62 
63 gboolean mainloop_destroy_signal(int sig);
64 
66 
67 // NOTE: sbd (as of at least 1.5.2) uses this
69 
70 // NOTE: sbd (as of at least 1.5.2) uses this
72 
73 guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms);
74 
75 // NOTE: sbd (as of at least 1.5.2) uses this
76 mainloop_timer_t *mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata);
77 
79 
80 
81 #include <crm/common/ipc.h>
82 #include <qb/qbipcs.h>
83 
94  int (*dispatch) (const char *buffer, ssize_t length, gpointer userdata);
95 
101  void (*destroy) (gpointer userdata);
102 };
103 
104 qb_ipcs_service_t *mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
105  struct qb_ipcs_service_handlers *callbacks);
106 
126 qb_ipcs_service_t *mainloop_add_ipc_server_with_prio(const char *name,
127  enum qb_ipc_type type,
128  struct qb_ipcs_service_handlers *callbacks,
129  enum qb_loop_priority prio);
130 
131 void mainloop_del_ipc_server(qb_ipcs_service_t * server);
132 
133 mainloop_io_t *mainloop_add_ipc_client(const char *name, int priority, size_t max_size,
134  void *userdata, struct ipc_client_callbacks *callbacks);
135 
137 
139 
148  int (*dispatch) (gpointer userdata);
149 
155  void (*destroy) (gpointer userdata);
156 };
157 
158 mainloop_io_t *mainloop_add_fd(const char *name, int priority, int fd, void *userdata,
159  struct mainloop_fd_callbacks *callbacks);
160 
161 void mainloop_del_fd(mainloop_io_t * client);
162 
163 /*
164  * Create a new tracked process
165  * To track a process group, use -pid
166  */
167 void mainloop_child_add(pid_t pid,
168  int timeout,
169  const char *desc,
170  void *userdata,
171  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
172 
174  int timeout,
175  const char *desc,
176  void *userdata,
178  void (*callback) (mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode));
179 
182 const char *mainloop_child_name(mainloop_child_t * child);
183 
184 pid_t mainloop_child_pid(mainloop_child_t * child);
186 gboolean mainloop_child_kill(pid_t pid);
187 
188 void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n);
189 void pcmk_drain_main_loop(GMainLoop *mloop, guint timer_ms,
190  bool (*check)(guint));
191 
192 #define G_PRIORITY_MEDIUM (G_PRIORITY_HIGH/2)
193 
194 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
196 #endif
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
gboolean mainloop_add_signal(int sig, void(*dispatch)(int sig))
Definition: mainloop.c:356
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
Definition: mainloop.c:958
void mainloop_timer_start(mainloop_timer_t *t)
Definition: mainloop.c:1332
guint mainloop_timer_set_period(mainloop_timer_t *t, guint period_ms)
Definition: mainloop.c:1352
mainloop_child_flags
Definition: mainloop.h:27
void mainloop_timer_del(mainloop_timer_t *t)
Definition: mainloop.c:1387
const char * name
Definition: cib.c:26
gboolean mainloop_child_kill(pid_t pid)
Definition: mainloop.c:1198
void(* destroy)(gpointer userdata)
Destroy function for mainloop file descriptor client data.
Definition: mainloop.h:155
Deprecated Pacemaker mainloop API.
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:646
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:1446
struct mainloop_timer_s mainloop_timer_t
Definition: mainloop.h:39
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:35
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:1254
struct mainloop_child_s mainloop_child_t
Definition: mainloop.h:36
void mainloop_set_trigger(crm_trigger_t *source)
Definition: mainloop.c:199
void mainloop_cleanup(void)
Definition: mainloop.c:420
pid_t mainloop_child_pid(mainloop_child_t *child)
Definition: mainloop.c:1018
enum crm_ais_msg_types type
Definition: cpg.c:51
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
Definition: mainloop.c:207
void mainloop_timer_stop(mainloop_timer_t *t)
Definition: mainloop.c:1342
struct trigger_s crm_trigger_t
Definition: mainloop.h:33
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
Definition: mainloop.h:148
uint32_t pid
Definition: cpg.c:49
void * mainloop_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:1036
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:184
void(* destroy)(gpointer userdata)
Destroy function for mainloop IPC connection client data.
Definition: mainloop.h:101
sighandler_t crm_signal_handler(int sig, sighandler_t dispatch)
Definition: mainloop.c:308
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:187
void mainloop_del_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:943
bool mainloop_timer_running(mainloop_timer_t *t)
Definition: mainloop.c:1323
void(* sighandler_t)(int)
Definition: mainloop.h:55
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:1285
void mainloop_trigger_complete(crm_trigger_t *trig)
Definition: mainloop.c:168
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:949
void mainloop_clear_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:1042
void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n)
Drain some remaining main loop events then quit it.
Definition: mainloop.c:1417
IPC interface to Pacemaker daemons.
void mainloop_del_fd(mainloop_io_t *client)
Definition: mainloop.c:1002
void mainloop_del_ipc_server(qb_ipcs_service_t *server)
Definition: mainloop.c:683
mainloop_timer_t * mainloop_timer_add(const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
Definition: mainloop.c:1368
gboolean mainloop_destroy_signal(int sig)
Definition: mainloop.c:400
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:918
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:639
const char * mainloop_child_name(mainloop_child_t *child)
Definition: mainloop.c:1024
unsigned int timeout
Definition: pcmk_fence.c:32
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
Definition: mainloop.h:94
int mainloop_child_timeout(mainloop_child_t *child)
Definition: mainloop.c:1030