Exemple #1
0
static cs_error_t sam_parent_warn_signal_set (
	int parent_fd_in,
	int parent_fd_out)
{
	int warn_signal;
	cs_error_t err;

	err = CS_OK;

	if (sam_safe_read (parent_fd_in, &warn_signal, sizeof (warn_signal)) != sizeof (warn_signal)) {
		err = CS_ERR_LIBRARY;
		goto error_reply;
	}

	err = sam_warn_signal_set (warn_signal);
	if (err != CS_OK) {
		goto error_reply;
	}


	return (sam_parent_reply_send (CS_OK, parent_fd_in, parent_fd_out));

error_reply:
	return (sam_parent_reply_send (err, parent_fd_in, parent_fd_out));
}
/*
 * Test warn signal set.
 */
static int test6 (void) {
	cs_error_t error;
	unsigned int instance_id;
	int test6_sig_del;

	qb_log (LOG_INFO, " initialize");
	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) {
		error = sam_warn_signal_set (SIGUSR1);
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't set warn signal. Error %d", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		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 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;
		}


		qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		qb_log (LOG_INFO, "iid %d: wait for real kill", instance_id);

		sleep (3);

		qb_log (LOG_INFO, "iid %d: wasn't killed", instance_id);
		return (1);
	}

	if (instance_id == 2) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't restore data. Error %d", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			qb_log (LOG_ERR, "Previous test failed. Signal was not delivered");
			return 1;
		}

		error = sam_warn_signal_set (SIGKILL);
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't set warn signal. Error %d", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		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 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;
		}


		qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		qb_log (LOG_INFO, "iid %d: wasn't killed", instance_id);
		return (1);
	}

	if (instance_id == 3) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't restore data. Error %d", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			qb_log (LOG_ERR, "Previous test failed. Signal WAS delivered");
			return 1;
		}

		return (0);
	}

	return 1;
}
Exemple #3
0
/*
 * Test warn signal set.
 */
static int
sam_test6 (void) {
	cs_error_t error;
	unsigned int instance_id;
	int test6_sig_del;

	setlinebuf(stdout);
	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) {
		error = sam_warn_signal_set (SIGUSR1);
		if (error != CS_OK) {
			fprintf (stderr, "Can't set warn signal. Error %d\n", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		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 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;
		}


		printf ("%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		printf ("%s iid %d: wait for real kill\n", __FUNCTION__, instance_id);

		sleep (3);

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (1);
	}

	if (instance_id == 2) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			fprintf (stderr, "Can't restore data. Error %d\n", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			fprintf (stderr, "Previous test failed. Signal was not delivered\n");
			return 1;
		}

		error = sam_warn_signal_set (SIGKILL);
		if (error != CS_OK) {
			fprintf (stderr, "Can't set warn signal. Error %d\n", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		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 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;
		}


		printf ("%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (1);
	}

	if (instance_id == 3) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			fprintf (stderr, "Can't restore data. Error %d\n", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			fprintf (stderr, "Previous test failed. Signal WAS delivered\n");
			return 1;
		}

		return (0);
	}

	return 1;
}