pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Typedefs | Functions | Variables
mainloop.c File Reference
#include <crm_internal.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
#include <crm/crm.h>
#include <crm/common/xml.h>
#include <crm/common/mainloop.h>
#include <crm/common/ipc_internal.h>
#include <qb/qbarray.h>
#include <crm/common/mainloop_compat.h>
Include dependency graph for mainloop.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Typedefs

typedef struct signal_s crm_signal_t
 

Functions

void mainloop_trigger_complete (crm_trigger_t *trig)
 
crm_trigger_tmainloop_add_trigger (int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
 Create a trigger to be used as a mainloop source. More...
 
void mainloop_set_trigger (crm_trigger_t *source)
 
gboolean mainloop_destroy_trigger (crm_trigger_t *source)
 
sighandler_t crm_signal_handler (int sig, sighandler_t dispatch)
 
gboolean mainloop_add_signal (int sig, void(*dispatch)(int sig))
 
gboolean mainloop_destroy_signal (int sig)
 
void mainloop_cleanup (void)
 
qb_ipcs_service_t * mainloop_add_ipc_server (const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
 
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. More...
 
void mainloop_del_ipc_server (qb_ipcs_service_t *server)
 
int pcmk__add_mainloop_ipc (crm_ipc_t *ipc, int priority, void *userdata, struct ipc_client_callbacks *callbacks, mainloop_io_t **source)
 Connect to IPC and add it as a main loop source. More...
 
guint pcmk__mainloop_timer_get_period (mainloop_timer_t *timer)
 Get period for mainloop timer. More...
 
mainloop_io_tmainloop_add_ipc_client (const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
 
void mainloop_del_ipc_client (mainloop_io_t *client)
 
crm_ipc_tmainloop_get_ipc_client (mainloop_io_t *client)
 
mainloop_io_tmainloop_add_fd (const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
 
void mainloop_del_fd (mainloop_io_t *client)
 
pid_t mainloop_child_pid (mainloop_child_t *child)
 
const char * mainloop_child_name (mainloop_child_t *child)
 
int mainloop_child_timeout (mainloop_child_t *child)
 
void * mainloop_child_userdata (mainloop_child_t *child)
 
void mainloop_clear_child_userdata (mainloop_child_t *child)
 
gboolean mainloop_child_kill (pid_t pid)
 
void mainloop_child_add_with_flags (pid_t pid, int timeout, const char *desc, void *privatedata, enum mainloop_child_flags flags, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
 
void mainloop_child_add (pid_t pid, int timeout, const char *desc, void *privatedata, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
 
bool mainloop_timer_running (mainloop_timer_t *t)
 
void mainloop_timer_start (mainloop_timer_t *t)
 
void mainloop_timer_stop (mainloop_timer_t *t)
 
guint mainloop_timer_set_period (mainloop_timer_t *t, guint period_ms)
 
mainloop_timer_tmainloop_timer_add (const char *name, guint period_ms, bool repeat, GSourceFunc cb, void *userdata)
 
void mainloop_timer_del (mainloop_timer_t *t)
 
void pcmk_quit_main_loop (GMainLoop *mloop, unsigned int n)
 Drain some remaining main loop events then quit it. More...
 
void pcmk_drain_main_loop (GMainLoop *mloop, guint timer_ms, bool(*check)(guint))
 Process main loop events while a certain condition is met. More...
 
gboolean crm_signal (int sig, void(*dispatch)(int sig))
 

Variables

struct qb_ipcs_poll_handlers gio_poll_funcs
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 13 of file mainloop.c.

Typedef Documentation

typedef struct signal_s crm_signal_t

Function Documentation

gboolean crm_signal ( int  sig,
void(*)(int sig)  dispatch 
)
Deprecated:
Use crm_signal_handler() instead

Definition at line 1495 of file mainloop.c.

sighandler_t crm_signal_handler ( int  sig,
sighandler_t  dispatch 
)

Definition at line 307 of file mainloop.c.

mainloop_io_t* mainloop_add_fd ( const char *  name,
int  priority,
int  fd,
void *  userdata,
struct mainloop_fd_callbacks callbacks 
)

Definition at line 975 of file mainloop.c.

mainloop_io_t* mainloop_add_ipc_client ( const char *  name,
int  priority,
size_t  max_size,
void *  userdata,
struct ipc_client_callbacks callbacks 
)

Definition at line 935 of file mainloop.c.

qb_ipcs_service_t* mainloop_add_ipc_server ( const char *  name,
enum qb_ipc_type  type,
struct qb_ipcs_service_handlers *  callbacks 
)

Definition at line 670 of file mainloop.c.

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.

Parameters
[in]namename of the IPC end-point ("address" for the client)
[in]typeselects libqb's IPC back-end (or use #QB_IPC_NATIVE)
[in]callbacksdefines libqb's IPC service-level handlers
[in]prioritypriority relative to other events handled in the abstract handling loop, use #QB_LOOP_MED when unsure
Returns
libqb's opaque handle to the created service abstraction
Note
For portability concerns, do not use this function if you keep priority as #QB_LOOP_MED, stick with mainloop_add_ipc_server (with exactly such semantics) instead (once you link with this new symbol employed, you can't downgrade the library freely anymore).
The intended effect will only get fully reflected when run-time linked to patched libqb: https://github.com/ClusterLabs/libqb/pull/352

Definition at line 677 of file mainloop.c.

gboolean mainloop_add_signal ( int  sig,
void(*)(int sig)  dispatch 
)

Definition at line 355 of file mainloop.c.

crm_trigger_t* mainloop_add_trigger ( int  priority,
int(*)(gpointer user_data)  dispatch,
gpointer  userdata 
)

Create a trigger to be used as a mainloop source.

Parameters
[in]priorityRelative priority of source (lower number is higher priority)
[in]dispatchTrigger dispatch function (should return 0 to remove the trigger from the mainloop, -1 if the trigger should be kept but the job is still running and not complete, and 1 if the trigger should be kept and the job is complete)
Returns
Newly allocated mainloop source for trigger

Definition at line 186 of file mainloop.c.

void mainloop_child_add ( pid_t  pid,
int  timeout,
const char *  desc,
void *  privatedata,
void(*)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode)  callback 
)

Definition at line 1305 of file mainloop.c.

void mainloop_child_add_with_flags ( pid_t  pid,
int  timeout,
const char *  desc,
void *  privatedata,
enum mainloop_child_flags  flags,
void(*)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode)  callback 
)

Definition at line 1271 of file mainloop.c.

gboolean mainloop_child_kill ( pid_t  pid)

Definition at line 1215 of file mainloop.c.

const char* mainloop_child_name ( mainloop_child_t child)

Definition at line 1041 of file mainloop.c.

pid_t mainloop_child_pid ( mainloop_child_t child)

Definition at line 1035 of file mainloop.c.

int mainloop_child_timeout ( mainloop_child_t child)

Definition at line 1047 of file mainloop.c.

void* mainloop_child_userdata ( mainloop_child_t child)

Definition at line 1053 of file mainloop.c.

void mainloop_cleanup ( void  )

Definition at line 429 of file mainloop.c.

void mainloop_clear_child_userdata ( mainloop_child_t child)

Definition at line 1059 of file mainloop.c.

void mainloop_del_fd ( mainloop_io_t client)

Definition at line 1019 of file mainloop.c.

void mainloop_del_ipc_client ( mainloop_io_t client)

Definition at line 960 of file mainloop.c.

void mainloop_del_ipc_server ( qb_ipcs_service_t *  server)

Definition at line 713 of file mainloop.c.

gboolean mainloop_destroy_signal ( int  sig)

Definition at line 409 of file mainloop.c.

gboolean mainloop_destroy_trigger ( crm_trigger_t source)

Definition at line 206 of file mainloop.c.

crm_ipc_t* mainloop_get_ipc_client ( mainloop_io_t client)

Definition at line 966 of file mainloop.c.

void mainloop_set_trigger ( crm_trigger_t source)

Definition at line 198 of file mainloop.c.

mainloop_timer_t* mainloop_timer_add ( const char *  name,
guint  period_ms,
bool  repeat,
GSourceFunc  cb,
void *  userdata 
)

Definition at line 1388 of file mainloop.c.

void mainloop_timer_del ( mainloop_timer_t t)

Definition at line 1409 of file mainloop.c.

bool mainloop_timer_running ( mainloop_timer_t t)

Definition at line 1343 of file mainloop.c.

guint mainloop_timer_set_period ( mainloop_timer_t t,
guint  period_ms 
)

Definition at line 1372 of file mainloop.c.

void mainloop_timer_start ( mainloop_timer_t t)

Definition at line 1352 of file mainloop.c.

void mainloop_timer_stop ( mainloop_timer_t t)

Definition at line 1362 of file mainloop.c.

void mainloop_trigger_complete ( crm_trigger_t trig)

Definition at line 168 of file mainloop.c.

int pcmk__add_mainloop_ipc ( crm_ipc_t ipc,
int  priority,
void *  userdata,
struct ipc_client_callbacks callbacks,
mainloop_io_t **  source 
)

Connect to IPC and add it as a main loop source.

Parameters
[in]ipcIPC connection to add
[in]priorityEvent source priority to use for connection
[in]userdataData to register with callbacks
[in]callbacksDispatch and destroy callbacks for connection
[out]sourceNewly allocated event source
Returns
Standard Pacemaker return code
Note
On failure, the caller is still responsible for ipc. On success, the caller should call mainloop_del_ipc_client() when source is no longer needed, which will lead to the disconnection of the IPC later in the main loop if it is connected. However the IPC disconnects, mainloop_gio_destroy() will free ipc and source after calling the destroy callback.

Definition at line 893 of file mainloop.c.

guint pcmk__mainloop_timer_get_period ( mainloop_timer_t timer)

Get period for mainloop timer.

Parameters
[in]timerTimer
Returns
Period in ms

Definition at line 926 of file mainloop.c.

void pcmk_drain_main_loop ( GMainLoop *  mloop,
guint  timer_ms,
bool(*)(guint)  check 
)

Process main loop events while a certain condition is met.

Parameters
[in]mloopMain loop to process
[in]timer_msDon't process longer than this amount of time
[in]checkFunction that returns TRUE if events should be processed
Note
This function is intended to be called at shutdown if certain important events should not be missed. The caller would likely quit the main loop or exit after calling this function. The check() function will be passed the remaining timeout in milliseconds.

Definition at line 1467 of file mainloop.c.

void pcmk_quit_main_loop ( GMainLoop *  mloop,
unsigned int  n 
)

Drain some remaining main loop events then quit it.

Parameters
[in]mloopMain loop to drain and quit
[in]nDrain up to this many pending events

Definition at line 1439 of file mainloop.c.

Variable Documentation

struct qb_ipcs_poll_handlers gio_poll_funcs
Initial value:
= {
.job_add = NULL,
.dispatch_add = gio_poll_dispatch_add,
.dispatch_mod = gio_poll_dispatch_mod,
.dispatch_del = gio_poll_dispatch_del,
}

Definition at line 637 of file mainloop.c.