---
name: "sam_initialize"
section: "3"
platform: "linux"
package: "libsam-dev"
version: "3.1.9-2+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sam_initialize"
---

# sam\_initialize(3)

Initialize health checking

## NAME

sam\_initialize - Initialize health checking

## SYNOPSIS

**#include \<corosync/sam.h\>**

**cs\_error\_t sam\_initialize (int** *time\_interval***, sam\_recovery\_policy\_t** *recovery\_policy*);

## DESCRIPTION

The **sam\_initialize** function is used to initialize health checking of a process.

Application can have only one instance of SAM. This function must be called before any other of SAM functions.  It is recommended to initialize before the process begins any process initialization.

The *time\_interval* parameter is a timeout in milliseconds before taking recovery action after having not received a healthcheck.

If *time\_interval* parameter is zero, there is no time limit and no healthcheck must be sent by the process.  In this operational mode, a process failure will continue to execute the recovery policy.

The *recovery\_policy* is defined as type:

```
  typedef enum {
  	SAM_RECOVERY_POLICY_QUIT = 1,
  	SAM_RECOVERY_POLICY_RESTART = 2,
        SAM_RECOVERY_POLICY_QUORUM = 0x08,
        SAM_RECOVERY_POLICY_QUORUM_QUIT = SAM_RECOVERY_POLICY_QUORUM | SAM_RECOVERY_POLICY_QUIT,
        SAM_RECOVERY_POLICY_QUORUM_RESTART = SAM_RECOVERY_POLICY_QUORUM | SAM_RECOVERY_POLICY_RESTART,
        SAM_RECOVERY_POLICY_CMAP = 0x10,
        SAM_RECOVERY_POLICY_CONFDB = 0x10,
  } sam_recovery_policy_t;
```

where

- SAM\_RECOVERY\_POLICY\_QUIT

  on failure, the process will terminate.

- SAM\_RECOVERY\_POLICY\_RESTART

  on failure, the process will restart.

- SAM\_RECOVERY\_POLICY\_QUORUM

  is not policy. Used only as flag meaning quorum integration

- SAM\_RECOVERY\_POLICY\_QUORUM\_QUIT

  same as *SAM\_RECOVERY\_POLICY\_QUIT* but **sam\_start (3)** will block until corosync becomes quorate and process will be terminated if quorum is lost.

- SAM\_RECOVERY\_POLICY\_QUORUM\_RESTART

  same as *SAM\_RECOVERY\_POLICY\_RESTART* but **sam\_start (3)** will block until corosync becomes quorate and process will be restarted if quorum is lost.

- SAM\_RECOVERY\_POLICY\_CMAP

  is not policy. Used only as flag meaning cmap integration. It can be used with all previous policies. For backward compatibility, SAM\_RECOVERY\_POLICY\_CONFDB with same meaning as *SAM\_RECOVERY\_POLICY\_CMAP* is also provided.

To perform event driven healthchecking, **[sam\_register(3)](/sam_register/3.md)** and **[sam\_start(3)](/sam_start/3.md)** functions must called.  Event driven healthchecking causes the duplicate standby process running the SAM serve rto periodically request healthchecks from the active process.

## RETURN VALUE

This call return CS\_OK value if successful, otherwise and error is returned.

## ERRORS

- CS\_ERR\_BAD\_HANDLE

  can happened in case of double initialization.

- CS\_ERR\_INVALID\_PARAM

  *recovery\_policy* has invalid value.

## SEE ALSO

[**sam\_register**(3)](/sam_register/3.md), [**sam\_start**(3)](/sam_start/3.md), [**sam\_hc\_callback\_register**(3)](/sam_hc_callback_register/3.md)

**CS\_ERR\_TRY\_AGAIN** Resource temporarily unavailable

**CS\_ERR\_INVALID\_PARAM** Invalid argument

**CS\_ERR\_ACCESS** Permission denied

**CS\_ERR\_LIBRARY** The connection failed

**CS\_ERR\_INTERRUPT** System call interrupted by a signal

**CS\_ERR\_NOT\_SUPPORTED** The requested protocol/functionality not supported

**CS\_ERR\_MESSAGE\_ERROR** Incorrect auth message received

**CS\_ERR\_NO\_MEMORY** Not enough memory to complete the requested task
