CPG_INITIALIZE(3)
π CPG_INITIALIZE π
okay bestie, welcome to CPG_INITIALIZE(3) β yes it's a section 3 page, yes it's from the Corosync Cluster Engine Programmer's Manual, and yes we are going to get you connected to the closed process groups API. let's go π¦
β¨ NAME β¨
cpg_initialize β create a new connection to the CPG service π
πΈ SYNOPSIS πΈ
#include <corosync/cpg.h>
int cpg_initialize(cpg_handle_t *handle, cpg_callbacks_t *callbacks);
π DESCRIPTION π
so, the cpg_initialize function is literally the thing that initializes a connection to the closed process groups API. BUT β huge heads up β this function is deprecated, and cpg_model_initialize should be used in newly written code. yes i'm being dramatic, but also i'm being accurate. periodt. π
every application can have several connections to the CPG API, no cap. each application uses the handle argument to uniquely identify the connection. and then that handle argument gets used in other function calls to identify which connection is the one being used for communication with the CPG service. it's giving β¨personalized ID badgeβ¨.
every single time a CPG event occurs within the joined group, one of the callbacks specified by the argument callbacks is called. the callback functions are described by these type definitions, right here, verbatim, do not touch:
typedef void (*cpg_deliver_fn_t) (
cpg_handle_t handle,
const struct cpg_name *group_name,
uint32_t nodeid,
uint32_t pid,
const void *msg,
size_t msg_len);
typedef void (*cpg_confchg_fn_t) (
cpg_handle_t handle,
const struct cpg_name *group_name,
const struct cpg_address *member_list, size_t member_list_entries,
const struct cpg_address *left_list, size_t left_list_entries,
const struct cpg_address *joined_list, size_t joined_list_entries);
and the callbacks argument? it's of the type:
typedef struct {
cpg_deliver_fn_t cpg_deliver_fn;
cpg_confchg_fn_t cpg_confchg_fn;
} cpg_callbacks_t;
when a configuration change occurs, or when a message is to be delivered, one of those callbacks gets called from the cpg_dispatch() function. so: configuration change happens β cpg_confchg_fn gets called. delivery of a message happens β cpg_deliver_fn gets called. iconic division of labor tbh π
and the cpg_address structure is defined like this:
struct cpg_address {
unsigned int nodeid;
unsigned int pid;
unsigned int reason;
};
where nodeid is a 32 bit unique node identifier, pid is the process ID of the process that has joined/left the group or sent the message, and reason is an integer code indicating why the node joined/left the group. β οΈ quick note bestie: this value is not set for the member_list items.
here are all the reason codes, no skipping:
CPG_REASON_JOINβ the process joined a group usingcpg_join().CPG_REASON_LEAVEβ the process left a group usingcpg_leave()CPG_REASON_NODEDOWNβ the process left a group because the node left the cluster.CPG_REASON_NODEUPβ the process joined a group because it was already a member of a group on a node that has just joined the clusterCPG_REASON_PROCDOWNβ the process left a group without callingcpg_leave()CPG_REASON_UNDEFINEDβ a special value used for themember_listitems
π« RETURN VALUE π«
this call returns the CS_OK value if successful, otherwise an error is returned. simple as that π«Ά
π ERRORS π
the errors are undocumented. yeah. i know. we're all just out here vibing π
β SEE ALSO β
cpg_overview(3)cpg_initialize(3)cpg_finalize(3)cpg_fd_get(3)cpg_dispatch(3)cpg_join(3)cpg_leave(3)cpg_mcast_joined(3)cpg_membership_get(3)cpg_zcb_alloc(3)cpg_zcb_free(3)cpg_zcb_mcast_joined(3)cpg_context_get(3)cpg_context_set(3)cpg_local_get(3)cpg_model_initialize(3)
and the error codes, served fresh:
CS_ERR_TRY_AGAINβ Resource temporarily unavailableCS_ERR_INVALID_PARAMβ Invalid argumentCS_ERR_ACCESSβ Permission deniedCS_ERR_LIBRARYβ The connection failedCS_ERR_INTERRUPTβ System call interrupted by a signalCS_ERR_NOT_SUPPORTEDβ The requested protocol/functionality not supportedCS_ERR_MESSAGE_ERRORβ Incorrect auth message receivedCS_ERR_NO_MEMORYβ Not enough memory to complete the requested task
and that's the whole page, bestie!! π this lil beauty comes to you from the corosync Man Page, dated 2019-04-16, and yeah the manual name is still CPG_INITIALIZE(3) because some things never change. go forth and initialize responsibly β¨ππ¦
π¦ where this page comes from
- debian bookworm: libcpg-dev 3.1.7-1+deb12u2 Β· BSD-3-Clause
- debian trixie: libcpg-dev 3.1.9-2+deb13u1 Β· BSD-3-Clause
- epel 9: corosynclib-devel 3.1.10-0.2.el9.1 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.10-3.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.10-3.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.9-5.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.9-5.fc43 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-4.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-4.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-6.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-6.fc44 Β· BSD-3-Clause
- nixos 26.05: corosync 3.1.9
- nixpkgs unstable: corosync 3.1.9
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- ubuntu jammy: libcpg-dev 3.1.6-1ubuntu1 Β· BSD-3-Clause
- ubuntu jammy: libcpg-dev 3.1.6-1ubuntu1.2 Β· BSD-3-Clause
- ubuntu noble: libcpg-dev 3.1.7-1ubuntu3 Β· BSD-3-Clause
- ubuntu noble: libcpg-dev 3.1.7-1ubuntu3.2 Β· BSD-3-Clause
- ubuntu questing: libcpg-dev 3.1.9-2ubuntu1
- ubuntu questing: libcpg-dev 3.1.9-2ubuntu1.1
- ubuntu resolute: libcpg-dev 3.1.9-2ubuntu3 Β· BSD-3-Clause
- ubuntu stonking: libcpg-dev 3.1.10-3ubuntu1 Β· BSD-3-Clause
- Copyright (c) 2006-2019 Red Hat, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms