static void do_command (int sock, char* func, char*args[], int num_args) { char response[100]; int err = 0; qb_log (LOG_INFO, "RPC:%s() called.", func); if (strncmp ("test", func, 4) == 0) { err = do_test_command(sock, func, args, num_args); } else if (strcmp ("setup_hc", func) == 0) { err = setup_hc (); } else if (strcmp ("sam_stop", func) == 0) { err = sam_stop (); if (err != CS_OK) { err = -1; qb_log (LOG_ERR,"RPC:%s sam_stop failed!", func); snprintf (response, 100, "%s", FAIL_STR); } err = sam_finalize(); } else { err = -1; qb_log (LOG_ERR,"RPC:%s not supported!", func); snprintf (response, 100, "%s", NOT_SUPPORTED_STR); } if (err == 0) { snprintf (response, 100, "%s", OK_STR); } else if (err == 1) { snprintf (response, 100, "%s", FAIL_STR); qb_log (LOG_ERR, "%s() test skipped?! (%d).", func, err); } else { snprintf (response, 100, "%s", FAIL_STR); qb_log (LOG_ERR, "%s() failed (%d).", func, err); } send (sock, response, strlen (response) + 1, 0); }
cs_error_t sam_finalize (void) { cs_error_t error; if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_INITIALIZED && sam_internal_data.internal_status != SAM_INTERNAL_STATUS_REGISTERED && sam_internal_data.internal_status != SAM_INTERNAL_STATUS_STARTED) { return (CS_ERR_BAD_HANDLE); } if (sam_internal_data.internal_status == SAM_INTERNAL_STATUS_STARTED) { error = sam_stop (); if (error != CS_OK) goto exit_error; } sam_internal_data.internal_status = SAM_INTERNAL_STATUS_FINALIZED; exit_error: return (CS_OK); }
/* * First test will just register SAM, with policy restart. First instance will * sleep one second, send hc and sleep another 3 seconds. This should force restart. * Second instance will sleep one second, send hc, stop hc and sleep 3 seconds. * Then start hc again and sleep 3 seconds. This should force restart again. * Last instance just calls initialize again. This should end with error. * Then call start, followed by stop and start again. Finally, we will call finalize * twice. One should succeed, second should fail. After this, we will call every function * (none should succeed). */ static int test1 (void) { cs_error_t error; unsigned int instance_id; int i; qb_enter(); error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART); if (error != CS_OK) { qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error); return 1; } qb_log (LOG_INFO, "register"); error = sam_register (&instance_id); if (error != CS_OK) { qb_log (LOG_ERR, "Can't register. Error %d", error); return 1; } if (instance_id == 1 || instance_id == 2) { qb_log (LOG_INFO, "iid %d: start", instance_id); error = sam_start (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", error); return 1; } for (i = 0; i < 10; i++) { qb_log (LOG_INFO, "iid %d: sleep 1", instance_id); sleep (1); qb_log (LOG_INFO, "iid %d: hc send", instance_id); error = sam_hc_send (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't send hc. Error %d", error); return 1; } } if (instance_id == 2) { qb_log (LOG_INFO, "iid %d: stop", instance_id); error = sam_stop (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't send hc. Error %d", error); return 1; } } qb_log (LOG_INFO, "iid %d: sleep 3", instance_id); sleep (3); qb_log (LOG_INFO, "iid %d: start", instance_id); error = sam_start (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", error); return 1; } qb_log (LOG_INFO, "iid %d: sleep 3", instance_id); sleep (3); return 0; } if (instance_id == 3) { error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART); if (error == CS_OK) { qb_log (LOG_ERR, "Can initialize SAM API after initialization"); return 1; } error = sam_start (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", error); return 1; } error = sam_stop (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't stop hc. Error %d", error); return 1; } error = sam_finalize (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't finalize sam. Error %d", error); return 1; } error = sam_finalize (); if (error == CS_OK) { qb_log (LOG_ERR, "Can finalize sam after finalization!"); return 1; } if (sam_initialize (2, SAM_RECOVERY_POLICY_RESTART) == CS_OK || sam_start () == CS_OK || sam_stop () == CS_OK || sam_register (NULL) == CS_OK || sam_hc_send () == CS_OK || sam_hc_callback_register (NULL) == CS_OK) { qb_log (LOG_ERR, "Can call one of function after finalization!"); return 1; } return 0; } return 1; }
/* * Test cmap integration + quit policy */ static int test8 (pid_t pid, pid_t old_pid, int test_n) { cmap_handle_t cmap_handle; cs_error_t err; uint64_t tstamp1, tstamp2; int32_t msec_diff; unsigned int instance_id; char key_name[CMAP_KEYNAME_MAXLEN]; char *str; err = cmap_initialize (&cmap_handle); if (err != CS_OK) { qb_log (LOG_INFO, "Could not initialize Cluster Map API instance error %d. Test skipped", err); return (1); } qb_log (LOG_INFO, "test %d", test_n); if (test_n == 2) { /* * Object should not exist */ qb_log (LOG_INFO, "Testing if object exists (it shouldn't)"); snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid); err = cmap_get_string(cmap_handle, key_name, &str); if (err == CS_OK) { qb_log (LOG_INFO, "Could find key \"%s\": %d.", key_name, err); free(str); return (2); } } if (test_n == 1 || test_n == 2) { qb_log (LOG_INFO, " initialize"); err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CMAP); if (err != CS_OK) { qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err); return 2; } qb_log (LOG_INFO, " register"); err = sam_register (&instance_id); if (err != CS_OK) { qb_log (LOG_ERR, "Can't register. Error %d", err); return 2; } snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.recovery", pid); err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"recovery\" key: %d.", err); return (2); } if (strcmp(str, "quit") != 0) { qb_log (LOG_INFO, "Recovery key \"%s\" is not \"quit\".", key_name); return (2); } free(str); snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid); err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "stopped") != 0) { qb_log (LOG_INFO, "State key is not \"stopped\"."); return (2); } free(str); qb_log (LOG_INFO, "iid %d: start", instance_id); err = sam_start (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", err); return 2; } err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "running") != 0) { qb_log (LOG_INFO, "State key is not \"running\"."); return (2); } free(str); qb_log (LOG_INFO, "iid %d: stop", instance_id); err = sam_stop (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't stop hc. Error %d", err); return 2; } err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "stopped") != 0) { qb_log (LOG_INFO, "State key is not \"stopped\"."); return (2); } free(str); qb_log (LOG_INFO, "iid %d: sleeping 5", instance_id); sleep (5); err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "stopped") != 0) { qb_log (LOG_INFO, "State key is not \"stopped\"."); return (2); } free(str); qb_log (LOG_INFO, "iid %d: start 2", instance_id); err = sam_start (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", err); return 2; } err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "running") != 0) { qb_log (LOG_INFO, "State key is not \"running\"."); return (2); } free(str); if (test_n == 2) { qb_log (LOG_INFO, "iid %d: sleeping 5. Should be killed", instance_id); sleep (5); return (2); } else { qb_log (LOG_INFO, "iid %d: Test HC", instance_id); err = sam_hc_send (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't send hc. Error %d", err); return 2; } snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.last_updated", pid); err = cmap_get_uint64(cmap_handle, key_name, &tstamp1); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"last_updated\" key: %d.", err); return (2); } qb_log (LOG_INFO, "iid %d: Sleep 1", instance_id); sleep (1); err = sam_hc_send (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't send hc. Error %d", err); return 2; } sleep (1); err = cmap_get_uint64(cmap_handle, key_name, &tstamp2); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"last_updated\" key: %d.", err); return (2); } msec_diff = (tstamp2 - tstamp1)/CS_TIME_NS_IN_MSEC; if (msec_diff < 500 || msec_diff > 2000) { qb_log (LOG_INFO, "Difference %d is not within <500, 2000> interval.", msec_diff); return (2); } qb_log (LOG_INFO, "iid %d: stop 2", instance_id); err = sam_stop (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't stop hc. Error %d", err); return 2; } snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid); err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "stopped") != 0) { qb_log (LOG_INFO, "State key is not \"stopped\"."); return (2); } free(str); qb_log (LOG_INFO, "iid %d: exiting", instance_id); return (0); } } if (test_n == 3) { qb_log (LOG_INFO, "Testing if status is failed"); /* * Previous should be FAILED */ snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid); err = cmap_get_string(cmap_handle, key_name, &str); if (err != CS_OK) { qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err); return (2); } if (strcmp(str, "failed") != 0) { qb_log (LOG_INFO, "State key is not \"failed\"."); return (2); } return (0); } return (2); }
/* * Test confdb integration + quit policy */ static int test8 (pid_t pid, pid_t old_pid, int test_n) { confdb_handle_t cdb_handle; cs_error_t err; hdb_handle_t res_handle, proc_handle, pid_handle; size_t value_len; uint64_t tstamp1, tstamp2; int32_t msec_diff; char key_value[256]; unsigned int instance_id; char tmp_obj[PATH_MAX]; confdb_value_types_t cdbtype; err = confdb_initialize (&cdb_handle, NULL); if (err != CS_OK) { printf ("Could not initialize Cluster Configuration Database API instance error %d. Test skipped\n", err); return (1); } printf ("%s test %d\n", __FUNCTION__, test_n); if (test_n == 2) { /* * Object should not exist */ printf ("%s Testing if object exists (it shouldn't)\n", __FUNCTION__); err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle); if (err != CS_OK) { printf ("Could not object_find \"resources\": %d.\n", err); return (2); } err = confdb_object_find_start(cdb_handle, res_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle); if (err != CS_OK) { printf ("Could not object_find \"process\": %d.\n", err); return (2); } if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) { snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid); } err = confdb_object_find_start(cdb_handle, proc_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle); if (err == CS_OK) { printf ("Could find object \"%s\": %d.\n", tmp_obj, err); return (2); } } if (test_n == 1 || test_n == 2) { printf ("%s: initialize\n", __FUNCTION__); err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CONFDB); if (err != CS_OK) { fprintf (stderr, "Can't initialize SAM API. Error %d\n", err); return 2; } printf ("%s: register\n", __FUNCTION__); err = sam_register (&instance_id); if (err != CS_OK) { fprintf (stderr, "Can't register. Error %d\n", err); return 2; } err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle); if (err != CS_OK) { printf ("Could not object_find \"resources\": %d.\n", err); return (2); } err = confdb_object_find_start(cdb_handle, res_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle); if (err != CS_OK) { printf ("Could not object_find \"process\": %d.\n", err); return (2); } if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) { snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid); } err = confdb_object_find_start(cdb_handle, proc_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle); if (err != CS_OK) { printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err); return (2); } err = confdb_key_get(cdb_handle, pid_handle, "recovery", strlen("recovery"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"recovery\" key: %d.\n", err); return (2); } if (value_len != strlen ("quit") || memcmp (key_value, "quit", value_len) != 0) { printf ("Recovery key \"%s\" is not \"watchdog\".\n", key_value); return (2); } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) { printf ("State key is not \"stopped\".\n"); return (2); } printf ("%s iid %d: start\n", __FUNCTION__, instance_id); err = sam_start (); if (err != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", err); return 2; } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("running") || memcmp (key_value, "running", value_len) != 0) { printf ("State key is not \"running\".\n"); return (2); } printf ("%s iid %d: stop\n", __FUNCTION__, instance_id); err = sam_stop (); if (err != CS_OK) { fprintf (stderr, "Can't stop hc. Error %d\n", err); return 2; } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) { printf ("State key is not \"stopped\".\n"); return (2); } printf ("%s iid %d: sleeping 5\n", __FUNCTION__, instance_id); sleep (5); err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) { printf ("State key is not \"stopped\".\n"); return (2); } printf ("%s iid %d: start 2\n", __FUNCTION__, instance_id); err = sam_start (); if (err != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", err); return 2; } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("running") || memcmp (key_value, "running", value_len) != 0) { printf ("State key is not \"running\".\n"); return (2); } if (test_n == 2) { printf ("%s iid %d: sleeping 5. Should be killed\n", __FUNCTION__, instance_id); sleep (5); return (2); } else { printf ("%s iid %d: Test HC\n", __FUNCTION__, instance_id); err = sam_hc_send (); if (err != CS_OK) { fprintf (stderr, "Can't send hc. Error %d\n", err); return 2; } err = confdb_key_get_typed (cdb_handle, pid_handle, "last_updated", &tstamp1, &value_len, &cdbtype); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } printf ("%s iid %d: Sleep 1\n", __FUNCTION__, instance_id); sleep (1); err = sam_hc_send (); if (err != CS_OK) { fprintf (stderr, "Can't send hc. Error %d\n", err); return 2; } sleep (1); err = confdb_key_get_typed (cdb_handle, pid_handle, "last_updated", &tstamp2, &value_len, &cdbtype); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } msec_diff = (tstamp2 - tstamp1)/CS_TIME_NS_IN_MSEC; if (msec_diff < 500 || msec_diff > 2000) { printf ("Difference %d is not within <500, 2000> interval.\n", msec_diff); return (2); } printf ("%s iid %d: stop 2\n", __FUNCTION__, instance_id); err = sam_stop (); if (err != CS_OK) { fprintf (stderr, "Can't stop hc. Error %d\n", err); return 2; } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) { printf ("State key is not \"stopped\".\n"); return (2); } printf ("%s iid %d: exiting\n", __FUNCTION__, instance_id); return (0); } } if (test_n == 3) { printf ("%s Testing if status is failed\n", __FUNCTION__); /* * Previous should be FAILED */ err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle); if (err != CS_OK) { printf ("Could not object_find \"resources\": %d.\n", err); return (2); } err = confdb_object_find_start(cdb_handle, res_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle); if (err != CS_OK) { printf ("Could not object_find \"process\": %d.\n", err); return (2); } if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) { snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid); } err = confdb_object_find_start(cdb_handle, proc_handle); if (err != CS_OK) { printf ("Could not start object_find %d.\n", err); return (2); } err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle); if (err != CS_OK) { printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err); return (2); } err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len); if (err != CS_OK) { printf ("Could not get \"state\" key: %d.\n", err); return (2); } if (value_len != strlen ("failed") || memcmp (key_value, "failed", value_len) != 0) { printf ("State key is not \"failed\".\n"); return (2); } return (0); } return (2); }
/* * First test will just register SAM, with policy restart. First instance will * sleep one second, send hc and sleep another 3 seconds. This should force restart. * Second instance will sleep one second, send hc, stop hc and sleep 3 seconds. * Then start hc again and sleep 3 seconds. This should force restart again. * Last instance just calls initialize again. This should end with error. * Then call start, followed by stop and start again. Finally, we will call finalize * twice. One should succeed, second should fail. After this, we will call every function * (none should succeed). */ static int test1 (void) { cs_error_t error; unsigned int instance_id; int i; printf ("%s: initialize\n", __FUNCTION__); error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART); if (error != CS_OK) { fprintf (stderr, "Can't initialize SAM API. Error %d\n", error); return 1; } printf ("%s: register\n", __FUNCTION__); error = sam_register (&instance_id); if (error != CS_OK) { fprintf (stderr, "Can't register. Error %d\n", error); return 1; } if (instance_id == 1 || instance_id == 2) { printf ("%s iid %d: start\n", __FUNCTION__, instance_id); error = sam_start (); if (error != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", error); return 1; } for (i = 0; i < 10; i++) { printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id); sleep (1); printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id); error = sam_hc_send (); if (error != CS_OK) { fprintf (stderr, "Can't send hc. Error %d\n", error); return 1; } } if (instance_id == 2) { printf ("%s iid %d: stop\n", __FUNCTION__, instance_id); error = sam_stop (); if (error != CS_OK) { fprintf (stderr, "Can't send hc. Error %d\n", error); return 1; } } printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id); sleep (3); printf ("%s iid %d: start\n", __FUNCTION__, instance_id); error = sam_start (); if (error != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", error); return 1; } printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id); sleep (3); return 0; } if (instance_id == 3) { error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART); if (error == CS_OK) { fprintf (stderr, "Can initialize SAM API after initialization"); return 1; } error = sam_start (); if (error != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", error); return 1; } error = sam_stop (); if (error != CS_OK) { fprintf (stderr, "Can't stop hc. Error %d\n", error); return 1; } error = sam_finalize (); if (error != CS_OK) { fprintf (stderr, "Can't finalize sam. Error %d\n", error); return 1; } error = sam_finalize (); if (error == CS_OK) { fprintf (stderr, "Can finalize sam after finalization!\n"); return 1; } if (sam_initialize (2, SAM_RECOVERY_POLICY_RESTART) == CS_OK || sam_start () == CS_OK || sam_stop () == CS_OK || sam_register (NULL) == CS_OK || sam_hc_send () == CS_OK || sam_hc_callback_register (NULL) == CS_OK) { fprintf (stderr, "Can call one of function after finalization!\n"); return 1; } return 0; } return 1; }